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.



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

#accountObject

Returns the value of attribute account.



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

def 
  @account
end

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#mashObject

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)
             = if 
                        mash.accounts.find { |a| a.name == .to_s }
                      elsif
                        mash.accounts.size == 1
                        mash.accounts.first
                      else
                        mash.accounts.find { |a| a. }
                      end

            raise DnsMadeEasy::APIKeyAndSecretMissingError,
                  ( ? "account #{} was not found" : 'default account does not exist') unless 

            raise DnsMadeEasy::InvalidCredentialsFormatError,
                  'Expected account entry to have "credentials" key' unless .credentials

            .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_sObject



53
54
55
# File 'lib/dnsmadeeasy/credentials/yaml_file.rb', line 53

def to_s
  "file #{filename}"
end