harmony-service 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/harmony_service +5 -1
- data/harmony-service.gemspec +1 -0
- data/lib/harmony/service.rb +4 -0
- data/lib/harmony/service/oauth_token_request.rb +3 -0
- data/lib/harmony/service/oauth_token_response.rb +2 -0
- data/lib/harmony/service/rake_tasks.rb +19 -0
- data/lib/harmony/service/response.rb +1 -1
- data/lib/harmony/service/rpc_service.rb +40 -42
- data/lib/harmony/service/utils/secrets.rb +13 -0
- data/lib/harmony/service/version.rb +1 -1
- data/spec/harmony/service/rpc_service_spec.rb +7 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 517ce4bdacc892b142714cc33993b5a9eca1ab5d
|
4
|
+
data.tar.gz: 6c38fc1b33244ea9d090fcf291bc1d2a7ed08042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75013f6bc6e4a20e38be17bcf4672e3caca1c723e8eabfd8943ba4855ab68894acb1810f29b31e19f84da7f2555d56a03bcdd2e0ad48f03b64ddb0c9def5a27b
|
7
|
+
data.tar.gz: 1c95cd487990d0d074ae08d75b19df57262574e64ebfd4cdc1d93039d2a186e97be3718d53c104afa886b69d8dfcba37808cfa24d6587062a94125086da24853
|
data/bin/harmony_service
CHANGED
@@ -9,8 +9,12 @@ handler_class = ARGV[0]
|
|
9
9
|
puts "Starting Harmony Service with handler: #{handler_class}"
|
10
10
|
load File.expand_path(ARGV[2])
|
11
11
|
|
12
|
+
# load env secrets
|
13
|
+
Harmony::Service::Utils::Secrets.load
|
14
|
+
|
15
|
+
abort "ENV['ampq_address'] must be defined." unless ENV['ampq_address']
|
12
16
|
opts = {
|
13
|
-
amqp: ENV['ampq_address']
|
17
|
+
amqp: ENV['ampq_address'],
|
14
18
|
vhost: ENV['ampq_vhost'] || '/',
|
15
19
|
exchange: 'sneakers',
|
16
20
|
exchange_type: :direct,
|
data/harmony-service.gemspec
CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "oj", '~> 2.17.4'
|
22
22
|
spec.add_dependency 'redis', '~> 3.3', '>= 3.3.3'
|
23
23
|
spec.add_dependency 'hashdiff', '~> 0.3.4'
|
24
|
+
spec.add_dependency 'sekrets'
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.10"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/harmony/service.rb
CHANGED
@@ -10,6 +10,9 @@ require 'harmony/service/error_response'
|
|
10
10
|
require 'harmony/service/attribute_names_request'
|
11
11
|
require 'harmony/service/attribute_names_response'
|
12
12
|
|
13
|
+
require 'harmony/service/oauth_token_request'
|
14
|
+
require 'harmony/service/oauth_token_response'
|
15
|
+
|
13
16
|
require 'harmony/service/calculator/request'
|
14
17
|
require 'harmony/service/calculator/response'
|
15
18
|
|
@@ -31,5 +34,6 @@ require 'harmony/service/notification/app_response'
|
|
31
34
|
|
32
35
|
require 'harmony/service/utils/diff'
|
33
36
|
require 'harmony/service/utils/storage'
|
37
|
+
require 'harmony/service/utils/secrets'
|
34
38
|
|
35
39
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
namespace :harmony do
|
5
|
+
desc 'Write initial secrets to encrypted file.'
|
6
|
+
task :write_secrets do |t, args|
|
7
|
+
abort "ENV['SEKRETS_KEY'] must be set." unless ENV['SEKRETS_KEY']
|
8
|
+
abort "ENV['QUEUE_NAME'] must be set." unless ENV['QUEUE_NAME']
|
9
|
+
abort "ENV['STAGING_AMPQ_URL'] must be set." unless ENV['STAGING_AMPQ_URL']
|
10
|
+
abort "ENV['PRODUCTION_AMPQ_URL'] must be set." unless ENV['PRODUCTION_AMPQ_URL']
|
11
|
+
|
12
|
+
secrets = {
|
13
|
+
development: {harmony_queue: ENV['QUEUE_NAME'], ampq_address: ENV['STAGING_AMPQ_URL'], ampq_vhost: 'harmony-staging-queue'},
|
14
|
+
staging: {harmony_queue: ENV['QUEUE_NAME'], ampq_address: ENV['STAGING_AMPQ_URL'], ampq_vhost: 'harmony-staging-queue'},
|
15
|
+
production: {harmony_queue: ENV['QUEUE_NAME'], ampq_address: ENV['PRODUCTION_AMPQ_URL'], ampq_vhost: 'harmony'}
|
16
|
+
}
|
17
|
+
`ruby -r yaml -e'puts(#{secrets}.to_yaml)' | sekrets write config/settings.yml.enc --key #{ENV['SEKRETS_KEY']}`
|
18
|
+
end
|
19
|
+
end
|
@@ -9,69 +9,66 @@ module Harmony
|
|
9
9
|
class RpcService
|
10
10
|
include Sneakers::Worker
|
11
11
|
from_queue ENV['harmony_queue'], timeout_job_after: 10, threads: 1
|
12
|
-
|
13
|
-
def work_with_params(message,
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
reject!
|
33
|
-
end
|
12
|
+
|
13
|
+
def work_with_params(message, _delivery_info, metadata)
|
14
|
+
logger.debug "Request: #{message}"
|
15
|
+
request = Oj.load(message)
|
16
|
+
request_class = request.class
|
17
|
+
response_classes = request_response_mapping[request_class]
|
18
|
+
raise "Unacceptable request class: #{request_class}" if response_classes.nil?
|
19
|
+
|
20
|
+
result = new_handler.work_with_request(request)
|
21
|
+
raise "Unacceptable response class: #{result.class}" unless response_classes.include?(result.class)
|
22
|
+
|
23
|
+
send_response(result, metadata)
|
24
|
+
ack!
|
25
|
+
rescue StandardError => error
|
26
|
+
logger.error error.message
|
27
|
+
logger.error error.backtrace.join("\n")
|
28
|
+
|
29
|
+
error_response = ErrorResponse.new message: error.message, exception: error
|
30
|
+
send_response(error_response, metadata)
|
31
|
+
reject!
|
34
32
|
end
|
35
|
-
|
33
|
+
|
36
34
|
def stop
|
37
35
|
super
|
38
|
-
#reply_to_exchange.close # not working
|
36
|
+
# reply_to_exchange.close # not working
|
39
37
|
reply_to_connection.close
|
40
38
|
end
|
41
|
-
|
39
|
+
|
42
40
|
def reply_to_connection
|
43
41
|
@reply_to_connection ||= create_reply_to_connection
|
44
42
|
end
|
45
|
-
|
43
|
+
|
46
44
|
def create_reply_to_connection
|
47
45
|
opts = Sneakers::CONFIG
|
48
|
-
conn = Bunny.new(opts[:amqp], :
|
46
|
+
conn = Bunny.new(opts[:amqp], vhost: opts[:vhost], heartbeat: opts[:heartbeat], logger: Sneakers.logger)
|
49
47
|
conn.start
|
50
48
|
conn
|
51
49
|
end
|
52
|
-
|
50
|
+
|
53
51
|
def reply_to_exchange
|
54
52
|
@reply_to_queue ||= create_reply_to_exchange
|
55
53
|
end
|
56
|
-
|
54
|
+
|
57
55
|
def create_reply_to_exchange
|
58
56
|
ch = reply_to_connection.create_channel
|
59
|
-
ch.exchange(AMQ::Protocol::EMPTY_STRING, :
|
57
|
+
ch.exchange(AMQ::Protocol::EMPTY_STRING, auto_delete: true)
|
60
58
|
end
|
61
|
-
|
62
|
-
|
59
|
+
|
63
60
|
private
|
61
|
+
|
64
62
|
def send_response(result, metadata)
|
65
63
|
json = Oj.dump(result)
|
66
64
|
logger.debug "Response: #{json}"
|
67
65
|
send_response_json(json, metadata.reply_to, metadata.correlation_id)
|
68
66
|
end
|
69
|
-
|
67
|
+
|
70
68
|
def send_response_json(json, routing_key, correlation_id)
|
71
|
-
reply_to_exchange.publish(json, :
|
69
|
+
reply_to_exchange.publish(json, routing_key: routing_key, correlation_id: correlation_id)
|
72
70
|
end
|
73
|
-
|
74
|
-
|
71
|
+
|
75
72
|
def request_response_mapping
|
76
73
|
{
|
77
74
|
Calculator::Request => [Calculator::Response],
|
@@ -82,19 +79,20 @@ module Harmony
|
|
82
79
|
Form::GetRequest => [Form::GetResponse],
|
83
80
|
Flow::EndedRequest => [Response],
|
84
81
|
Notification::Request => [Notification::AppResponse, Response],
|
85
|
-
AttributeNamesRequest => [AttributeNamesResponse]
|
82
|
+
AttributeNamesRequest => [AttributeNamesResponse],
|
83
|
+
OauthTokenRequest => [OauthTokenResponse]
|
86
84
|
}
|
87
85
|
end
|
88
|
-
|
86
|
+
|
89
87
|
def new_handler
|
90
88
|
handler_class = Sneakers::CONFIG[:handler_class]
|
91
|
-
raise
|
92
|
-
|
89
|
+
raise 'No handler specified' if handler_class.nil?
|
90
|
+
|
93
91
|
handler = Object.const_get(handler_class).new
|
94
92
|
raise "Unable to create handler: #{handler_class}" if handler.nil?
|
95
|
-
|
93
|
+
|
96
94
|
handler
|
97
95
|
end
|
98
96
|
end
|
99
97
|
end
|
100
|
-
end
|
98
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'sekrets'
|
2
|
+
|
3
|
+
class Harmony::Service::Utils::Secrets
|
4
|
+
|
5
|
+
def self.load
|
6
|
+
env = ENV['HARMONY_ENV']
|
7
|
+
abort "ENV['HARMONY_ENV'] must be set." unless env
|
8
|
+
|
9
|
+
secrets = Sekrets.settings_for('./config/settings.yml.enc')[env]
|
10
|
+
secrets.each_pair{|k,v| ENV[k] = v.to_s }
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -86,6 +86,13 @@ describe Harmony::Service::RpcService do
|
|
86
86
|
it { expect(subject).to have_received(:send_response_json).with("{\"^o\":\"Harmony::Service::AttributeNamesResponse\",\"options\":{}}", "harmony.trello", "abc123") }
|
87
87
|
it { expect(subject).to have_received(:ack!) }
|
88
88
|
end
|
89
|
+
|
90
|
+
context "oauth_token" do
|
91
|
+
let(:request) { Harmony::Service::OauthTokenRequest.new }
|
92
|
+
let(:response) { Harmony::Service::OauthTokenResponse.new}
|
93
|
+
it { expect(subject).to have_received(:send_response_json).with("{\"^o\":\"Harmony::Service::OauthTokenResponse\"}", "harmony.trello", "abc123") }
|
94
|
+
it { expect(subject).to have_received(:ack!) }
|
95
|
+
end
|
89
96
|
|
90
97
|
context "exception" do
|
91
98
|
let(:handler) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: harmony-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brooke-Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sneakers
|
@@ -86,6 +86,20 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 0.3.4
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: sekrets
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
89
103
|
- !ruby/object:Gem::Dependency
|
90
104
|
name: bundler
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,10 +180,14 @@ files:
|
|
166
180
|
- lib/harmony/service/message.rb
|
167
181
|
- lib/harmony/service/notification/app_response.rb
|
168
182
|
- lib/harmony/service/notification/request.rb
|
183
|
+
- lib/harmony/service/oauth_token_request.rb
|
184
|
+
- lib/harmony/service/oauth_token_response.rb
|
185
|
+
- lib/harmony/service/rake_tasks.rb
|
169
186
|
- lib/harmony/service/request.rb
|
170
187
|
- lib/harmony/service/response.rb
|
171
188
|
- lib/harmony/service/rpc_service.rb
|
172
189
|
- lib/harmony/service/utils/diff.rb
|
190
|
+
- lib/harmony/service/utils/secrets.rb
|
173
191
|
- lib/harmony/service/utils/storage.rb
|
174
192
|
- lib/harmony/service/version.rb
|
175
193
|
- spec/harmony/service/rpc_service_spec.rb
|
@@ -196,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
214
|
version: '0'
|
197
215
|
requirements: []
|
198
216
|
rubyforge_project:
|
199
|
-
rubygems_version: 2.6.
|
217
|
+
rubygems_version: 2.6.14
|
200
218
|
signing_key:
|
201
219
|
specification_version: 4
|
202
220
|
summary: Gem which helps you to build Harmony services
|