Class: OnlinePayments::SDK::Webhooks::InMemorySecretKeyStore
- Inherits:
-
Object
- Object
- OnlinePayments::SDK::Webhooks::InMemorySecretKeyStore
- Includes:
- SecretKeyStore, Singleton
- Defined in:
- lib/onlinepayments/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
17 18 19 20 21 |
# File 'lib/onlinepayments/sdk/webhooks/in_memory_secret_key_store.rb', line 17 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
53 54 55 |
# File 'lib/onlinepayments/sdk/webhooks/in_memory_secret_key_store.rb', line 53 def clear @store.clear end |
#get_secret_key(key_id) ⇒ Object
Retrieves the secret key corresponding to the given key id
27 28 29 30 31 32 33 |
# File 'lib/onlinepayments/sdk/webhooks/in_memory_secret_key_store.rb', line 27 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.
48 49 50 |
# File 'lib/onlinepayments/sdk/webhooks/in_memory_secret_key_store.rb', line 48 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.
39 40 41 42 43 |
# File 'lib/onlinepayments/sdk/webhooks/in_memory_secret_key_store.rb', line 39 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 |