Class: BjondservicesController

Inherits:
ApplicationController
  • Object
show all
Includes:
BjondJwt
Defined in:
app/controllers/bjondservices_controller.rb

Instance Method Summary collapse

Methods included from BjondJwt

#jwt_decode_payload_and_return_json, #jwt_encode_payload

Instance Method Details

#configure_group_endpointObject

Encrypted Communication w Bjond servers ################



58
59
60
61
62
63
64
65
66
# File 'app/controllers/bjondservices_controller.rb', line 58

def configure_group_endpoint
  puts 'configure_group_endpoint'
  bjond_registration = get_registration
  result = jwt_decode_payload_and_return_json(request.raw_post, bjond_registration)
  BjondApi::BjondAppConfig.instance.configure_group(result, bjond_registration, params[:groupid])
  render :json => {
    :status => 'OK'
  }.to_json
end

#editObject



14
15
16
# File 'app/controllers/bjondservices_controller.rb', line 14

def edit
  @bjondservice = BjondService.find(params[:id])
end

#get_group_configurationObject



74
75
76
77
78
# File 'app/controllers/bjondservices_controller.rb', line 74

def get_group_configuration
  bjond_registration = get_registration
  payload = BjondApi::BjondAppConfig.instance.get_group_configuration(bjond_registration, params[:groupid])
  render :json => jwt_encode_payload(payload.to_json, bjond_registration)
end

#get_registrationObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/bjondservices_controller.rb', line 80

def get_registration
  ap params
  registration = nil
  if (params[:environment])
    puts '**************** Looking up registration by environment'
    registration = BjondRegistration.find_by_server(params[:environment])
  end

  if (registration.nil?)
    puts 'searching by remote request'
    registration = BjondRegistration.find_registration_by_remote_request(request)
  end
  ap registration
  return registration
end

#get_schemaObject



68
69
70
71
72
# File 'app/controllers/bjondservices_controller.rb', line 68

def get_schema
  puts 'get_schema'
  render :json => jwt_encode_payload(BjondApi::BjondAppConfig.instance.group_configuration_schema,
                                     get_registration)
end

#get_user_configurationObject



96
97
98
99
100
# File 'app/controllers/bjondservices_controller.rb', line 96

def get_user_configuration
  bjond_registration = get_registration
  payload = BjondApi::BjondAppConfig.instance.get_user_configuration(bjond_registration)
  render :json => jwt_encode_payload(payload.to_json, bjond_registration)
end

#get_user_schemaObject



102
103
104
105
106
107
# File 'app/controllers/bjondservices_controller.rb', line 102

def get_user_schema
  puts 'get_user_schema'
  bjond_registration = get_registration
  payload = jwt_encode_payload(BjondApi::BjondAppConfig.instance.user_configuration_schema, bjond_registration)
  render :json => payload
end

#indexObject



10
11
12
# File 'app/controllers/bjondservices_controller.rb', line 10

def index
  @app_info = BjondApi::BjondAppConfig.instance.active_definition
end

#registerObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/bjondservices_controller.rb', line 27

def register
  registration = BjondRegistration.find_by_id(params[:id])
  if (!registration.nil?)
    response = BjondApi.register_app(BjondApi::BjondAppConfig.instance.active_definition, registration.server)
    if (response.status === 200 )
      render :json => {
        :status => 'Updated'
      }
    else
      raise "Failed to update.\n" + response.body
    end
  else
    render :json => {
      :status => 'Registration not found'
    }
  end
end

#register_group_endpointObject



47
48
49
50
51
52
53
54
55
# File 'app/controllers/bjondservices_controller.rb', line 47

def register_group_endpoint
  registration = get_registration
  service = BjondService.find_or_initialize_by(:group_id => params[:groupid], :bjond_registration_id => registration.id)
  if (service.endpoint != params[:endpoint])
    service.endpoint = params[:endpoint]
    service.save
  end
  render :json => service
end

#updateObject



18
19
20
21
22
23
24
25
# File 'app/controllers/bjondservices_controller.rb', line 18

def update
  @bjondservice = BjondService.find(params[:id])
  if @bjondservice.update(bjondservices_params)
    redirect_to @bjondservice.bjond_registration, notice: 'Bjond services was successfully updated.'
  else
    render @bjondservice.bjond_registration
  end
end