Class: DnsMadeEasy::Credentials::YamlFile
- Inherits:
-
Object
- Object
- DnsMadeEasy::Credentials::YamlFile
- Defined in:
- lib/dnsmadeeasy/credentials/yaml_file.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#mash ⇒ Object
Returns the value of attribute mash.
Instance Method Summary collapse
-
#initialize(file: default_credentials_path) ⇒ YamlFile
constructor
A new instance of YamlFile.
- #keys(account: nil, encryption_key: nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(file: default_credentials_path) ⇒ YamlFile
Returns a new instance of YamlFile.
13 14 15 16 |
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 13 def initialize(file: default_credentials_path) self.filename = file parse! if exist? end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
11 12 13 |
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 11 def account @account end |
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 11 def filename @filename end |
#mash ⇒ Object
Returns the value of attribute mash.
11 12 13 |
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 11 def mash @mash end |
Instance Method Details
#keys(account: nil, encryption_key: nil) ⇒ Object
18 19 20 21 22 23 24 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 |
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 18 def keys(account: nil, encryption_key: nil) return nil unless exist? return nil if mash.nil? creds = if mash.accounts.is_a?(Array) account = if account mash.accounts.find { |a| a.name == account.to_s } elsif mash.accounts.size == 1 mash.accounts.first else mash.accounts.find { |a| a.default_account } end raise DnsMadeEasy::APIKeyAndSecretMissingError, (account ? "account #{account} was not found" : 'default account does not exist') unless account raise DnsMadeEasy::InvalidCredentialsFormatError, 'Expected account entry to have "credentials" key' unless account.credentials account.credentials elsif mash.credentials mash.credentials else raise DnsMadeEasy::InvalidCredentialsFormatError, 'expected either "accounts" or "credentials" as the top-level key' end creds ? ApiKeys.new(creds.api_key, creds.api_secret, encryption_key || creds.encryption_key) : nil end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 53 def to_s "file #{filename}" end |