class Ingenico::Connect::SDK::Webhooks::InMemorySecretKeyStore
An in-memory secret key store. This implementation can be used in applications where secret keys are specified at application startup. Thread-safe.
Public Class Methods
Creates new InMemorySecretKeyStore
# File lib/ingenico/connect/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
Public Instance Methods
Removes all stored secret keys from the store
# File lib/ingenico/connect/sdk/webhooks/in_memory_secret_key_store.rb, line 51 def clear @store.clear end
Retrieves the secret key corresponding to the given key id
@param key_id [String] key id of the secret key @raise [Ingenico::Connect::SDK::Webhooks::SecretKeyNotAvailableException] if the secret key for the given key id is not available.
# File lib/ingenico/connect/sdk/webhooks/in_memory_secret_key_store.rb, line 25 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
Removes the secret key for the given key id.
@param key_id [String] the key id whose corresponding secret should be removed from the store
# File lib/ingenico/connect/sdk/webhooks/in_memory_secret_key_store.rb, line 46 def remove_secret_key(key_id) @store.delete(key_id) end
Stores the given secret key for the given key id.
@param key_id [String] key id of the secret key @param secret_key [String] the secret key to be stored
# File lib/ingenico/connect/sdk/webhooks/in_memory_secret_key_store.rb, line 37 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