Module: DnsMadeEasy::Credentials

Defined in:
lib/dnsmadeeasy/credentials.rb,
lib/dnsmadeeasy/credentials/api_keys.rb,
lib/dnsmadeeasy/credentials/yaml_file.rb

Overview

A Facade module

## Usage

@creds = DnsMadeEasy::Credentials.create(key, secret)
@creds.api_key #=> ...
@creds.api_secret # > ...

### From a single-level YAML file that looks like this:

“‘yaml credentials:

api_key: 12345678-a8f8-4466-ffff-2324aaaa9098
api_secret: 43009899-abcc-ffcc-eeee-09f809808098

““

@creds = DnsMadeEasy::Credentials.keys_from_file(file: file)
@creds.api_key #=> '12345678-a8f8-4466-ffff-2324aaaa9098'

#### From a default filename ~/.dnsmadeeasy/credentials.yml

@creds = DnsMadeEasy::Credentials.keys_from_file

### From a multi-account file

Multi-account YAML file must look like this:

“‘yaml accounts:

- name: production
  default_account: true
  credentials:
    api_key: "BAhTOh1TeW06OkRhdGE6OldyYXBwZXJTdHJ1Y3QLOhNlbmNyeXB0ZWRfZGF0YSJV9HFDvF4KUwQLqevf4zvsKO1Yk04kRimAHAfNgoFO0dtRb6OjREyI43uzFV7z63FGjzXcBBG9KDUdj6OowbDw2z86nkTpakkKuIP31HCPZkQ6B2l2IhV2LPWTPSfDruDxi_ToEfbQOhBjaXBoZXJfbmFtZSIQQUVTLTI1Ni1DQkM6CXNhbHQwOgx2ZXJzaW9uaQY6DWNvbXByZXNzVA=="
    api_secret: "BAhTOh1TeW06OkRhdGE6OldyYXBwZXJTdHJ1Y3QLOhNlbmNyeXB0ZWRfZGF0YSJVHE1D3mpTsUseEdm3NWox7xdeQExobVx3-dHnEJoK9XYXawoPvtgroxOhsaYxZtxz_ZeHtSDZwu0eyDVyZ-XDo-vxalo9cQ2FOm05hVQaebo6B2l2IhVosiRfW5FnRK4BxfwPytLcOhBjaXBoZXJfbmFtZSIQQUVTLTI1Ni1DQkM6CXNhbHQwOgx2ZXJzaW9uaQY6DWNvbXByZXNzVA=="
    encryption_key: spec/fixtures/sym.key
- name: preview
  credentials:
    api_key: "BAhTOh1TeW06OkRhdGE6OldyYXBwZXJTdHJ1Y3QLOhNlbmNyeXB0ZWRfZGF0YSJV9HFDvF4KUwQLqevf4zvsKO1Yk04kRimAHAfNgoFO0dtRb6OjREyI43uzFV7z63FGjzXcBBG9KDUdj6OowbDw2z86nkTpakkKuIP31HCPZkQ6B2l2IhV2LPWTPSfDruDxi_ToEfbQOhBjaXBoZXJfbmFtZSIQQUVTLTI1Ni1DQkM6CXNhbHQwOgx2ZXJzaW9uaQY6DWNvbXByZXNzVA=="
    api_secret: "BAhTOh1TeW06OkRhdGE6OldyYXBwZXJTdHJ1Y3QLOhNlbmNyeXB0ZWRfZGF0YSJVHE1D3mpTsUseEdm3NWox7xdeQExobVx3-dHnEJoK9XYXawoPvtgroxOhsaYxZtxz_ZeHtSDZwu0eyDVyZ-XDo-vxalo9cQ2FOm05hVQaebo6B2l2IhVosiRfW5FnRK4BxfwPytLcOhBjaXBoZXJfbmFtZSIQQUVTLTI1Ni1DQkM6CXNhbHQwOgx2ZXJzaW9uaQY6DWNvbXByZXNzVA=="
    encryption_key:
- name: staging
  credentials:
    api_key: 12345678-a8f8-4466-ffff-2324aaaa9098
    api_secret: 43009899-abcc-ffcc-eeee-09f809808098

“‘

Here we have multiple credentials account, one of which can have ‘default_account: true’ Each account has a name that’s used in ‘account` argument. Finally, if the keys are encrypted, the key can either be referenced in the YAML file itself (in the above case it points to a file name — see documentation on the gem Sym about various formats of the key).

Note that in this case, encryption key is optional, since the YAML file actually specifies the key.

@creds = DnsMadeEasy::Credentials.keys_from_file(
                   file: 'spec/fixtures/credentials-multi-account.yml',
                   account: 'production')

)

Defined Under Namespace

Classes: ApiKeys, YamlFile

Class Method Summary collapse

Class Method Details

.create(key, secret, encryption_key = nil) ⇒ Object

Create a new instance of Credentials::ApiKeys



78
79
80
# File 'lib/dnsmadeeasy/credentials.rb', line 78

def create(key, secret, encryption_key = nil)
  ApiKeys.new(key, secret, encryption_key)
end

.default_credentials_path(user: nil) ⇒ Object

Returns String path to the default credentials file.

Returns:

  • String path to the default credentials file.



91
92
93
94
95
# File 'lib/dnsmadeeasy/credentials.rb', line 91

def default_credentials_path(user: nil)
  user ?
    File.expand_path(Dir.home(user) + '/.dnsmadeeasy/credentials.yml').freeze :
    File.expand_path('~/.dnsmadeeasy/credentials.yml').freeze
end

.keys_from_file(file: default_credentials_path, account: nil, encryption_key: nil) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/dnsmadeeasy/credentials.rb', line 82

def keys_from_file(file: default_credentials_path,
                   account: nil,
                   encryption_key: nil)

  YamlFile.new(file: file).keys(account:        ,
                                encryption_key: encryption_key)
end