class Ingenico::Direct::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

new() click to toggle source

Creates new InMemorySecretKeyStore

# 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

Public Instance Methods

clear() click to toggle source

Removes all stored secret keys from the store

# File lib/ingenico/direct/sdk/webhooks/in_memory_secret_key_store.rb, line 51
def clear
  @store.clear
end
get_secret_key(key_id) click to toggle source

Retrieves the secret key corresponding to the given key id

@param key_id [String] key id of the secret key @raise [Ingenico::Direct::SDK::Webhooks::SecretKeyNotAvailableException] if the secret key for the given key id is not available.

# 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) click to toggle source

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/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) click to toggle source

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/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