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(filename: default_credentials_path) ⇒ YamlFile
constructor
A new instance of YamlFile.
- #keys(account_name: nil, encryption_key: nil) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(filename: 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(filename: default_credentials_path) self.filename = filename 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_name: 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 |
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 18 def keys(account_name: nil, encryption_key: nil) return nil unless exist? return nil if mash.nil? creds = if mash.accounts.is_a?(Array) account = if account_name mash.accounts.find { |a| a.name == account_name.to_s } else mash.accounts.find { |a| a.default_account } end raise DnsMadeEasy::APIKeyAndSecretMissingError, (account_name ? "account #{account_name} 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
50 51 52 |
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 50 def to_s "file #{filename}" end |