Class: Worldline::Connect::SDK::Webhooks::InMemorySecretKeyStore
- Inherits:
-
Object
- Object
- Worldline::Connect::SDK::Webhooks::InMemorySecretKeyStore
- Includes:
- Singleton, SecretKeyStore
- Defined in:
- lib/worldline/connect/sdk/webhooks/in_memory_secret_key_store.rb
Overview
An in-memory secret key store. This implementation can be used in applications where secret keys are specified at application startup. Thread-safe.
Instance Method Summary collapse
-
#clear ⇒ Object
Removes all stored secret keys from the store.
-
#get_secret_key(key_id) ⇒ Object
Retrieves the secret key corresponding to the given key id.
-
#initialize ⇒ InMemorySecretKeyStore
constructor
Creates new InMemorySecretKeyStore.
-
#remove_secret_key(key_id) ⇒ Object
Removes the secret key for the given key id.
-
#store_secret_key(key_id, secret_key) ⇒ Object
Stores the given secret key for the given key id.
Constructor Details
#initialize ⇒ InMemorySecretKeyStore
Creates new InMemorySecretKeyStore
18 19 20 21 22 |
# File 'lib/worldline/connect/sdk/webhooks/in_memory_secret_key_store.rb', line 18 def initialize # NOTE: use Map instead of Hash to provide better performance # under high concurrency. @store = Concurrent::Map.new end |
Instance Method Details
#clear ⇒ Object
Removes all stored secret keys from the store
54 55 56 |
# File 'lib/worldline/connect/sdk/webhooks/in_memory_secret_key_store.rb', line 54 def clear @store.clear end |
#get_secret_key(key_id) ⇒ Object
Retrieves the secret key corresponding to the given key id
28 29 30 31 32 33 34 |
# File 'lib/worldline/connect/sdk/webhooks/in_memory_secret_key_store.rb', line 28 def get_secret_key(key_id) if (secret_key = @store.get(key_id)).nil? msg = "could not find secret key for key id " + key_id raise SecretKeyNotAvailableException.new(message: msg, key_id: key_id) end secret_key end |
#remove_secret_key(key_id) ⇒ Object
Removes the secret key for the given key id.
49 50 51 |
# File 'lib/worldline/connect/sdk/webhooks/in_memory_secret_key_store.rb', line 49 def remove_secret_key(key_id) @store.delete(key_id) end |
#store_secret_key(key_id, secret_key) ⇒ Object
Stores the given secret key for the given key id.
40 41 42 43 44 |
# File 'lib/worldline/connect/sdk/webhooks/in_memory_secret_key_store.rb', line 40 def store_secret_key(key_id, secret_key) raise ArgumentError if key_id.nil? or key_id.strip.empty? raise ArgumentError if secret_key.nil? or secret_key.strip.empty? @store.put(key_id, secret_key) end |