class Flo::CredStore::PwProtectedStore
Attributes
cred_file[W]
password[R]
Public Class Methods
new(opts={})
click to toggle source
# 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
Public Instance Methods
cred_file()
click to toggle source
# 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
credentials_for(provider_sym)
click to toggle source
Decrypts the credentials file and returns the credentials for the requested provider @param provider_sym [Symbol] @return [Flo::CredStore::Creds]
# 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)
click to toggle source
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 @param file_location [String] @return [String]
# 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
inspect()
click to toggle source
Remove password from inspect output
# File lib/flo/cred_store/pw_protected_store.rb, line 38 def inspect "#<Flo::CredStore::PwProtectedStore:#{object_id} @cred_file=#{cred_file.inspect}>" end
Private Instance Methods
crypto()
click to toggle source
# File lib/flo/cred_store/pw_protected_store.rb, line 54 def crypto GPGME::Crypto.new(password: @password, symmetric: true) end
decrypted_file()
click to toggle source
# File lib/flo/cred_store/pw_protected_store.rb, line 46 def decrypted_file crypto.decrypt(cred_file) end
full_credentials_hash()
click to toggle source
# File lib/flo/cred_store/pw_protected_store.rb, line 50 def full_credentials_hash @full_credentials_hash ||= YAML.load(decrypted_file.read) || {} end