Class: MinimalPipeline::Keystore

Inherits:
Object
  • Object
show all
Defined in:
lib/minimal_pipeline/keystore.rb

Overview

Here is an example of how to use this class to interact with the Keystore.

“` keystore = MinimalPipeline::Keystore.new

# Store keystore.store('EXAMPLE_KEY', 'foo')

# Retrieve content = keystore.retrieve('EXAMPLE_KEY') puts content # Outputs 'foo' “`

You will need the following environment variables to be present:

  • `AWS_REGION` or `region`

  • `keystore_table`

  • `keystore_kms_id`

For more information on the Keystore please see github.com/stelligent/keystore

Instance Method Summary collapse

Constructor Details

#initializeKeystore

Initializes a `Keystore` client Requires environment variables `AWS_REGION` or `region` to be set. Also requires `keystore_table` and `keystore_kms_id`


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/minimal_pipeline/keystore.rb', line 32

def initialize
  raise 'You must set env variable AWS_REGION or region.' \
    if ENV['AWS_REGION'].nil? && ENV['region'].nil?
  raise 'You must set env variable keystore_table.' \
    if ENV['inventory_store'].nil? && ENV['keystore_table'].nil?
  raise 'You must set env variable keystore_kms_id.' \
    if ENV['inventory_store_key'].nil? && ENV['keystore_kms_id'].nil?

  region = ENV['AWS_REGION'] || ENV['region']
  keystore_table = ENV['keystore_table'] || ENV['inventory_store']
  keystore_kms_id = ENV['keystore_kms_id'] || ENV['inventory_store_key']
  kms = Aws::KMS::Client.new(region: region)
  dynamo = Aws::DynamoDB::Client.new(region: region)
  @keystore = ::Keystore.new(dynamo: dynamo,
                             table_name: keystore_table,
                             kms: kms,
                             key_id: keystore_kms_id)
end

Instance Method Details

#retrieve(keyname) ⇒ String

Retrieves a value from the Keystore

Parameters:

  • keyname (String)

    The name of the Keystore key

Returns:

  • (String)

    The value stored in the Keystore for the given key


55
56
57
# File 'lib/minimal_pipeline/keystore.rb', line 55

def retrieve(keyname)
  @keystore.retrieve(key: keyname)
end

#store(keyname, value) ⇒ Object

Stores a value in the Keystore

Parameters:

  • keyname (String)

    The name of the Keystore key

  • value (String)

    The value to store for the given key


63
64
65
# File 'lib/minimal_pipeline/keystore.rb', line 63

def store(keyname, value)
  @keystore.store(key: keyname, value: value)
end