Class: Veil::CredentialCollection::ChefSecretsEnv

Inherits:
Base
  • Object
show all
Defined in:
lib/veil/credential_collection/chef_secrets_env.rb

Instance Attribute Summary

Attributes inherited from Base

#credentials, #decryptor, #encryptor, #hasher, #version

Instance Method Summary collapse

Methods inherited from Base

#add, #add_from_file, create, #credentials_as_hash, #credentials_for_export, #exist?, #get, #remove, #rotate_hasher, #to_hash

Constructor Details

#initialize(opts = {}) ⇒ ChefSecretsEnv

Create a new ChefSecretsEnv

Parameters:

  • opts (Hash) (defaults to: {}) —

    a hash of options to pass to the constructor



12
13
14
15
16
17
# File 'lib/veil/credential_collection/chef_secrets_env.rb', line 12

def initialize(opts = {})
  var_name = opts[:var_name] || 'CHEF_SECRETS_DATA'

  @credentials = {}
  import_credentials_hash(inflate_secrets_from_environment(var_name))
end

Instance Method Details

#inflate_secrets_from_environment(var_name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/veil/credential_collection/chef_secrets_env.rb', line 26

def inflate_secrets_from_environment(var_name)
  value = ENV[var_name]
  unless value
    msg = "Env var #{var_name} has not been set. This should by done by "\
      "launching this application via veil-env-wrapper."
    raise InvalidCredentialCollectionEnv.new(msg)
  end

  begin
    JSON.parse(value)
  rescue JSON::ParserError => e
    msg = "Env var #{var_name} could not be parsed: #{e.message}"
    raise InvalidCredentialCollectionEnv.new(msg)
  end
end

#rotate ⇒ Object Also known as: rotate_credentials, save

Unsupported methods

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/veil/credential_collection/chef_secrets_env.rb', line 20

def rotate
  raise NotImplementedError
end