hoodoo 1.14.0 → 1.15.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 +4 -4
- data/lib/hoodoo/services/middleware/endpoints/inter_resource_remote.rb +1 -1
- data/lib/hoodoo/services/middleware/middleware.rb +2 -2
- data/lib/hoodoo/services/services/session.rb +205 -144
- data/lib/hoodoo/transient_store/transient_store.rb +13 -4
- data/lib/hoodoo/transient_store/transient_store/memcached.rb +8 -0
- data/lib/hoodoo/version.rb +1 -1
- data/spec/active/active_record/finder_spec.rb +4 -4
- data/spec/client/client_spec.rb +4 -0
- data/spec/services/middleware/middleware_permissions_spec.rb +28 -32
- data/spec/services/services/session_spec.rb +485 -353
- data/spec/spec_helper.rb +31 -10
- data/spec/transient_store/transient_store/memcached_redis_mirror_spec.rb +3 -13
- data/spec/transient_store/transient_store/memcached_spec.rb +15 -0
- data/spec/transient_store/transient_store_spec.rb +11 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fad91d3880f61878b0df4c509f63f8afd7b7ed21
|
4
|
+
data.tar.gz: 0c2502907dd97eda85b8ede8369c85935bc2a89a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c011115dcfee583a769f46deb6e167847208860c3fcb7f878191d5c6ef8f51757845530d44ab07f01b387522e730215911865b447e6f93bd78480f28a78abb8a
|
7
|
+
data.tar.gz: 2df1b22163e1944e86e4d546bcc950ada63eba410d841e94e144aadcb2696531dfa7f1c3c0427c5bc8ba9184f8ba438a5b9def124c2dc1cc96a21b30586d171f
|
@@ -949,7 +949,7 @@ module Hoodoo; module Services
|
|
949
949
|
# Ignore errors, there's nothing much we can do about them and in
|
950
950
|
# the worst case we just have to wait for this to expire naturally.
|
951
951
|
|
952
|
-
session.
|
952
|
+
session.delete_from_store()
|
953
953
|
end
|
954
954
|
|
955
955
|
# Extract the returned data, handling error conditions.
|
@@ -1629,7 +1629,7 @@ module Hoodoo; module Services
|
|
1629
1629
|
:session_id => session_id
|
1630
1630
|
)
|
1631
1631
|
|
1632
|
-
result = session.
|
1632
|
+
result = session.load_from_store!( session_id )
|
1633
1633
|
session = nil if result != :ok
|
1634
1634
|
elsif ( self.class.environment.test? || self.class.environment.development? )
|
1635
1635
|
interaction.using_test_session()
|
@@ -9,7 +9,7 @@
|
|
9
9
|
########################################################################
|
10
10
|
|
11
11
|
require 'ostruct'
|
12
|
-
require '
|
12
|
+
require 'hoodoo/transient_store'
|
13
13
|
require 'hoodoo/transient_store/mocks/dalli_client'
|
14
14
|
|
15
15
|
module Hoodoo
|
@@ -20,8 +20,7 @@ module Hoodoo
|
|
20
20
|
class Session
|
21
21
|
|
22
22
|
# Time To Live: Number of seconds for which a session remains valid
|
23
|
-
# after being saved.
|
24
|
-
# stores that support TTL such as Memcached - see #save_to_memcached.
|
23
|
+
# after being saved.
|
25
24
|
#
|
26
25
|
TTL = 172800 # 48 hours
|
27
26
|
|
@@ -47,8 +46,8 @@ module Hoodoo
|
|
47
46
|
# version changes, associated sessions are flushed.
|
48
47
|
#
|
49
48
|
# If you _change_ a Caller version in a Session, you _really_ should
|
50
|
-
# call #
|
51
|
-
# change gets recognised in
|
49
|
+
# call #save_to_store as soon as possible afterwards so that the
|
50
|
+
# change gets recognised in the transient store.
|
52
51
|
#
|
53
52
|
attr_accessor :caller_version
|
54
53
|
|
@@ -107,7 +106,7 @@ module Hoodoo
|
|
107
106
|
# Only set when the session is saved (or loaded from a representation
|
108
107
|
# that includes an existing expiry date). See e.g.:
|
109
108
|
#
|
110
|
-
# * #
|
109
|
+
# * #save_to_store
|
111
110
|
#
|
112
111
|
# The value is a Time instance in UTC. If +nil+, the session has not
|
113
112
|
# yet been saved.
|
@@ -138,9 +137,7 @@ module Hoodoo
|
|
138
137
|
#
|
139
138
|
# +caller_version+:: Version of the Caller instance; defaults to zero.
|
140
139
|
#
|
141
|
-
# +memcached_host+:: Host for Memcached connections
|
142
|
-
# want to use the #load_from_memcached! or
|
143
|
-
# #save_to_memcached methods.
|
140
|
+
# +memcached_host+:: Host for Memcached connections.
|
144
141
|
#
|
145
142
|
def initialize( options = {} )
|
146
143
|
@created_at = Time.now.utc
|
@@ -151,62 +148,95 @@ module Hoodoo
|
|
151
148
|
self.caller_version = options[ :caller_version ] || 0
|
152
149
|
end
|
153
150
|
|
154
|
-
# Save this session to
|
155
|
-
# be loaded by #
|
151
|
+
# Save this session to the transient store, in a manner that will allow
|
152
|
+
# it to be loaded by #load_from_store! later.
|
156
153
|
#
|
157
|
-
# A session can only be saved if it has a Caller ID - see #caller_id=
|
158
|
-
#
|
154
|
+
# A session can only be saved if it has a Caller ID - see #caller_id= or
|
155
|
+
# the options hash passed to the constructor.
|
159
156
|
#
|
160
|
-
# The Hoodoo::Services::Session::TTL constant determines
|
161
|
-
#
|
157
|
+
# The Hoodoo::Services::Session::TTL constant determines the maximum
|
158
|
+
# length of time for which the data persists inside the transient store.
|
162
159
|
#
|
163
160
|
# Returns a symbol:
|
164
161
|
#
|
165
162
|
# * +:ok+: The session data was saved OK and is valid. There was either
|
166
|
-
# a Caller record with an earlier or matching value in
|
167
|
-
# no preexisting record of the Caller.
|
163
|
+
# a Caller record with an earlier or matching value in the transient
|
164
|
+
# store, no preexisting record of the Caller.
|
168
165
|
#
|
169
166
|
# * +:outdated+: The session data could not be saved because an existing
|
170
|
-
# Caller record was found in
|
171
|
-
# 'this' session, implying that the session is already outdated.
|
167
|
+
# Caller record was found in the transient store with a _newer_ version
|
168
|
+
# than 'this' session, implying that the session is already outdated.
|
172
169
|
#
|
173
|
-
# * +:fail+: The session data could not be saved
|
170
|
+
# * +:fail+: The session data could not be saved.
|
174
171
|
#
|
175
|
-
def
|
172
|
+
def save_to_store
|
176
173
|
if self.caller_id.nil?
|
177
|
-
raise 'Hoodoo::Services::Session\#
|
174
|
+
raise 'Hoodoo::Services::Session\#save_to_store: Cannot save this session as it has no assigned Caller UUID'
|
178
175
|
end
|
179
176
|
|
180
177
|
begin
|
181
|
-
|
178
|
+
store = get_store()
|
182
179
|
|
183
|
-
# Try to update the Caller version in
|
180
|
+
# Try to update the Caller version in the store using this
|
184
181
|
# Session's data. If this fails, the Caller version is out of
|
185
|
-
# date or we couldn't talk to
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
182
|
+
# date or we couldn't talk to the store. Either way, bail out.
|
183
|
+
#
|
184
|
+
# TL;DR: The 'update' call here is critical.
|
185
|
+
#
|
186
|
+
# This process refreshes the caller version information in the
|
187
|
+
# transient store back-end with each new Session. If eventually the
|
188
|
+
# Caller version is expired or evicted, Sessions would be immediately
|
189
|
+
# invalidated and a recreation would result in the Caller version
|
190
|
+
# being rewritten.
|
191
|
+
#
|
192
|
+
# What if the Caller goes out of date? An external service must gate
|
193
|
+
# access to Caller resource changes and update the Caller version
|
194
|
+
# itself if the Caller alters in a way that should invalidate
|
195
|
+
# Sessions. This refreshes the lifetime on that item which normally
|
196
|
+
# expires at a much greater TTL than sessions anyway and, if anyone
|
197
|
+
# tries to use a Stale session after, the Caller version mismatch
|
198
|
+
# will invalidate it so they'll need a new one.
|
199
|
+
#
|
200
|
+
# If a Caller version is created but somehow evicted before any of
|
201
|
+
# the older existing Sessions (perhaps because Caller version data is
|
202
|
+
# small but Session data is large) then attempts to read the Session
|
203
|
+
# will fail; *loading* a Session requires the Caller version. The
|
204
|
+
# Caller would have to create a new Session and this would by virtue
|
205
|
+
# of the handling resource endpoint's service code acquire the new
|
206
|
+
# Caller version data immediately then cause it to be re-asserted /
|
207
|
+
# re-written by the code below.
|
208
|
+
#
|
209
|
+
result = update_caller_version_in_store( self.caller_id,
|
210
|
+
self.caller_version,
|
211
|
+
store )
|
190
212
|
|
191
213
|
return result unless result.equal?( :ok )
|
192
214
|
|
193
215
|
# Must set this before saving, even though the delay between
|
194
|
-
# setting this value and
|
195
|
-
# with a TTL will mean that
|
216
|
+
# setting this value and the store actually saving the value
|
217
|
+
# with a TTL will mean that the store expires the key slightly
|
196
218
|
# *after* the time we record.
|
197
219
|
|
198
220
|
@expires_at = ( ::Time.now + TTL ).utc()
|
221
|
+
result = store.set( key: self.session_id,
|
222
|
+
payload: self.to_h(),
|
223
|
+
maximum_lifespan: TTL )
|
199
224
|
|
200
|
-
|
201
|
-
|
202
|
-
|
225
|
+
case result
|
226
|
+
when true
|
227
|
+
return :ok
|
228
|
+
when false
|
229
|
+
raise 'Unknown storage engine failure'
|
230
|
+
else
|
231
|
+
raise result
|
232
|
+
end
|
203
233
|
|
204
234
|
rescue => exception
|
205
235
|
|
206
236
|
# Log error and return nil if the session can't be parsed
|
207
237
|
#
|
208
238
|
Hoodoo::Services::Middleware.logger.warn(
|
209
|
-
'Hoodoo::Services::Session\#
|
239
|
+
'Hoodoo::Services::Session\#save_to_store: Session saving failed - connection fault or session corrupt',
|
210
240
|
exception.to_s
|
211
241
|
)
|
212
242
|
|
@@ -215,10 +245,14 @@ module Hoodoo
|
|
215
245
|
return :fail
|
216
246
|
end
|
217
247
|
|
248
|
+
# Deprecated alias for #save_to_store, dating back to when the Session
|
249
|
+
# engine was hard-coded to Memcached.
|
250
|
+
#
|
251
|
+
alias_method( :save_to_memcached, :save_to_store )
|
252
|
+
|
218
253
|
# Load session data into this instance, overwriting instance values
|
219
254
|
# if the session is found. Raises an exception if there is a problem
|
220
|
-
# connecting to
|
221
|
-
# set through the constructor or #memcached_host accessor first.
|
255
|
+
# connecting to the transient store.
|
222
256
|
#
|
223
257
|
# +sid+:: The Session UUID to look up.
|
224
258
|
#
|
@@ -228,16 +262,17 @@ module Hoodoo
|
|
228
262
|
#
|
229
263
|
# * +:outdated+: The session data was loaded, but is outdated; either
|
230
264
|
# the session has expired, or its Caller version mismatches the
|
231
|
-
# associated stored Caller version in
|
265
|
+
# associated stored Caller version in the transient store.
|
232
266
|
#
|
233
267
|
# * +:not_found+: The session was not found.
|
234
268
|
#
|
235
|
-
# * +:fail+: The session data could not be loaded (
|
269
|
+
# * +:fail+: The session data could not be loaded (unexpected storage
|
270
|
+
# engine failure).
|
236
271
|
#
|
237
|
-
def
|
272
|
+
def load_from_store!( sid )
|
238
273
|
begin
|
239
|
-
|
240
|
-
session_hash =
|
274
|
+
store = get_store()
|
275
|
+
session_hash = store.get( key: sid, allow_throw: true )
|
241
276
|
|
242
277
|
if session_hash.nil?
|
243
278
|
return :not_found
|
@@ -245,7 +280,7 @@ module Hoodoo
|
|
245
280
|
self.from_h!( session_hash )
|
246
281
|
return :outdated if self.expired?
|
247
282
|
|
248
|
-
cv =
|
283
|
+
cv = load_caller_version_from_store( store, self.caller_id )
|
249
284
|
|
250
285
|
if cv == nil || cv > self.caller_version
|
251
286
|
return :outdated
|
@@ -259,7 +294,7 @@ module Hoodoo
|
|
259
294
|
# Log error and return nil if the session can't be parsed
|
260
295
|
#
|
261
296
|
Hoodoo::Services::Middleware.logger.warn(
|
262
|
-
'Hoodoo::Services::Session\#
|
297
|
+
'Hoodoo::Services::Session\#load_from_store!: Session loading failed - connection fault or session corrupt',
|
263
298
|
exception.to_s
|
264
299
|
)
|
265
300
|
|
@@ -268,45 +303,50 @@ module Hoodoo
|
|
268
303
|
return :fail
|
269
304
|
end
|
270
305
|
|
271
|
-
#
|
272
|
-
#
|
273
|
-
# code alters any Callers independently, it *MUST* call here to keep
|
274
|
-
# Memcached records up to date.
|
306
|
+
# Deprecated alias for #load_from_store!, dating back to when the Session
|
307
|
+
# engine was hard-coded to Memcached.
|
275
308
|
#
|
276
|
-
|
277
|
-
|
278
|
-
#
|
309
|
+
alias_method( :load_from_memcached!, :load_from_store! )
|
310
|
+
|
311
|
+
# Update the version of a given Caller in the transient store. This is
|
312
|
+
# done automatically when Sessions are saved to that store, but if
|
313
|
+
# external code alters any Callers independently, it *MUST* call here to
|
314
|
+
# keep stored records up to date.
|
315
|
+
#
|
316
|
+
# If no cached version is in the transient store for the Caller, the
|
317
|
+
# method assumes it is being called for the first time for that Caller
|
318
|
+
# and writes the version it has to hand, rather than considering it an
|
279
319
|
# error condition.
|
280
320
|
#
|
281
|
-
# +cid+::
|
321
|
+
# +cid+:: Caller UUID of the Caller record to update.
|
282
322
|
#
|
283
|
-
# +cv+::
|
323
|
+
# +cv+:: New version to store (an Integer).
|
284
324
|
#
|
285
|
-
# +
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
325
|
+
# +store+:: Optional Hoodoo::TransientStore instance to use for data
|
326
|
+
# storage. If omitted, a connection is established for
|
327
|
+
# you. This is mostly an optimisation parameter, used by
|
328
|
+
# code which already has established a connection and
|
329
|
+
# wants to avoid creating another unnecessarily.
|
290
330
|
#
|
291
331
|
# Returns a Symbol:
|
292
332
|
#
|
293
333
|
# * +:ok+: The Caller record was updated successfully.
|
294
334
|
#
|
295
|
-
# * +:outdated+: The Caller was already present in
|
296
|
-
# _higher version_ than the one you wanted to save. Your own
|
297
|
-
# Caller data must therefore already be out of date.
|
335
|
+
# * +:outdated+: The Caller was already present in the transient store
|
336
|
+
# with a _higher version_ than the one you wanted to save. Your own
|
337
|
+
# local Caller data must therefore already be out of date.
|
298
338
|
#
|
299
|
-
# * +:fail+: The Caller could not be updated (
|
339
|
+
# * +:fail+: The Caller could not be updated (unexpected storage engine
|
340
|
+
# failure).
|
300
341
|
#
|
301
|
-
def
|
342
|
+
def update_caller_version_in_store( cid, cv, store = nil )
|
302
343
|
begin
|
303
|
-
|
304
|
-
|
305
|
-
cached_version = load_caller_version_from_memcached( mclient, cid )
|
344
|
+
store ||= get_store()
|
345
|
+
cached_version = load_caller_version_from_store( store, cid )
|
306
346
|
|
307
347
|
if cached_version != nil && cached_version > cv
|
308
348
|
return :outdated
|
309
|
-
elsif
|
349
|
+
elsif save_caller_version_to_store( store, cid, cv ) == true
|
310
350
|
return :ok
|
311
351
|
end
|
312
352
|
|
@@ -315,7 +355,7 @@ module Hoodoo
|
|
315
355
|
# Log error and return nil if the session can't be parsed
|
316
356
|
#
|
317
357
|
Hoodoo::Services::Middleware.logger.warn(
|
318
|
-
'Hoodoo::Services::Session\#
|
358
|
+
'Hoodoo::Services::Session\#update_caller_version_in_store: Client version update - connection fault or corrupt record',
|
319
359
|
exception.to_s
|
320
360
|
)
|
321
361
|
|
@@ -324,26 +364,68 @@ module Hoodoo
|
|
324
364
|
return :fail
|
325
365
|
end
|
326
366
|
|
327
|
-
#
|
367
|
+
# Deprecated interface (use #update_caller_version_in_store instead),
|
368
|
+
# dating back to when the Session engine was hard-coded to Memcached.
|
369
|
+
#
|
370
|
+
# Parameters as for #update_caller_version_in_store, except +store+ is
|
371
|
+
# must be a fully configured Dalli::Client instance. Use of this
|
372
|
+
# interface is inefficient and discouraged; it will result in logged
|
373
|
+
# warnings.
|
374
|
+
#
|
375
|
+
def update_caller_version_in_memcached( cid, cv, store = nil )
|
376
|
+
unless store.nil?
|
377
|
+
Hoodoo::Services::Middleware.logger.warn(
|
378
|
+
'Hoodoo::Services::Session#update_caller_version_in_memcached is deprecated - use #update_caller_version_in_store'
|
379
|
+
)
|
380
|
+
|
381
|
+
# Inefficient - create a TransientStore configured for the normal
|
382
|
+
# Memcached connection data, but get hold of its storage engine and
|
383
|
+
# change that engine's client to the provided Dalli::Client instance.
|
384
|
+
|
385
|
+
temp_store = Hoodoo::TransientStore.new(
|
386
|
+
storage_engine: :memcached,
|
387
|
+
storage_host_uri: self.memcached_host(),
|
388
|
+
default_namespace: 'nz_co_loyalty_hoodoo_session_'
|
389
|
+
)
|
390
|
+
|
391
|
+
memcached_engine = temp_store.storage_engine_instance()
|
392
|
+
memcached_engine.client = store
|
393
|
+
|
394
|
+
begin
|
395
|
+
update_caller_version_in_store( cid, cv, temp_store )
|
396
|
+
ensure
|
397
|
+
temp_store.close()
|
398
|
+
end
|
399
|
+
|
400
|
+
else
|
401
|
+
update_caller_version_in_store( cid, cv )
|
402
|
+
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
# Delete this session from the transient store. The Session object is not
|
328
407
|
# modified.
|
329
408
|
#
|
330
409
|
# Returns a symbol:
|
331
410
|
#
|
332
|
-
# * +:ok+: The Session was deleted from
|
411
|
+
# * +:ok+: The Session was deleted from the transient store successfully.
|
333
412
|
#
|
334
|
-
# * +:
|
413
|
+
# * +:fail+: The session data could not be deleted (unexpected storage
|
414
|
+
# engine failure).
|
335
415
|
#
|
336
|
-
|
337
|
-
#
|
338
|
-
def delete_from_memcached
|
416
|
+
def delete_from_store
|
339
417
|
begin
|
340
418
|
|
341
|
-
|
419
|
+
store = get_store()
|
420
|
+
result = store.delete( key: self.session_id )
|
342
421
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
422
|
+
case result
|
423
|
+
when true
|
424
|
+
return :ok
|
425
|
+
when false
|
426
|
+
raise 'Unknown storage engine failure'
|
427
|
+
else
|
428
|
+
raise result
|
347
429
|
end
|
348
430
|
|
349
431
|
rescue => exception
|
@@ -351,7 +433,7 @@ module Hoodoo
|
|
351
433
|
# Log error and return nil if the session can't be parsed
|
352
434
|
#
|
353
435
|
Hoodoo::Services::Middleware.logger.warn(
|
354
|
-
'Hoodoo::Services::Session\#
|
436
|
+
'Hoodoo::Services::Session\#delete_from_store: Session delete - connection fault',
|
355
437
|
exception.to_s
|
356
438
|
)
|
357
439
|
|
@@ -360,6 +442,11 @@ module Hoodoo
|
|
360
442
|
|
361
443
|
end
|
362
444
|
|
445
|
+
# Deprecated alias for #delete_from_store, dating back to when the
|
446
|
+
# Session engine was hard-coded to Memcached.
|
447
|
+
#
|
448
|
+
alias_method( :delete_from_memcached, :delete_from_store )
|
449
|
+
|
363
450
|
# Has this session expired? Only valid if an expiry date is set;
|
364
451
|
# see #expires_at.
|
365
452
|
#
|
@@ -373,9 +460,8 @@ module Hoodoo
|
|
373
460
|
return ! ( exp.nil? || now < exp )
|
374
461
|
end
|
375
462
|
|
376
|
-
# Represent this session's data as a Hash, for uses such as
|
377
|
-
#
|
378
|
-
# See also #from_h!.
|
463
|
+
# Represent this session's data as a Hash, for uses such as persistence
|
464
|
+
# or loading into another session instance. See also #from_h!.
|
379
465
|
#
|
380
466
|
def to_h
|
381
467
|
hash = {}
|
@@ -493,7 +579,7 @@ module Hoodoo
|
|
493
579
|
# * +false+ if the session can't be saved due to a mismatched caller
|
494
580
|
# version - the session must have become invalid _during_ handling.
|
495
581
|
#
|
496
|
-
# If the augmented session cannot be saved due to a
|
582
|
+
# If the augmented session cannot be saved due to a storage problem,
|
497
583
|
# an exception is raised and the generic handler will turn this into a
|
498
584
|
# 500 response for the caller. At this time, we really can't do much
|
499
585
|
# better than that since failure to save the augmented session means
|
@@ -528,7 +614,7 @@ module Hoodoo
|
|
528
614
|
local_session.session_id = Hoodoo::UUID.generate()
|
529
615
|
local_session.permissions = local_permissions
|
530
616
|
|
531
|
-
case local_session.
|
617
|
+
case local_session.save_to_store()
|
532
618
|
when :ok
|
533
619
|
return local_session
|
534
620
|
|
@@ -543,96 +629,71 @@ module Hoodoo
|
|
543
629
|
|
544
630
|
private
|
545
631
|
|
546
|
-
# Connect to the
|
632
|
+
# Connect to the storage engine. Returns a Hoodoo:TransientStore
|
547
633
|
# instance. Raises an exception if no connection can be established.
|
548
634
|
#
|
549
|
-
|
550
|
-
|
551
|
-
# +host+:: Connection host (IP "address:port" String) for Memcached.
|
552
|
-
#
|
553
|
-
def self.connect_to_memcached( host )
|
554
|
-
|
555
|
-
if Hoodoo::Services::Middleware.environment.test? && MockDalliClient.bypass? == false
|
556
|
-
return MockDalliClient.new
|
557
|
-
end
|
558
|
-
|
559
|
-
if host.nil? || host.empty?
|
560
|
-
raise 'Hoodoo::Services::Session.connect_to_memcached: The Memcached connection host data is nil or empty'
|
561
|
-
end
|
562
|
-
|
563
|
-
exception = nil
|
564
|
-
stats = nil
|
565
|
-
mclient = nil
|
635
|
+
def get_store
|
636
|
+
host = self.memcached_host()
|
566
637
|
|
567
638
|
begin
|
568
|
-
@@
|
569
|
-
@@
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
:serializer => JSON,
|
574
|
-
:namespace => :nz_co_loyalty_hoodoo_session_
|
575
|
-
}
|
639
|
+
@@stores ||= {}
|
640
|
+
@@stores[ host ] ||= Hoodoo::TransientStore.new(
|
641
|
+
storage_engine: :memcached,
|
642
|
+
storage_host_uri: host,
|
643
|
+
default_namespace: 'nz_co_loyalty_hoodoo_session_'
|
576
644
|
)
|
577
645
|
|
578
|
-
|
646
|
+
raise 'Unknown storage engine failure' if @@stores[ host ].nil?
|
579
647
|
|
580
|
-
rescue =>
|
581
|
-
exception
|
648
|
+
rescue => exception
|
649
|
+
raise "Hoodoo::Services::Session\#get_store: Cannot connect to Memcached at '#{ host }': #{ exception.to_s }"
|
582
650
|
|
583
651
|
end
|
584
652
|
|
585
|
-
|
586
|
-
if exception.nil?
|
587
|
-
raise "Hoodoo::Services::Session.connect_to_memcached: Did not get back meaningful data from Memcached at '#{ host }'"
|
588
|
-
else
|
589
|
-
raise "Hoodoo::Services::Session.connect_to_memcached: Cannot connect to Memcached at '#{ host }': #{ exception.to_s }"
|
590
|
-
end
|
591
|
-
else
|
592
|
-
return @@dalli_clients[ host ]
|
593
|
-
end
|
653
|
+
@@stores[ host ]
|
594
654
|
end
|
595
655
|
|
596
|
-
# Try to read a cached Caller version from
|
597
|
-
# cached version if available, or +nil+ if the record isn't found.
|
656
|
+
# Try to read a cached Caller version from the transient store. Returns
|
657
|
+
# the cached version if available, or +nil+ if the record isn't found.
|
598
658
|
#
|
599
|
-
# May raise an exception for e.g.
|
659
|
+
# May raise an exception for e.g. unexpected storage engine failures.
|
600
660
|
#
|
601
661
|
# TODO: As a temporary measure, compatibility bridge code in Authsome
|
602
662
|
# may call this private interface via ".send". Until that is
|
603
663
|
# decommissioned, the API shouldn't be changed without updating
|
604
664
|
# Authsome too.
|
605
665
|
#
|
606
|
-
# +
|
607
|
-
#
|
608
|
-
#
|
609
|
-
# +cid+:: Caller UUID of interest.
|
666
|
+
# +store+:: A Hoodoo::TransientStore instance to use for storage.
|
667
|
+
# +cid+:: Caller UUID of interest.
|
610
668
|
#
|
611
|
-
def
|
612
|
-
version_hash =
|
669
|
+
def load_caller_version_from_store( store, cid )
|
670
|
+
version_hash = store.get( key: cid, allow_throw: true )
|
613
671
|
return version_hash.nil? ? nil : version_hash[ 'version' ]
|
614
672
|
end
|
615
673
|
|
616
|
-
# Save the Caller version for a given Caller ID to
|
674
|
+
# Save the Caller version for a given Caller ID to the transient store.
|
617
675
|
# Returns +true+ if successful, else +false+.
|
618
676
|
#
|
619
|
-
# May raise an exception for e.g.
|
677
|
+
# May raise an exception for e.g. unexpected storage engine failures.
|
620
678
|
#
|
621
679
|
# Note that any existing record for the given Caller, if there
|
622
680
|
# is one, is unconditionally overwritten.
|
623
681
|
#
|
624
|
-
# +
|
625
|
-
#
|
626
|
-
#
|
627
|
-
# +cid+:: Caller UUID of interest.
|
628
|
-
#
|
629
|
-
# +cv+:: Version to save for that Caller UUID.
|
682
|
+
# +store+:: A Hoodoo::TransientStore instance to use for storage.
|
683
|
+
# +cid+:: Caller UUID of interest.
|
684
|
+
# +cv+:: Version to save for that Caller UUID.
|
630
685
|
#
|
631
|
-
def
|
632
|
-
|
633
|
-
cid,
|
634
|
-
{ 'version' => cv }
|
686
|
+
def save_caller_version_to_store( store, cid, cv )
|
687
|
+
result = store.set(
|
688
|
+
key: cid,
|
689
|
+
payload: { 'version' => cv }
|
635
690
|
)
|
691
|
+
|
692
|
+
if result.is_a?( Exception )
|
693
|
+
raise result
|
694
|
+
else
|
695
|
+
return result
|
696
|
+
end
|
636
697
|
end
|
637
698
|
|
638
699
|
# Before Hoodoo::TransientStore was created, the Session system was
|