Class: Veil::CredentialCollection::ChefSecretsFd

Inherits:
Base
  • Object
show all
Defined in:
lib/veil/credential_collection/chef_secrets_fd.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 = {}) ⇒ ChefSecretsFd

Create a new ChefSecretsFd

Parameters:

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

    ignored



13
14
15
16
# File 'lib/veil/credential_collection/chef_secrets_fd.rb', line 13

def initialize(opts = {})
  @credentials = {}
  import_credentials_hash(inflate_secrets_from_fd)
end

Instance Method Details

#inflate_secrets_from_fdObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/veil/credential_collection/chef_secrets_fd.rb', line 25

def inflate_secrets_from_fd
  if ENV['CHEF_SECRETS_FD'].nil?
    raise InvalidCredentialCollectionFd.new("CHEF_SECRETS_FD not found in environment")
  end

  fd = ENV['CHEF_SECRETS_FD'].to_i
  value = nil

  begin
    file = IO.new(fd, "r")
    value = file.gets
  rescue StandardError => e
    msg = "A problem occured trying to read passed file descriptor: #{e}"
    raise InvalidCredentialCollectionFd.new(msg)
  ensure
    file.close if file
  end

  if !value
    msg = "File at CHEF_SECRETS_FD (#{fd}) did not contain any data!"
    raise InvalidCredentialCollectionFd.new(msg)
  end

  begin
    JSON.parse(value)
  rescue JSON::ParserError => e
    msg = "Chef secrets data could not be parsed: #{e.message}"
    raise InvalidCredentialCollectionFd.new(msg)
  end
end

#rotateObject Also known as: rotate_credentials, save

Unsupported methods

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/veil/credential_collection/chef_secrets_fd.rb', line 19

def rotate
  raise NotImplementedError
end