Class: AwsKeychain::Keychain

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Keychain

Initializes a new keychain from the specified keychain file

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options for the class where the keys are one of :keychain_file relative or absolute path to a json file containing the keychain data :keychain_data a hash containing the keychain data where keys are the name of the credential

    and values are a hash with any keys ("key" and "secret" are required keys)
    


35
36
37
38
39
40
41
42
43
# File 'lib/keychain.rb', line 35

def initialize(options={})
  unless options.has_key?(:keychain_file) || options.has_key?(:keychain_data)
    raise ArgumentError, 'Either a keychain_file or keychain_data is required to create a new keychain class'
  end

  @keychain = options[:keychain_data] || JSON.parse(IO.read(options[:keychain_file]))

  # TODO: Validate that the hash is correct.
end

Instance Attribute Details

#keychainObject

Returns the value of attribute keychain.



27
28
29
# File 'lib/keychain.rb', line 27

def keychain
  @keychain
end

Instance Method Details

#[](key) ⇒ Hash

Array operator override to access keys by their name

Parameters:

  • key (String)

    The string name of the key to return

Returns:

  • (Hash)

    The desired hash



56
57
58
# File 'lib/keychain.rb', line 56

def [](key)
  @keychain[key]
end

#listArray

Lists the names of all keys in the keychain

Returns:

  • (Array)

    The names of all keys in the keychain



48
49
50
# File 'lib/keychain.rb', line 48

def list
  @keychain.keys
end