bjond-api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +6 -0
  3. data/Manifest +7 -0
  4. data/README.rdoc +74 -0
  5. data/Rakefile +19 -0
  6. data/VERSION +1 -0
  7. data/app/assets/images/bjond-api/.keep +0 -0
  8. data/app/assets/javascripts/bjond-api/.keep +0 -0
  9. data/app/assets/javascripts/bjond_api.js +19 -0
  10. data/app/assets/stylesheets/bjond-api/.keep +0 -0
  11. data/app/assets/stylesheets/bjond_registrations.css +4 -0
  12. data/app/assets/stylesheets/scaffold.css +56 -0
  13. data/app/controllers/.keep +0 -0
  14. data/app/controllers/bjond_registrations_controller.rb +72 -0
  15. data/app/controllers/bjondservices_controller.rb +83 -0
  16. data/app/helpers/.keep +0 -0
  17. data/app/helpers/bjond_registrations_helper.rb +2 -0
  18. data/app/mailers/.keep +0 -0
  19. data/app/models/.keep +0 -0
  20. data/app/models/bjond_registration.rb +26 -0
  21. data/app/models/bjond_service.rb +3 -0
  22. data/app/views/.keep +0 -0
  23. data/app/views/bjond_registrations/_form.html.erb +34 -0
  24. data/app/views/bjond_registrations/edit.html.erb +6 -0
  25. data/app/views/bjond_registrations/index.html.erb +32 -0
  26. data/app/views/bjond_registrations/new.html.erb +25 -0
  27. data/app/views/bjond_registrations/show.html.erb +41 -0
  28. data/app/views/bjondservices/index.html.erb +5 -0
  29. data/app/views/shared/_app_info.html.erb +34 -0
  30. data/bin/rails +12 -0
  31. data/bjond-api.gemspec +100 -0
  32. data/bjond-integration-gem.gemspec +50 -0
  33. data/bower.json +18 -0
  34. data/config/routes.rb +10 -0
  35. data/db/migrate/20160726195312_create_bjond_registrations.rb +10 -0
  36. data/db/migrate/20160726222319_rename_encryption_key_column.rb +5 -0
  37. data/db/migrate/20160726225852_add_encrypted_encryption_key_iv_to_bjond_registration.rb +5 -0
  38. data/db/migrate/20160727144938_add_host_and_ip_to_bjond_registrations.rb +6 -0
  39. data/db/migrate/20160727191615_create_bjond_services.rb +10 -0
  40. data/db/migrate/20160727194217_add_registration_id_to_bjond_service.rb +5 -0
  41. data/lib/bjond-api.rb +21 -0
  42. data/lib/bjond-app/engine.rb +4 -0
  43. data/lib/bjond-app-config.rb +19 -0
  44. data/lib/bjond-app-definition.rb +11 -0
  45. data/lib/bjond-consequence.rb +7 -0
  46. data/lib/bjond-event.rb +6 -0
  47. data/lib/bjond-field.rb +7 -0
  48. data/lib/generators/initializer_generator.rb +8 -0
  49. data/lib/generators/templates/initializer.rb +41 -0
  50. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 79241eb6cab2ba8f7e996f0f2a96a6b233ca0544
4
+ data.tar.gz: 7fd2d9be3cf44ce69a8f61e440daebfda2270d4f
5
+ SHA512:
6
+ metadata.gz: 4537c05e23c79c5a6d3c2374ed5bb5ba0fed26939e3d7f2a8d64137b2a500336870821760980412215b677d76e7095749c3d7cbfca5127be6a45cc92b831dc2a
7
+ data.tar.gz: c014b55ac671b3d3bd92b065617ce8b5f47517d6ce351058807323b1341029b2edd096cdc6aeb067db86ac8e741f523ffab1e0312a746b5a72d3bc21232d2006
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+
2
+ gem 'rails', '~> 4.2', '>= 4.2.4'
3
+
4
+ group :development, :test do
5
+ gem 'jeweler', '~> 2.0', '>= 2.0.1'
6
+ end
data/Manifest ADDED
@@ -0,0 +1,7 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ lib/bjond-app-definition.rb
5
+ lib/bjond-consequence.rb
6
+ lib/bjond-event.rb
7
+ lib/bjond-field.rb
data/README.rdoc ADDED
@@ -0,0 +1,74 @@
1
+ = Bjönd API
2
+
3
+ A rubygem wrapper for the Bjönd API.
4
+
5
+ This gem also contains an engine with endpoints that are made to interface with Bjond server-core.
6
+
7
+ == Creating a Bjond Integration App
8
+
9
+ To create a Bjond App using the Ruby on Rails framework, perform the following actions within your Rails application.
10
+
11
+ (1) Add the following line to your Gemfile -
12
+
13
+ gem 'bjond-api'
14
+
15
+ (2) Install it with -
16
+
17
+ bundle install
18
+
19
+
20
+ (3) Migrate your Database
21
+
22
+ To install necessary migrations, add this to your Rails' application.rb file -
23
+
24
+ config.paths['db/migrate'] = BjondApi::Engine.paths['db/migrate'].existent
25
+
26
+
27
+ (4) At this point, you can run the migrations as usual using -
28
+
29
+ rake db:migrate
30
+
31
+ The `config.paths['db/migrate']` line can be removed once the migrations are copied.
32
+
33
+ (5) Generate Configuration Files
34
+
35
+ To get you started, generate a config file by running the following command:
36
+
37
+ rails g initializer
38
+
39
+ This will automatically do two things:
40
+
41
+ - (5a) Copy a baseline bower.json file in to the root of your app. If you already have a bower.json file, you can skip this file when prompted. Instead, you can copy the dependencies over manually. At the time of this writing, the most import client side library is angular.js. Once the bower.json file is in your environment, run -
42
+
43
+ bower install
44
+
45
+ In application.js, include scripts using -
46
+
47
+ //= require bjond-api
48
+
49
+ From your angular app, include our module as a dependency -
50
+
51
+ angular.module('your-app',['bjond-api']);
52
+
53
+ - (5b) The generator will also create a root config create a config file that will initialize important variables for the Bjond-App gem. This will be copied into your app at: config/initializers/bjond-api-initializer.rb
54
+
55
+ (6) Set-up Encryption Key
56
+
57
+ For security, the encryption keys stored from Bjond Server are themselves encrypted. Define the following environment variable: APP_ENCRYPTION_KEY. If you have multiple apps in your environment, you can modify the name of this constant using BjondApi::BjondAppConfig.instance.encryption_key_name.
58
+
59
+ To create an API key, from the Rails console (Rails c), type -
60
+
61
+ [ Array.new(32) { rand(256) }.pack('C*') ].pack('m').chop
62
+
63
+ Add this to your .bashrc / .zshrc like follows:
64
+
65
+ BJOND_APP_ENCRYPTION_KEY="12345678/nux3uEVX2tHBRGc5gN4gQXIbkFEmy6d3chas="
66
+
67
+ Again, BJOND_APP_ENCRYPTION_KEY can be changed. It just needs to match the value set in your config file.
68
+
69
+ == API Methods
70
+
71
+ - register_app
72
+
73
+
74
+
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
5
+ gem.name = "bjond-api"
6
+ gem.summary = "Interface that facilitates communication with Bjönd servers."
7
+ gem.description = "Rails engine that provides communication between Bjönd Server Core and a client app."
8
+ gem.email = "blake.rego@bjondinc.com"
9
+ gem.homepage = "http://github.com/Bjond/bjond-integration-gem"
10
+ gem.authors = ["Blake Rego"]
11
+ gem.add_dependency 'faraday', '~> 0.9.2'
12
+ gem.add_dependency 'syruppay_jose', '~> 1.0'
13
+ gem.add_dependency 'attr_encrypted', '~> 3.0', '>= 3.0.3'
14
+ gem.licenses = ['MIT']
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
File without changes
File without changes
@@ -0,0 +1,19 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+
4
+ angular.module('bjond-api',[])
5
+
6
+ .controller('registrationsController', ['$scope', '$http', function ($scope, $http) {
7
+
8
+ $scope.result = null;
9
+
10
+ $scope.register = function (id) {
11
+ $http.get('/bjond-app/services/register?id=' + id).then(function () {
12
+ alert('Registration Updated with Bjond!');
13
+ }).catch(function (response) {
14
+ alert('Failed to register. Please check logs.');
15
+ console.log(response.data);
16
+ });
17
+ };
18
+
19
+ }]);
File without changes
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
File without changes
@@ -0,0 +1,72 @@
1
+ class BjondRegistrationsController < ApplicationController
2
+ before_action :set_bjond_registration, only: [:show, :edit, :update, :destroy]
3
+
4
+ require 'bjond-api'
5
+ require 'resolv'
6
+ require 'uri'
7
+
8
+ # GET /bjond_registrations
9
+ def index
10
+ @bjond_registrations = BjondRegistration.all
11
+ @app_info = BjondApi::BjondAppConfig.instance.active_definition
12
+ end
13
+
14
+ # GET /bjond_registrations/1
15
+ def show
16
+ end
17
+
18
+ # GET /bjond_registrations/new
19
+ def new
20
+ @bjond_registration = BjondRegistration.new
21
+ end
22
+
23
+ # GET /bjond_registrations/1/edit
24
+ def edit
25
+ end
26
+
27
+ # POST /bjond_registrations
28
+ def create
29
+ @bjond_registration = BjondRegistration.find_or_initialize_by(bjond_registration_params)
30
+ uri = URI.parse(@bjond_registration.server)
31
+ @bjond_registration.ip = Resolv.getaddress(uri.host)
32
+ @bjond_registration.host = Resolv.getname(@bjond_registration.ip)
33
+ response = BjondApi.register_app(BjondApi::BjondAppConfig.instance.active_definition, @bjond_registration.server)
34
+
35
+ if (response.status == 500)
36
+ throw "Unable to register with Bjond. \n" + response.body
37
+ end
38
+
39
+
40
+ if @bjond_registration.save
41
+ redirect_to @bjond_registration, notice: 'Bjond registration was successfully created.'
42
+ else
43
+ render :new
44
+ end
45
+ end
46
+
47
+ # PATCH/PUT /bjond_registrations/1
48
+ def update
49
+ if @bjond_registration.update(bjond_registration_params)
50
+ redirect_to @bjond_registration, notice: 'Bjond registration was successfully updated.'
51
+ else
52
+ render :edit
53
+ end
54
+ end
55
+
56
+ # DELETE /bjond_registrations/1
57
+ def destroy
58
+ @bjond_registration.destroy
59
+ redirect_to bjond_registrations_url, notice: 'Bjond registration was successfully destroyed.'
60
+ end
61
+
62
+ private
63
+ # Use callbacks to share common setup or constraints between actions.
64
+ def set_bjond_registration
65
+ @bjond_registration = BjondRegistration.find(params[:id])
66
+ end
67
+
68
+ # Only allow a trusted parameter "white list" through.
69
+ def bjond_registration_params
70
+ params.require(:bjond_registration).permit(:server, :encryption_key, :ip, :host)
71
+ end
72
+ end
@@ -0,0 +1,83 @@
1
+ class BjondservicesController < ApplicationController
2
+
3
+ require 'bjond-api'
4
+ require 'syruppay_jose'
5
+
6
+ skip_before_filter :verify_authenticity_token, :only => [:get_schema, :register_group_endpoint, :configure_group_endpoint]
7
+
8
+ def index
9
+ @app_info = BjondApi::BjondAppConfig.instance.active_definition
10
+ end
11
+
12
+ def register
13
+ registration = BjondRegistration.find_by_id(params[:id])
14
+ if (!registration.nil?)
15
+ response = BjondApi.register_app(BjondApi::BjondAppConfig.instance.active_definition, registration.server)
16
+ if (response.status === 200 )
17
+ render :json => {
18
+ :status => 'Updated'
19
+ }
20
+ else
21
+ raise "Failed to update.\n" + response.body
22
+ end
23
+ else
24
+ render :json => {
25
+ :status => 'Registration not found'
26
+ }
27
+ end
28
+ end
29
+
30
+
31
+
32
+ def register_group_endpoint
33
+ registration = BjondRegistration.find_registration_by_remote_ip(request.remote_ip)
34
+ service = BjondService.find_or_initialize_by(:group_id => params[:groupid], :registration_id => registration.id)
35
+ if (service.endpoint != params[:endpoint])
36
+ service.endpoint = params[:endpoint]
37
+ service.save
38
+ end
39
+ render :json => service
40
+ end
41
+
42
+ ################ Encrypted Communication w Bjond servers ################
43
+ def configure_group_endpoint
44
+ bjond_registration = BjondRegistration.find_registration_by_remote_ip(request.remote_ip)
45
+ result = jwt_decode_payload_and_return_json(request.raw_post, bjond_registration)
46
+ BjondApi::BjondAppConfig.instance.configure_group(result, bjond_registration)
47
+ render :json => {
48
+ :status => 'OK'
49
+ }.to_json
50
+ end
51
+
52
+ def get_schema
53
+ render :json => jwt_encode_payload(BjondApi::BjondAppConfig.instance.group_configuration_schema,
54
+ BjondRegistration.find_registration_by_remote_ip(request.remote_ip))
55
+ end
56
+
57
+ def get_group_configuration
58
+ bjond_registration = BjondRegistration.find_registration_by_remote_ip(request.remote_ip)
59
+ payload = BjondApi::BjondAppConfig.instance.get_group_configuration(bjond_registration)
60
+ render :json => jwt_encode_payload(payload.to_json, bjond_registration)
61
+ end
62
+
63
+ private
64
+ def jwt_encode_payload(json, bjond_registration)
65
+ payload = {
66
+ :json => json,
67
+ :iss => 'Bjönd, Inc.',
68
+ :aud => ENV['BJOND_ADAPTER_AUDIENCE'],
69
+ :exp => Time.now.to_i + 10*3600,
70
+ :nbf => Time.now.to_i - 2*3600,
71
+ :sub => ENV['BJOND_ADAPTER_SUBJECT']
72
+ }.to_json
73
+ header = {:alg => 'A128KW', :enc => 'A128CBC-HS256'}
74
+ return SyrupPay::JsonEncryptionCompactSerialization.serialization(Base64.decode64(bjond_registration.encryption_key), header, payload)
75
+ end
76
+
77
+ def jwt_decode_payload_and_return_json(token, bjond_registration)
78
+ claims_json = SyrupPay::CompactDeserialization.deserialization(Base64.decode64(bjond_registration.encryption_key), token)
79
+ claims = JSON.parse(claims_json)
80
+ return JSON.parse(claims['json'][0])
81
+ end
82
+
83
+ end
data/app/helpers/.keep ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ module BjondRegistrationsHelper
2
+ end
data/app/mailers/.keep ADDED
File without changes
data/app/models/.keep ADDED
File without changes
@@ -0,0 +1,26 @@
1
+ include BjondApi
2
+ require 'attr_encrypted'
3
+ require 'Resolv'
4
+
5
+ class BjondRegistration < ActiveRecord::Base
6
+ has_many :BjondServices
7
+
8
+
9
+ attr_encrypted :encryption_key, key: ENV[BjondApi::BjondAppConfig.instance.encryption_key_name]
10
+
11
+ def self.find_registration_by_remote_ip(ip)
12
+ ip = Resolv.getaddress(ip)
13
+ result = BjondRegistration.find_by_ip(ip)
14
+ if (!result.nil?)
15
+ return result
16
+ end
17
+ host = Resolv.getname(ip)
18
+ host_result = BjondRegistration.find_by_host(host)
19
+ if (!host_result.nil?)
20
+ return host_result
21
+ end
22
+
23
+ return BjondRegistration.first
24
+ end
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ class BjondService < ActiveRecord::Base
2
+ belongs_to :BjondRegistration
3
+ end
data/app/views/.keep ADDED
File without changes
@@ -0,0 +1,34 @@
1
+ <%= form_for(@bjond_registration) do |f| %>
2
+ <% if @bjond_registration.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@bjond_registration.errors.count, "error") %> prohibited this bjond_registration from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @bjond_registration.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :server %><br>
16
+ <%= f.text_field :server %>
17
+ </div>
18
+ <div class="field">
19
+ IP
20
+ <%= f.text_field :ip %>
21
+ </div>
22
+ <div class="field">
23
+ Host
24
+ <%= f.text_field :host %>
25
+ </div>
26
+
27
+ <div class="field">
28
+ Encryption Key
29
+ <%= f.text_field :encryption_key %>
30
+ </div>
31
+ <div class="actions">
32
+ <%= f.submit %>
33
+ </div>
34
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Bjond Registration</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @bjond_registration %> |
6
+ <%= link_to 'Back', bjond_registrations_path %>
@@ -0,0 +1,32 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Listing Bjond Registrations</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Server</th>
9
+ <th>Encrypted Encryption Key</th>
10
+ <th colspan="3"></th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <% @bjond_registrations.each do |bjond_registration| %>
16
+ <tr>
17
+ <td><%= bjond_registration.server %></td>
18
+ <td><%= bjond_registration.encrypted_encryption_key %></td>
19
+ <td><%= link_to 'Show', bjond_registration %></td>
20
+ <td><%= link_to 'Edit', edit_bjond_registration_path(bjond_registration) %></td>
21
+ <td><%= link_to 'Destroy', bjond_registration, method: :delete, data: { confirm: 'Are you sure?' } %></td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+
27
+ <br>
28
+
29
+ <%= link_to 'New Bjond registration', new_bjond_registration_path %>
30
+
31
+
32
+ <%= render 'shared/app_info.html' %>
@@ -0,0 +1,25 @@
1
+ <h1>New Bjond Registration</h1>
2
+
3
+ <%= form_for(@bjond_registration) do |f| %>
4
+ <% if @bjond_registration.errors.any? %>
5
+ <div id="error_explanation">
6
+ <h2><%= pluralize(@bjond_registration.errors.count, "error") %> prohibited this bjond_registration from being saved:</h2>
7
+
8
+ <ul>
9
+ <% @bjond_registration.errors.full_messages.each do |message| %>
10
+ <li><%= message %></li>
11
+ <% end %>
12
+ </ul>
13
+ </div>
14
+ <% end %>
15
+
16
+ <div class="field">
17
+ Enter server name (e.g. https://test.bjondhealth.com)
18
+ <%= f.text_field :server %>
19
+ </div>
20
+ <div class="actions">
21
+ <%= f.submit "Register with Bjond"%>
22
+ </div>
23
+ <% end %>
24
+
25
+ <%= link_to 'Back', bjond_registrations_path %>
@@ -0,0 +1,41 @@
1
+ <div class="show-registrations" ng-controller="registrationsController">
2
+ <p id="notice"><%= notice %></p>
3
+
4
+ <p>
5
+ <strong>Server:</strong>
6
+ <%= @bjond_registration.server %>
7
+ </p>
8
+
9
+ <p>
10
+ <strong>Host:</strong>
11
+ <%= @bjond_registration.host %>
12
+ </p>
13
+
14
+ <p>
15
+ <strong>IP:</strong>
16
+ <%= @bjond_registration.ip %>
17
+ </p>
18
+
19
+
20
+ <%- if (@bjond_registration.encrypted_encryption_key) %>
21
+ <div class="encryption-key-found">
22
+ <p>
23
+ <strong>Encryption Key (encrypted):</strong>
24
+ <%= @bjond_registration.encrypted_encryption_key %>
25
+ </p>
26
+ </div>
27
+ <% else %>
28
+ <p class="not-found">
29
+ Please log in to the Bjond server and locate the encryption key. You must be a tenant administratior. You will find this information on the 'Develop' tab of the system settings. Once you find this information, <%= link_to 'add it here', edit_bjond_registration_path(@bjond_registration) %>.
30
+ </p>
31
+
32
+ <% end %>
33
+
34
+
35
+ <button ng-click="register(<%= @bjond_registration.id %>)">
36
+ Update Registration
37
+ </button>
38
+ <%= link_to 'Edit', edit_bjond_registration_path(@bjond_registration) %> |
39
+ <%= link_to 'Back', bjond_registrations_path %>
40
+
41
+ </div>
@@ -0,0 +1,5 @@
1
+ <h1 class="title" ng-controller="homeController">
2
+ <%= @app_info.name %>
3
+ </h1>
4
+
5
+ <%= render 'shared/app_info.html' %>
@@ -0,0 +1,34 @@
1
+ <div class="integration-app">
2
+ <h2>App Info</h2>
3
+
4
+ <div class="field-wrapper">
5
+ <div class="app-label">ID:</div>
6
+ <div class="info"><%= @app_info.id %></div>
7
+ </div>
8
+
9
+ <div class="field-wrapper">
10
+ <div class="app-label">Author:</div>
11
+ <div class="info"><%= @app_info.author %></div>
12
+ </div>
13
+
14
+ <div class="field-wrapper">
15
+ <div class="app-label">Description</div>
16
+ <div class="info"><%= @app_info.description %></div>
17
+ </div>
18
+
19
+ <div class="field-wrapper">
20
+ <div class="app-label">Icon URL</div>
21
+ <div class="info"><%= @app_info.iconURL %></div>
22
+ </div>
23
+
24
+ <div class="field-wrapper">
25
+ <div class="app-label">Config URL</div>
26
+ <div class="info"><%= @app_info.configURL %></div>
27
+ </div>
28
+
29
+ <div class="field-wrapper">
30
+ <div class="app-label">Root Endpoint</div>
31
+ <div class="info"><%= @app_info.rootEndpoint %></div>
32
+ </div>
33
+
34
+ </div>
data/bin/rails ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/bjond-app/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
data/bjond-api.gemspec ADDED
@@ -0,0 +1,100 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: bjond-api 0.0.2 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "bjond-api"
9
+ s.version = "0.0.2"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Blake Rego"]
14
+ s.date = "2016-07-29"
15
+ s.description = "Rails engine that provides communication between Bj\u{f6}nd Server Core and a client app."
16
+ s.email = "blake.rego@bjondinc.com"
17
+ s.executables = ["rails"]
18
+ s.extra_rdoc_files = [
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ "Gemfile",
23
+ "Manifest",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "app/assets/images/bjond-api/.keep",
28
+ "app/assets/javascripts/bjond-api/.keep",
29
+ "app/assets/javascripts/bjond_api.js",
30
+ "app/assets/stylesheets/bjond-api/.keep",
31
+ "app/assets/stylesheets/bjond_registrations.css",
32
+ "app/assets/stylesheets/scaffold.css",
33
+ "app/controllers/.keep",
34
+ "app/controllers/bjond_registrations_controller.rb",
35
+ "app/controllers/bjondservices_controller.rb",
36
+ "app/helpers/.keep",
37
+ "app/helpers/bjond_registrations_helper.rb",
38
+ "app/mailers/.keep",
39
+ "app/models/.keep",
40
+ "app/models/bjond_registration.rb",
41
+ "app/models/bjond_service.rb",
42
+ "app/views/.keep",
43
+ "app/views/bjond_registrations/_form.html.erb",
44
+ "app/views/bjond_registrations/edit.html.erb",
45
+ "app/views/bjond_registrations/index.html.erb",
46
+ "app/views/bjond_registrations/new.html.erb",
47
+ "app/views/bjond_registrations/show.html.erb",
48
+ "app/views/bjondservices/index.html.erb",
49
+ "app/views/shared/_app_info.html.erb",
50
+ "bin/rails",
51
+ "bjond-api.gemspec",
52
+ "bjond-integration-gem.gemspec",
53
+ "bower.json",
54
+ "config/routes.rb",
55
+ "db/migrate/20160726195312_create_bjond_registrations.rb",
56
+ "db/migrate/20160726222319_rename_encryption_key_column.rb",
57
+ "db/migrate/20160726225852_add_encrypted_encryption_key_iv_to_bjond_registration.rb",
58
+ "db/migrate/20160727144938_add_host_and_ip_to_bjond_registrations.rb",
59
+ "db/migrate/20160727191615_create_bjond_services.rb",
60
+ "db/migrate/20160727194217_add_registration_id_to_bjond_service.rb",
61
+ "lib/bjond-api.rb",
62
+ "lib/bjond-app-config.rb",
63
+ "lib/bjond-app-definition.rb",
64
+ "lib/bjond-app/engine.rb",
65
+ "lib/bjond-consequence.rb",
66
+ "lib/bjond-event.rb",
67
+ "lib/bjond-field.rb",
68
+ "lib/generators/initializer_generator.rb",
69
+ "lib/generators/templates/initializer.rb"
70
+ ]
71
+ s.homepage = "http://github.com/Bjond/bjond-integration-gem"
72
+ s.licenses = ["MIT"]
73
+ s.rubygems_version = "2.4.8"
74
+ s.summary = "Interface that facilitates communication with Bj\u{f6}nd servers."
75
+
76
+ if s.respond_to? :specification_version then
77
+ s.specification_version = 4
78
+
79
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
80
+ s.add_runtime_dependency(%q<rails>, [">= 4.2.4", "~> 4.2"])
81
+ s.add_development_dependency(%q<jeweler>, [">= 2.0.1", "~> 2.0"])
82
+ s.add_runtime_dependency(%q<faraday>, ["~> 0.9.2"])
83
+ s.add_runtime_dependency(%q<syruppay_jose>, ["~> 1.0"])
84
+ s.add_runtime_dependency(%q<attr_encrypted>, [">= 3.0.3", "~> 3.0"])
85
+ else
86
+ s.add_dependency(%q<rails>, [">= 4.2.4", "~> 4.2"])
87
+ s.add_dependency(%q<jeweler>, [">= 2.0.1", "~> 2.0"])
88
+ s.add_dependency(%q<faraday>, ["~> 0.9.2"])
89
+ s.add_dependency(%q<syruppay_jose>, ["~> 1.0"])
90
+ s.add_dependency(%q<attr_encrypted>, [">= 3.0.3", "~> 3.0"])
91
+ end
92
+ else
93
+ s.add_dependency(%q<rails>, [">= 4.2.4", "~> 4.2"])
94
+ s.add_dependency(%q<jeweler>, [">= 2.0.1", "~> 2.0"])
95
+ s.add_dependency(%q<faraday>, ["~> 0.9.2"])
96
+ s.add_dependency(%q<syruppay_jose>, ["~> 1.0"])
97
+ s.add_dependency(%q<attr_encrypted>, [">= 3.0.3", "~> 3.0"])
98
+ end
99
+ end
100
+
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: bjond-integration-gem 0.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "bjond-integration-gem".freeze
9
+ s.version = "0.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Blake Rego".freeze]
14
+ s.date = "2016-07-23"
15
+ s.email = "blake.rego@bjondinc.com".freeze
16
+ s.extra_rdoc_files = [
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Manifest",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/bjond-api.rb",
26
+ "lib/bjond-app-definition.rb",
27
+ "lib/bjond-consequence.rb",
28
+ "lib/bjond-event.rb",
29
+ "lib/bjond-field.rb"
30
+ ]
31
+ s.homepage = "http://github.com/Bjond/bjond-integration-gem".freeze
32
+ s.rubygems_version = "2.6.6".freeze
33
+ s.summary = "Helper that facilitates communication with Bj\u{f6}nd servers.".freeze
34
+
35
+ if s.respond_to? :specification_version then
36
+ s.specification_version = 4
37
+
38
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
+ s.add_runtime_dependency(%q<jeweler>.freeze, [">= 0"])
40
+ s.add_runtime_dependency(%q<faraday>.freeze, [">= 0"])
41
+ else
42
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
43
+ s.add_dependency(%q<faraday>.freeze, [">= 0"])
44
+ end
45
+ else
46
+ s.add_dependency(%q<jeweler>.freeze, [">= 0"])
47
+ s.add_dependency(%q<faraday>.freeze, [">= 0"])
48
+ end
49
+ end
50
+
data/bower.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "bjond-app",
3
+ "authors": ["Blake Rego blake.rego@bjondinc.com"],
4
+ "description": "Bjond app",
5
+ "dependencies": {
6
+ "angular-mocks": "1.3.6",
7
+ "jquery": "~2.x",
8
+ "jsbn-angular": "1.4.0",
9
+ "lodash": "3.X - 4.X",
10
+ "angular-moment": "0.9.0",
11
+ "angular": "1.3.6"
12
+ },
13
+ "resolutions": {
14
+ "angular": "1.3.6",
15
+ "lodash": "3.X - 4.X"
16
+ },
17
+ "devDependencies": {}
18
+ }
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ Rails.application.routes.draw do
2
+
3
+ resources :bjond_registrations
4
+ get '/bjond-app/services/' => 'bjondservices#index'
5
+ get '/bjond-app/services/schema' => 'bjondservices#get_schema'
6
+ get '/bjond-app/services/register' => 'bjondservices#register'
7
+ post '/bjond-app/services/:groupid/register' => 'bjondservices#register_group_endpoint'
8
+ get '/bjond-app/services/:groupid/read' => 'bjondservices#get_group_configuration'
9
+ post '/bjond-app/services/:groupid/configure' => 'bjondservices#configure_group_endpoint'
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateBjondRegistrations < ActiveRecord::Migration
2
+ def change
3
+ create_table :bjond_registrations do |t|
4
+ t.string :server
5
+ t.string :encryptionKey
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class RenameEncryptionKeyColumn < ActiveRecord::Migration
2
+ def change
3
+ rename_column :bjond_registrations, :encryptionKey, :encrypted_encryption_key
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddEncryptedEncryptionKeyIvToBjondRegistration < ActiveRecord::Migration
2
+ def change
3
+ add_column :bjond_registrations, :encrypted_encryption_key_iv, :string
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddHostAndIpToBjondRegistrations < ActiveRecord::Migration
2
+ def change
3
+ add_column :bjond_registrations, :host, :string
4
+ add_column :bjond_registrations, :ip, :string
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ class CreateBjondServices < ActiveRecord::Migration
2
+ def change
3
+ create_table :bjond_services do |t|
4
+ t.string :group_id
5
+ t.string :endpoint
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class AddRegistrationIdToBjondService < ActiveRecord::Migration
2
+ def change
3
+ add_column :bjond_services, :registration_id, :string
4
+ end
5
+ end
data/lib/bjond-api.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'bjond-app-definition'
2
+ require 'bjond-consequence'
3
+ require 'bjond-event'
4
+ require 'bjond-field'
5
+ require 'faraday'
6
+ require 'bjond-app/engine'
7
+ require 'bjond-app-config'
8
+
9
+ module BjondApi
10
+
11
+ def self.register_app(integration_app, bjondhost=ENV['BJOND_SERVER'])
12
+ conn = Faraday.new(:url => bjondhost)
13
+ return conn.post do |req|
14
+ req.url '/server-core/services/integrationmanager/register?cache=1'
15
+ req.headers['Content-Type'] = 'application/json'
16
+ req.body = integration_app.to_json
17
+ end
18
+ end
19
+
20
+ end
21
+
@@ -0,0 +1,4 @@
1
+ module BjondApi
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ require 'singleton'
2
+
3
+ module BjondApi
4
+ class BjondAppConfig
5
+ include Singleton
6
+
7
+ attr_accessor :active_definition, :group_configuration_schema, :group_configuration, :encryption_key_name
8
+
9
+ self.instance.encryption_key_name = 'APP_ENCRYPTION_KEY'
10
+
11
+ def configure_group(config, bjond_registration)
12
+ puts '[ App group configuration method not implemented. This can be set via BjondAppConfig.instance.configure_group ]'
13
+ end
14
+
15
+ def get_group_configuration(bjond_registration)
16
+ puts '[ get_group_configuration method not implemented. This can be set via BjondAppConfig.instance.get_group_configuration ]'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require 'securerandom'
2
+
3
+ module BjondApi
4
+ class BjondAppDefinition
5
+ attr_accessor :id, :author, :name, :description, :rootEndpoint, :configURL, :iconURL, :rootEndpoint, :integrationEvent, :integrationConsequence
6
+
7
+ def initialize()
8
+ self.id = SecureRandom.uuid
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'securerandom'
2
+
3
+ module BjondApi
4
+ class BjondConsequence
5
+ attr_accessor :id, :json_key, :name, :description, :webhook, :service_id
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module BjondApi
3
+ class BjondEvent
4
+ attr_accessor :id, :jsonKey, :name, :description, :fields, :serviceId
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ require 'securerandom'
2
+
3
+ module BjondApi
4
+ class BjondField
5
+ attr_accessor :id, :jsonKey, :name, :description, :fieldType, :event, :options
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class InitializerGenerator < Rails::Generators::Base
2
+ source_root File.expand_path("../templates", __FILE__)
3
+
4
+ def create_initializer_file
5
+ copy_file "initializer.rb", "config/initializers/bjond_api_initializer.rb"
6
+ copy_file "../../../bower.json", "bower.json"
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ require 'bjond-api'
2
+
3
+ integration_app = BjondApi::BjondAppDefinition.new
4
+ integration_app.id = '[your-guid-here]'
5
+ integration_app.author = 'Bjond, Inc.'
6
+ integration_app.name = 'Bjond Pokitdok API'
7
+ integration_app.description = 'Testing API functionality'
8
+ integration_app.iconURL = ''
9
+
10
+ # Warning: If you change configURL, or rootEndpoint, you will need to manually configure Bjond service routes.
11
+ # We recommend leaving these two variables alone.
12
+ integration_app.configURL = "http://#{Rails.application.config.action_controller.default_url_options[:host] || `hostname`}/bjond-app/services"
13
+ integration_app.rootEndpoint = "http://#{Rails.application.config.action_controller.default_url_options[:host] || `hostname`}/bjond-app/services"
14
+
15
+
16
+
17
+ config = BjondApi::BjondAppConfig.instance
18
+ config.active_definition = integration_app
19
+ config.group_configuration_schema = {
20
+ :id => 'urn:jsonschema:com:bjond:persistence:bjondservice:GroupConfiguration',
21
+ :title => 'bjond-[name]-app-schema',
22
+ :type => 'object',
23
+ :properties => {
24
+ :sample_field => {
25
+ :type => 'string',
26
+ :description => 'Sample field description',
27
+ :title => 'Sample field'
28
+ }
29
+ },
30
+ :required => ['sample_field']
31
+ }.to_json
32
+
33
+ config.encryption_key_name = 'APP_ENCRYPTION_KEY'
34
+
35
+ def config.configure_group(result, bjond_registration)
36
+ puts '[ App group configuration method not implemented. This can be set via BjondAppConfig.instance.configure_group ]'
37
+ end
38
+
39
+ def config.get_group_configuration(bjond_registration)
40
+ puts '[ get_group_configuration method not implemented. This can be set via BjondAppConfig.instance.get_group_configuration ]'
41
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bjond-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Blake Rego
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.4
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.2.4
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: jeweler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.0.1
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.0'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.0.1
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: faraday
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 0.9.2
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 0.9.2
67
+ - !ruby/object:Gem::Dependency
68
+ name: syruppay_jose
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.0'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '1.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: attr_encrypted
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.0.3
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '3.0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 3.0.3
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: '3.0'
101
+ description: Rails engine that provides communication between Bjönd Server Core and
102
+ a client app.
103
+ email: blake.rego@bjondinc.com
104
+ executables:
105
+ - rails
106
+ extensions: []
107
+ extra_rdoc_files:
108
+ - README.rdoc
109
+ files:
110
+ - Gemfile
111
+ - Manifest
112
+ - README.rdoc
113
+ - Rakefile
114
+ - VERSION
115
+ - app/assets/images/bjond-api/.keep
116
+ - app/assets/javascripts/bjond-api/.keep
117
+ - app/assets/javascripts/bjond_api.js
118
+ - app/assets/stylesheets/bjond-api/.keep
119
+ - app/assets/stylesheets/bjond_registrations.css
120
+ - app/assets/stylesheets/scaffold.css
121
+ - app/controllers/.keep
122
+ - app/controllers/bjond_registrations_controller.rb
123
+ - app/controllers/bjondservices_controller.rb
124
+ - app/helpers/.keep
125
+ - app/helpers/bjond_registrations_helper.rb
126
+ - app/mailers/.keep
127
+ - app/models/.keep
128
+ - app/models/bjond_registration.rb
129
+ - app/models/bjond_service.rb
130
+ - app/views/.keep
131
+ - app/views/bjond_registrations/_form.html.erb
132
+ - app/views/bjond_registrations/edit.html.erb
133
+ - app/views/bjond_registrations/index.html.erb
134
+ - app/views/bjond_registrations/new.html.erb
135
+ - app/views/bjond_registrations/show.html.erb
136
+ - app/views/bjondservices/index.html.erb
137
+ - app/views/shared/_app_info.html.erb
138
+ - bin/rails
139
+ - bjond-api.gemspec
140
+ - bjond-integration-gem.gemspec
141
+ - bower.json
142
+ - config/routes.rb
143
+ - db/migrate/20160726195312_create_bjond_registrations.rb
144
+ - db/migrate/20160726222319_rename_encryption_key_column.rb
145
+ - db/migrate/20160726225852_add_encrypted_encryption_key_iv_to_bjond_registration.rb
146
+ - db/migrate/20160727144938_add_host_and_ip_to_bjond_registrations.rb
147
+ - db/migrate/20160727191615_create_bjond_services.rb
148
+ - db/migrate/20160727194217_add_registration_id_to_bjond_service.rb
149
+ - lib/bjond-api.rb
150
+ - lib/bjond-app-config.rb
151
+ - lib/bjond-app-definition.rb
152
+ - lib/bjond-app/engine.rb
153
+ - lib/bjond-consequence.rb
154
+ - lib/bjond-event.rb
155
+ - lib/bjond-field.rb
156
+ - lib/generators/initializer_generator.rb
157
+ - lib/generators/templates/initializer.rb
158
+ homepage: http://github.com/Bjond/bjond-integration-gem
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.4.8
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Interface that facilitates communication with Bjönd servers.
182
+ test_files: []