Class: Flo::CredStore::PwProtectedStore

Inherits:
Object
  • Object
show all
Defined in:
lib/flo/cred_store/pw_protected_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ PwProtectedStore

Returns a new instance of PwProtectedStore.



12
13
14
15
# File 'lib/flo/cred_store/pw_protected_store.rb', line 12

def initialize(opts={})
  @password = opts[:password] # If nil, should prompt interactively
  @cred_file_location = opts[:cred_file_location]
end

Instance Attribute Details

#cred_fileObject



33
34
35
# File 'lib/flo/cred_store/pw_protected_store.rb', line 33

def cred_file
  @cred_file ||= File.new(@cred_file_location || File.join(Dir.home, '.flo_creds.yml.gpg'))
end

Instance Method Details

#credentials_for(provider_sym) ⇒ Flo::CredStore::Creds

Decrypts the credentials file and returns the credentials for the requested provider

Parameters:

  • provider_sym (Symbol)

Returns:



21
22
23
# File 'lib/flo/cred_store/pw_protected_store.rb', line 21

def credentials_for(provider_sym)
  Flo::CredStore::Creds.new(full_credentials_hash[provider_sym])
end

#encrypt_file(file_location) ⇒ String

Convenience method for producing an encrypted version of a file. This only returns the encrypted version as a string, you will have to save it yourself if desired

Parameters:

  • file_location (String)

Returns:

  • (String)


29
30
31
# File 'lib/flo/cred_store/pw_protected_store.rb', line 29

def encrypt_file(file_location)
  crypto.encrypt(File.open(file_location)).to_s
end

#inspectObject

Remove password from inspect output



38
39
40
# File 'lib/flo/cred_store/pw_protected_store.rb', line 38

def inspect
  "#<Flo::CredStore::PwProtectedStore:#{object_id} @cred_file=#{cred_file.inspect}>"
end