hoodoo 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/hoodoo/client/endpoint/endpoints/amqp.rb +43 -25
- data/lib/hoodoo/discovery.rb +1 -1
- data/lib/hoodoo/services/discovery/discoverers/by_flux.rb +130 -0
- data/lib/hoodoo/services/discovery/results/for_amqp.rb +15 -21
- data/lib/hoodoo/services/discovery/results/for_local.rb +17 -0
- data/lib/hoodoo/services/middleware/amqp_log_message.rb +92 -154
- data/lib/hoodoo/services/middleware/amqp_log_writer.rb +25 -50
- data/lib/hoodoo/services/middleware/middleware.rb +75 -25
- data/lib/hoodoo/services/services/service.rb +2 -2
- data/lib/hoodoo/version.rb +1 -1
- data/spec/services/discovery/discoverers/by_flux_spec.rb +134 -0
- data/spec/services/discovery/results/for_amqp_spec.rb +4 -7
- data/spec/services/discovery/results/for_local_spec.rb +4 -0
- data/spec/services/middleware/amqp_log_message_spec.rb +32 -34
- data/spec/services/middleware/amqp_log_writer_spec.rb +2 -5
- data/spec/services/middleware/middleware_exotic_communication_spec.rb +147 -143
- data/spec/services/middleware/middleware_logging_spec.rb +10 -10
- data/spec/services/middleware/middleware_multi_remote_spec.rb +1 -1
- data/spec/services/middleware/middleware_public_spec.rb +73 -18
- data/spec/services/middleware/middleware_spec.rb +4 -4
- data/spec/services/services/application_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -8
- metadata +19 -7
- data/lib/hoodoo/services/discovery/discoverers/by_consul.rb +0 -66
- data/spec/alchemy/alchemy-amq.rb +0 -33
- data/spec/services/discovery/discoverers/by_consul_spec.rb +0 -29
@@ -1,5 +1,5 @@
|
|
1
1
|
# service_middleware_spec.rb is too large. This file covers logging
|
2
|
-
# extentions around StructuredLogger
|
2
|
+
# extentions around StructuredLogger.
|
3
3
|
|
4
4
|
require 'spec_helper'
|
5
5
|
|
@@ -101,8 +101,8 @@ describe Hoodoo::Services::Middleware do
|
|
101
101
|
|
102
102
|
context 'off queue' do
|
103
103
|
before :each do
|
104
|
-
@old_queue = ENV[ '
|
105
|
-
ENV[ '
|
104
|
+
@old_queue = ENV[ 'AMQ_URI' ]
|
105
|
+
ENV[ 'AMQ_URI' ] = nil
|
106
106
|
|
107
107
|
@cvar = false
|
108
108
|
if Hoodoo::Services::Middleware.class_variable_defined?( '@@alchemy' )
|
@@ -112,7 +112,7 @@ describe Hoodoo::Services::Middleware do
|
|
112
112
|
end
|
113
113
|
|
114
114
|
after :each do
|
115
|
-
ENV[ '
|
115
|
+
ENV[ 'AMQ_URI' ] = @old_queue
|
116
116
|
|
117
117
|
if Hoodoo::Services::Middleware.class_variable_defined?( '@@alchemy' )
|
118
118
|
if @cvar == true
|
@@ -155,8 +155,8 @@ describe Hoodoo::Services::Middleware do
|
|
155
155
|
|
156
156
|
context 'on queue' do
|
157
157
|
before :each do
|
158
|
-
@old_queue = ENV[ '
|
159
|
-
ENV[ '
|
158
|
+
@old_queue = ENV[ 'AMQ_URI' ]
|
159
|
+
ENV[ 'AMQ_URI' ] = 'amqp://test:test@127.0.0.1'
|
160
160
|
|
161
161
|
@cvar = false
|
162
162
|
if Hoodoo::Services::Middleware.class_variable_defined?( '@@alchemy' )
|
@@ -166,7 +166,7 @@ describe Hoodoo::Services::Middleware do
|
|
166
166
|
end
|
167
167
|
|
168
168
|
after :each do
|
169
|
-
ENV[ '
|
169
|
+
ENV[ 'AMQ_URI' ] = @old_queue
|
170
170
|
|
171
171
|
if Hoodoo::Services::Middleware.class_variable_defined?( '@@alchemy' )
|
172
172
|
if @cvar == true
|
@@ -182,7 +182,7 @@ describe Hoodoo::Services::Middleware do
|
|
182
182
|
@app = app
|
183
183
|
end
|
184
184
|
def call(env)
|
185
|
-
env['
|
185
|
+
env['alchemy.service'] = self
|
186
186
|
@app.call(env)
|
187
187
|
end
|
188
188
|
def send_message(*args)
|
@@ -214,7 +214,7 @@ describe Hoodoo::Services::Middleware do
|
|
214
214
|
it 'has the expected "development" mode loggers' do
|
215
215
|
force_logging_to( 'development' )
|
216
216
|
|
217
|
-
expect_any_instance_of(FakeAlchemy).to receive(:
|
217
|
+
expect_any_instance_of(FakeAlchemy).to receive(:send_message_to_queue).at_least(:once)
|
218
218
|
spec_helper_silence_stdout() do
|
219
219
|
get '/v1/test_log/hello', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
220
220
|
end
|
@@ -228,7 +228,7 @@ describe Hoodoo::Services::Middleware do
|
|
228
228
|
it 'has the expected "production" mode loggers' do
|
229
229
|
force_logging_to( 'production' )
|
230
230
|
|
231
|
-
expect_any_instance_of(FakeAlchemy).to receive(:
|
231
|
+
expect_any_instance_of(FakeAlchemy).to receive(:send_message_to_queue).at_least(:once)
|
232
232
|
get '/v1/test_log/hello', nil, { 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
233
233
|
|
234
234
|
instances = Hoodoo::Services::Middleware.logger.instances
|
@@ -403,7 +403,7 @@ describe Hoodoo::Services::Middleware do
|
|
403
403
|
|
404
404
|
response = spec_helper_http(
|
405
405
|
port: @port,
|
406
|
-
path: '/
|
406
|
+
path: '/2/TestEcho.tar.gz?limit=25&offset=75&_reference=embed_one,embed_two',
|
407
407
|
headers: headers
|
408
408
|
)
|
409
409
|
|
@@ -59,9 +59,16 @@ end
|
|
59
59
|
|
60
60
|
describe Hoodoo::Services::Middleware do
|
61
61
|
|
62
|
-
def try_to_call( endpoint
|
62
|
+
def try_to_call( endpoint: nil,
|
63
|
+
resource: nil,
|
64
|
+
ident: nil )
|
65
|
+
|
66
|
+
path = resource.nil? ?
|
67
|
+
"/v1/#{ endpoint }/#{ ident }" :
|
68
|
+
"/1/#{ resource }/#{ ident }"
|
69
|
+
|
63
70
|
get(
|
64
|
-
|
71
|
+
path,
|
65
72
|
nil,
|
66
73
|
{ 'CONTENT_TYPE' => 'application/json; charset=utf-8' }
|
67
74
|
)
|
@@ -102,24 +109,36 @@ describe Hoodoo::Services::Middleware do
|
|
102
109
|
|
103
110
|
context '#list' do
|
104
111
|
it 'prohibits actions without session', :without_session => true do
|
105
|
-
try_to_call( 'no_public_action' )
|
112
|
+
try_to_call( endpoint: 'no_public_action' )
|
113
|
+
expect( last_response.status ).to eq( 401 )
|
114
|
+
|
115
|
+
try_to_call( resource: 'NoPublicAction' )
|
106
116
|
expect( last_response.status ).to eq( 401 )
|
107
117
|
end
|
108
118
|
|
109
119
|
it 'allows actions with session' do
|
110
|
-
try_to_call( 'no_public_action' )
|
120
|
+
try_to_call( endpoint: 'no_public_action' )
|
121
|
+
expect( last_response.status ).to eq( 200 )
|
122
|
+
|
123
|
+
try_to_call( resource: 'NoPublicAction' )
|
111
124
|
expect( last_response.status ).to eq( 200 )
|
112
125
|
end
|
113
126
|
end
|
114
127
|
|
115
128
|
context '#show' do
|
116
129
|
it 'prohibits actions without session', :without_session => true do
|
117
|
-
try_to_call( 'no_public_action', 'some_uuid' )
|
130
|
+
try_to_call( endpoint: 'no_public_action', ident: 'some_uuid' )
|
131
|
+
expect( last_response.status ).to eq( 401 )
|
132
|
+
|
133
|
+
try_to_call( resource: 'NoPublicAction', ident: 'some_uuid' )
|
118
134
|
expect( last_response.status ).to eq( 401 )
|
119
135
|
end
|
120
136
|
|
121
137
|
it 'allows actions with session' do
|
122
|
-
try_to_call( 'no_public_action', 'some_uuid' )
|
138
|
+
try_to_call( endpoint: 'no_public_action', ident: 'some_uuid' )
|
139
|
+
expect( last_response.status ).to eq( 200 )
|
140
|
+
|
141
|
+
try_to_call( resource: 'NoPublicAction', ident: 'some_uuid' )
|
123
142
|
expect( last_response.status ).to eq( 200 )
|
124
143
|
end
|
125
144
|
end
|
@@ -145,22 +164,34 @@ describe Hoodoo::Services::Middleware do
|
|
145
164
|
end
|
146
165
|
|
147
166
|
it 'prohibits secure actions without session', :without_session => true do
|
148
|
-
try_to_call( 'public_action', 'some_uuid' )
|
167
|
+
try_to_call( endpoint: 'public_action', ident: 'some_uuid' )
|
168
|
+
expect( last_response.status ).to eq( 401 )
|
169
|
+
|
170
|
+
try_to_call( resource: 'PublicAction', ident: 'some_uuid' )
|
149
171
|
expect( last_response.status ).to eq( 401 )
|
150
172
|
end
|
151
173
|
|
152
174
|
it 'allows secure actions with session' do
|
153
|
-
try_to_call( 'public_action', 'some_uuid' )
|
175
|
+
try_to_call( endpoint: 'public_action', ident: 'some_uuid' )
|
176
|
+
expect( last_response.status ).to eq( 200 )
|
177
|
+
|
178
|
+
try_to_call( resource: 'PublicAction', ident: 'some_uuid' )
|
154
179
|
expect( last_response.status ).to eq( 200 )
|
155
180
|
end
|
156
181
|
|
157
182
|
it 'allows public actions without session', :without_session => true do
|
158
|
-
try_to_call( 'public_action' )
|
183
|
+
try_to_call( endpoint: 'public_action' )
|
184
|
+
expect( last_response.status ).to eq( 200 )
|
185
|
+
|
186
|
+
try_to_call( resource: 'PublicAction' )
|
159
187
|
expect( last_response.status ).to eq( 200 )
|
160
188
|
end
|
161
189
|
|
162
190
|
it 'allows public actions with session' do
|
163
|
-
try_to_call( 'public_action' )
|
191
|
+
try_to_call( endpoint: 'public_action' )
|
192
|
+
expect( last_response.status ).to eq( 200 )
|
193
|
+
|
194
|
+
try_to_call( resource: 'PublicAction' )
|
164
195
|
expect( last_response.status ).to eq( 200 )
|
165
196
|
end
|
166
197
|
end
|
@@ -187,24 +218,36 @@ describe Hoodoo::Services::Middleware do
|
|
187
218
|
context 'in interface with no public actions' do
|
188
219
|
context '#list' do
|
189
220
|
it 'prohibits actions without session', :without_session => true do
|
190
|
-
try_to_call( 'no_public_action' )
|
221
|
+
try_to_call( endpoint: 'no_public_action' )
|
222
|
+
expect( last_response.status ).to eq( 401 )
|
223
|
+
|
224
|
+
try_to_call( resource: 'NoPublicAction' )
|
191
225
|
expect( last_response.status ).to eq( 401 )
|
192
226
|
end
|
193
227
|
|
194
228
|
it 'allows actions with session' do
|
195
|
-
try_to_call( 'no_public_action' )
|
229
|
+
try_to_call( endpoint: 'no_public_action' )
|
230
|
+
expect( last_response.status ).to eq( 200 )
|
231
|
+
|
232
|
+
try_to_call( resource: 'NoPublicAction' )
|
196
233
|
expect( last_response.status ).to eq( 200 )
|
197
234
|
end
|
198
235
|
end
|
199
236
|
|
200
237
|
context '#show' do
|
201
238
|
it 'prohibits actions without session', :without_session => true do
|
202
|
-
try_to_call( 'no_public_action', 'some_uuid' )
|
239
|
+
try_to_call( endpoint: 'no_public_action', ident: 'some_uuid' )
|
240
|
+
expect( last_response.status ).to eq( 401 )
|
241
|
+
|
242
|
+
try_to_call( resource: 'NoPublicAction', ident: 'some_uuid' )
|
203
243
|
expect( last_response.status ).to eq( 401 )
|
204
244
|
end
|
205
245
|
|
206
246
|
it 'allows actions with session' do
|
207
|
-
try_to_call( 'no_public_action', 'some_uuid' )
|
247
|
+
try_to_call( endpoint: 'no_public_action', ident: 'some_uuid' )
|
248
|
+
expect( last_response.status ).to eq( 200 )
|
249
|
+
|
250
|
+
try_to_call( resource: 'NoPublicAction', ident: 'some_uuid' )
|
208
251
|
expect( last_response.status ).to eq( 200 )
|
209
252
|
end
|
210
253
|
end
|
@@ -212,22 +255,34 @@ describe Hoodoo::Services::Middleware do
|
|
212
255
|
|
213
256
|
context 'in interface with public actions' do
|
214
257
|
it 'prohibits secure actions without session', :without_session => true do
|
215
|
-
try_to_call( 'public_action', 'some_uuid' )
|
258
|
+
try_to_call( endpoint: 'public_action', ident: 'some_uuid' )
|
259
|
+
expect( last_response.status ).to eq( 401 )
|
260
|
+
|
261
|
+
try_to_call( resource: 'PublicAction', ident: 'some_uuid' )
|
216
262
|
expect( last_response.status ).to eq( 401 )
|
217
263
|
end
|
218
264
|
|
219
265
|
it 'allows secure actions with session' do
|
220
|
-
try_to_call( 'public_action', 'some_uuid' )
|
266
|
+
try_to_call( endpoint: 'public_action', ident: 'some_uuid' )
|
267
|
+
expect( last_response.status ).to eq( 200 )
|
268
|
+
|
269
|
+
try_to_call( resource: 'PublicAction', ident: 'some_uuid' )
|
221
270
|
expect( last_response.status ).to eq( 200 )
|
222
271
|
end
|
223
272
|
|
224
273
|
it 'allows public actions without session', :without_session => true do
|
225
|
-
try_to_call( 'public_action' )
|
274
|
+
try_to_call( endpoint: 'public_action' )
|
275
|
+
expect( last_response.status ).to eq( 200 )
|
276
|
+
|
277
|
+
try_to_call( resource: 'PublicAction' )
|
226
278
|
expect( last_response.status ).to eq( 200 )
|
227
279
|
end
|
228
280
|
|
229
281
|
it 'allows public actions with session' do
|
230
|
-
try_to_call( 'public_action' )
|
282
|
+
try_to_call( endpoint: 'public_action' )
|
283
|
+
expect( last_response.status ).to eq( 200 )
|
284
|
+
|
285
|
+
try_to_call( resource: 'PublicAction' )
|
231
286
|
expect( last_response.status ).to eq( 200 )
|
232
287
|
end
|
233
288
|
end
|
@@ -194,12 +194,12 @@ describe Hoodoo::Services::Middleware do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
it 'should know about a queue' do
|
197
|
-
old = ENV[ '
|
198
|
-
ENV[ '
|
197
|
+
old = ENV[ 'AMQ_URI' ]
|
198
|
+
ENV[ 'AMQ_URI' ] = nil
|
199
199
|
expect(Hoodoo::Services::Middleware.on_queue?).to eq(false)
|
200
|
-
ENV[ '
|
200
|
+
ENV[ 'AMQ_URI' ] = 'foo'
|
201
201
|
expect(Hoodoo::Services::Middleware.on_queue?).to eq(true)
|
202
|
-
ENV[ '
|
202
|
+
ENV[ 'AMQ_URI' ] = old
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
@@ -28,17 +28,17 @@ describe Hoodoo::Services::Service do
|
|
28
28
|
it 'should complain about incorrect interface classes' do
|
29
29
|
expect {
|
30
30
|
RSpecTestService.comprised_of( Hash )
|
31
|
-
}.to raise_error(RuntimeError, "Hoodoo::Services::
|
31
|
+
}.to raise_error(RuntimeError, "Hoodoo::Services::Service::comprised_of expects Hoodoo::Services::Interface subclasses only - got 'Hash'")
|
32
32
|
|
33
33
|
expect {
|
34
34
|
RSpecTestService.comprised_of( Hoodoo::Services::Interface )
|
35
|
-
}.to raise_error(RuntimeError, "Hoodoo::Services::
|
35
|
+
}.to raise_error(RuntimeError, "Hoodoo::Services::Service::comprised_of expects Hoodoo::Services::Interface subclasses only - got 'Hoodoo::Services::Interface'")
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should complain if called directly' do
|
39
39
|
expect {
|
40
40
|
RSpecTestService.new.call( nil )
|
41
|
-
}.to raise_error(RuntimeError, "Hoodoo::Services::
|
41
|
+
}.to raise_error(RuntimeError, "Hoodoo::Services::Service subclasses should only be called through the middleware - add 'use Hoodoo::Services::Middleware' to (e.g.) config.ru")
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should correctly report its component classes' do
|
data/spec/spec_helper.rb
CHANGED
@@ -30,17 +30,12 @@ require 'database_cleaner'
|
|
30
30
|
require 'active_record'
|
31
31
|
require 'logger'
|
32
32
|
|
33
|
-
# Include
|
34
|
-
|
35
|
-
# TODO: See spec/alchemy/alchemy-amq.rb. Remove this once 'real' Alchemy
|
36
|
-
# is opened.
|
37
|
-
#
|
38
|
-
$LOAD_PATH.unshift File.join( File.dirname( __FILE__ ), 'alchemy' )
|
33
|
+
# Include Alchemy Flux for testing only.
|
39
34
|
|
40
35
|
begin
|
41
|
-
require 'alchemy-
|
36
|
+
require 'alchemy-flux'
|
42
37
|
rescue LoadError
|
43
|
-
raise 'Cannot load alchemy-
|
38
|
+
raise 'Cannot load alchemy-flux; did you run me with "bundle exec..." ?'
|
44
39
|
end
|
45
40
|
|
46
41
|
# Now it's safe to require Rack test code and Hoodoo itself.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoodoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loyalty New Zealand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: uuidtools
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.6'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: alchemy-flux
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.1'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.1'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rspec
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -348,11 +362,11 @@ files:
|
|
348
362
|
- lib/hoodoo/presenters/types/text.rb
|
349
363
|
- lib/hoodoo/presenters/types/uuid.rb
|
350
364
|
- lib/hoodoo/services.rb
|
351
|
-
- lib/hoodoo/services/discovery/discoverers/by_consul.rb
|
352
365
|
- lib/hoodoo/services/discovery/discoverers/by_convention.rb
|
353
366
|
- lib/hoodoo/services/discovery/discoverers/by_drb/by_drb.rb
|
354
367
|
- lib/hoodoo/services/discovery/discoverers/by_drb/drb_server.rb
|
355
368
|
- lib/hoodoo/services/discovery/discoverers/by_drb/drb_server_start.rb
|
369
|
+
- lib/hoodoo/services/discovery/discoverers/by_flux.rb
|
356
370
|
- lib/hoodoo/services/discovery/discovery.rb
|
357
371
|
- lib/hoodoo/services/discovery/results/for_amqp.rb
|
358
372
|
- lib/hoodoo/services/discovery/results/for_http.rb
|
@@ -393,7 +407,6 @@ files:
|
|
393
407
|
- spec/active/active_record/translated_spec.rb
|
394
408
|
- spec/active/active_record/uuid_spec.rb
|
395
409
|
- spec/active/active_record/writer_spec.rb
|
396
|
-
- spec/alchemy/alchemy-amq.rb
|
397
410
|
- spec/client/augmented_array_spec.rb
|
398
411
|
- spec/client/augmented_base_spec.rb
|
399
412
|
- spec/client/augmented_hash_spec.rb
|
@@ -446,10 +459,10 @@ files:
|
|
446
459
|
- spec/presenters/types/text_spec.rb
|
447
460
|
- spec/presenters/types/uuid_spec.rb
|
448
461
|
- spec/presenters/walk_spec.rb
|
449
|
-
- spec/services/discovery/discoverers/by_consul_spec.rb
|
450
462
|
- spec/services/discovery/discoverers/by_convention_spec.rb
|
451
463
|
- spec/services/discovery/discoverers/by_drb/by_drb_spec.rb
|
452
464
|
- spec/services/discovery/discoverers/by_drb/drb_server_spec.rb
|
465
|
+
- spec/services/discovery/discoverers/by_flux_spec.rb
|
453
466
|
- spec/services/discovery/discovery_spec.rb
|
454
467
|
- spec/services/discovery/results/for_amqp_spec.rb
|
455
468
|
- spec/services/discovery/results/for_http_spec.rb
|
@@ -522,7 +535,6 @@ test_files:
|
|
522
535
|
- spec/active/active_record/translated_spec.rb
|
523
536
|
- spec/active/active_record/uuid_spec.rb
|
524
537
|
- spec/active/active_record/writer_spec.rb
|
525
|
-
- spec/alchemy/alchemy-amq.rb
|
526
538
|
- spec/client/augmented_array_spec.rb
|
527
539
|
- spec/client/augmented_base_spec.rb
|
528
540
|
- spec/client/augmented_hash_spec.rb
|
@@ -575,10 +587,10 @@ test_files:
|
|
575
587
|
- spec/presenters/types/text_spec.rb
|
576
588
|
- spec/presenters/types/uuid_spec.rb
|
577
589
|
- spec/presenters/walk_spec.rb
|
578
|
-
- spec/services/discovery/discoverers/by_consul_spec.rb
|
579
590
|
- spec/services/discovery/discoverers/by_convention_spec.rb
|
580
591
|
- spec/services/discovery/discoverers/by_drb/by_drb_spec.rb
|
581
592
|
- spec/services/discovery/discoverers/by_drb/drb_server_spec.rb
|
593
|
+
- spec/services/discovery/discoverers/by_flux_spec.rb
|
582
594
|
- spec/services/discovery/discovery_spec.rb
|
583
595
|
- spec/services/discovery/results/for_amqp_spec.rb
|
584
596
|
- spec/services/discovery/results/for_http_spec.rb
|
@@ -1,66 +0,0 @@
|
|
1
|
-
########################################################################
|
2
|
-
# File:: by_consul.rb
|
3
|
-
# (C):: Loyalty New Zealand 2015
|
4
|
-
#
|
5
|
-
# Purpose:: Discover resource endpoint locations via a registry held in
|
6
|
-
# Consul. For AMQP-based endpoints; maps paths to queue names.
|
7
|
-
# PLACEHOLDER: NOT YET IMPLEMENTED.
|
8
|
-
# ----------------------------------------------------------------------
|
9
|
-
# 03-Mar-2015 (ADH): Created.
|
10
|
-
########################################################################
|
11
|
-
|
12
|
-
module Hoodoo
|
13
|
-
module Services
|
14
|
-
class Discovery # Just used as a namespace here
|
15
|
-
|
16
|
-
# Discover resource endpoint locations via a registry held in
|
17
|
-
# Consul. For AMQP-based endpoints; maps paths to queue names.
|
18
|
-
#
|
19
|
-
class ByConsul < Hoodoo::Services::Discovery
|
20
|
-
|
21
|
-
protected
|
22
|
-
|
23
|
-
# Announce the location of an instance to Consul.
|
24
|
-
#
|
25
|
-
# Call via Hoodoo::Services::Discovery::Base#announce.
|
26
|
-
#
|
27
|
-
# TODO: NOT YET IMPLEMENTED. Placeholder only.
|
28
|
-
#
|
29
|
-
# +resource+:: Passed to #discover_remote.
|
30
|
-
# +version+:: Passed to #discover_remote.
|
31
|
-
# +options+:: Ignored. TODO: Queue name, equivalent path.
|
32
|
-
#
|
33
|
-
def announce_remote( resource, version, options = {} )
|
34
|
-
return discover_remote( resource, version ) # TODO: Replace
|
35
|
-
end
|
36
|
-
|
37
|
-
# Discover the location of an instance using Consul.
|
38
|
-
#
|
39
|
-
# TODO: This currently doesn't use Consul at all! It has a
|
40
|
-
# TODO: hard-coded mapping.
|
41
|
-
#
|
42
|
-
# Returns a Hoodoo::Services::Discovery::ForAMQP instance if
|
43
|
-
# the endpoint is found, else +nil+.
|
44
|
-
#
|
45
|
-
# Call via Hoodoo::Services::Discovery::Base#announce.
|
46
|
-
#
|
47
|
-
# +resource+:: Passed to #discover_remote.
|
48
|
-
# +version+:: Passed to #discover_remote.
|
49
|
-
#
|
50
|
-
def discover_remote( resource, version )
|
51
|
-
|
52
|
-
queue = "service.#{ resource.to_s.downcase }"
|
53
|
-
path = "/v#{ version }/#{ resource.to_s.downcase.pluralize }"
|
54
|
-
|
55
|
-
return Hoodoo::Services::Discovery::ForAMQP.new(
|
56
|
-
resource: resource,
|
57
|
-
version: version,
|
58
|
-
queue_name: queue,
|
59
|
-
equivalent_path: path
|
60
|
-
)
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|