class DnsMadeEasy::Credentials::ApiKeys
Immutable instance with key and secret.
Constants
- API_KEY_REGEX
Attributes
account[R]
api_key[R]
api_secret[R]
default[R]
encryption_key[R]
Public Class Methods
new(key, secret, encryption_key = nil, default: false, account: nil)
click to toggle source
# File lib/dnsmadeeasy/credentials/api_keys.rb, line 26 def initialize(key, secret, encryption_key = nil, default: false, account: nil) raise InvalidCredentialKeys, "Key and Secret can not be nil" if key.nil? || secret.nil? @default = default @account = account if !valid?(key, secret) && encryption_key @encryption_key = sym_resolve(encryption_key) @api_key = decr(key, @encryption_key) @api_secret = decr(secret, @encryption_key) else @api_key = key @api_secret = secret end raise InvalidCredentialKeys, "Key [#{api_key}] or Secret [#{api_secret}] has failed validation for its format" unless valid? end
Public Instance Methods
==(other)
click to toggle source
# File lib/dnsmadeeasy/credentials/api_keys.rb, line 69 def ==(other) other.is_a?(ApiKeys) && other.valid? && other.api_key == api_key && other.api_secret == api_secret end
Also aliased as: eql?
rofl(key)
click to toggle source
# File lib/dnsmadeeasy/credentials/api_keys.rb, line 58 def rofl(key) Digest::SHA256.hexdigest(key) if key end
sym_resolve(encryption_key)
click to toggle source
# File lib/dnsmadeeasy/credentials/api_keys.rb, line 44 def sym_resolve(encryption_key) null_output = ::File.open('/dev/null', 'w') result = Sym::Application.new({ cache_passwords: true, key: encryption_key }, $stdin, null_output, null_output).execute if result.is_a?(Hash) raise InvalidCredentialKeys, "Unable to decrypt the data, error is: #{result[:exception]}" else result end end
to_s()
click to toggle source
# File lib/dnsmadeeasy/credentials/api_keys.rb, line 54 def to_s "<#{self.class.name}#key=[s#{rofl(api_key)}] secret=[#{rofl(api_secret)}] encryption_key=[#{rofl(encryption_key)}]>" end
valid?(key = api_key, secret = api_secret)
click to toggle source
# File lib/dnsmadeeasy/credentials/api_keys.rb, line 62 def valid?(key = api_key, secret = api_secret) key && secret && API_KEY_REGEX.match(key) && API_KEY_REGEX.match(secret) end