Class: DnsMadeEasy::Credentials::YamlFile

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsmadeeasy/credentials/yaml_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file: default_credentials_path) ⇒ YamlFile

Returns a new instance of YamlFile.



14
15
16
17
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 14

def initialize(file: default_credentials_path)
  self.filename = file
  parse! if exist?
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



12
13
14
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 12

def 
  @account
end

#filenameObject

Returns the value of attribute filename.



12
13
14
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 12

def filename
  @filename
end

#mashObject

Returns the value of attribute mash.



12
13
14
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 12

def mash
  @mash
end

Instance Method Details

#keys(account: nil, encryption_key: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 19

def keys(account: nil, encryption_key: nil)
  return nil unless exist?
  return nil if mash.nil?

  creds = if mash.accounts.is_a?(Array)
            credentials_from_array(mash.accounts, &.to_s)

          elsif mash.credentials
            mash.credentials

          else
            raise DnsMadeEasy::InvalidCredentialsFormatError,
                  'expected either "accounts" or "credentials" as the top-level key'
          end

  return nil unless creds

  ApiKeys.new creds.api_key,
              creds.api_secret,
              encryption_key || creds.encryption_key
end

#to_sObject



41
42
43
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 41

def to_s
  "file #{filename}"
end