Class: Ingenico::Direct::SDK::Webhooks::InMemorySecretKeyStore
- Inherits:
-
Object
- Object
- Ingenico::Direct::SDK::Webhooks::InMemorySecretKeyStore
- Includes:
- SecretKeyStore, Singleton
- Defined in:
- lib/ingenico/direct/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
15 16 17 18 19 |
# File 'lib/ingenico/direct/sdk/webhooks/in_memory_secret_key_store.rb', line 15 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
51 52 53 |
# File 'lib/ingenico/direct/sdk/webhooks/in_memory_secret_key_store.rb', line 51 def clear @store.clear end |
#get_secret_key(key_id) ⇒ Object
Retrieves the secret key corresponding to the given key id
25 26 27 28 29 30 31 |
# File 'lib/ingenico/direct/sdk/webhooks/in_memory_secret_key_store.rb', line 25 def get_secret_key(key_id) if (secret_key = @store.get(key_id)) return secret_key end msg = "could not find secret key for key id #{key_id}" raise SecretKeyNotAvailableException, message: msg, key_id: key_id end |
#remove_secret_key(key_id) ⇒ Object
Removes the secret key for the given key id.
46 47 48 |
# File 'lib/ingenico/direct/sdk/webhooks/in_memory_secret_key_store.rb', line 46 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.
37 38 39 40 41 |
# File 'lib/ingenico/direct/sdk/webhooks/in_memory_secret_key_store.rb', line 37 def store_secret_key(key_id, secret_key) raise ArgumentError if key_id.nil? || key_id.strip.empty? raise ArgumentError if secret_key.nil? || secret_key.strip.empty? @store.put(key_id, secret_key) end |