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 ################



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

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)
  render :json => {
    :status => 'OK'
  }.to_json
end

#get_group_configurationObject



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

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

#get_registrationObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/bjondservices_controller.rb', line 67

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



55
56
57
58
59
# File 'app/controllers/bjondservices_controller.rb', line 55

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

#indexObject



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

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

#registerObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/bjondservices_controller.rb', line 14

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



34
35
36
37
38
39
40
41
42
# File 'app/controllers/bjondservices_controller.rb', line 34

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