Sha256: de7c2aa4287cff72fd4d824eebc7c26dd9a72a0fdf3375ce4fd21326dc36832d

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'public_suffix'
require 'glare/version'
require 'glare/credentials'
require 'glare/client'
require 'glare/domain'
require 'glare/api_response'
require 'glare/dns_record'
require 'glare/cf_dns_records'
require 'glare/errors'

module Glare
  class << self
    def register(fqdn, destination, type, proxied = false)
      client = build_client
      Domain.new(client).register(fqdn, destination, type, proxied)
    end

    def resolve(fqdn, type)
      client = build_client
      Domain.new(client).resolve(fqdn, type)
    end

    def deregister(fqdn, type)
      client = build_client
      Domain.new(client).deregister(fqdn, type)
    end

    def proxied?(fqdn, type)
      client = build_client
      Domain.new(client).proxied?(fqdn, type)
    end

    private

    CF_EMAIL = 'CF_EMAIL'.freeze
    CF_AUTH_KEY = 'CF_AUTH_KEY'.freeze
    CF_API_TOKEN = 'CF_API_TOKEN'.freeze

    def default_credentials
      email = ENV.fetch(CF_EMAIL)
      auth_key = ENV.fetch(CF_AUTH_KEY)
      Credentials.new(email, auth_key)
    end

    def client_with_api_key
      credentials = default_credentials
      Glare::Client.new.from_global_api_key(credentials.email, credentials.auth_key)
    end

    def client_with_api_token
      return nil unless ENV.key?(CF_API_TOKEN)

      api_token = ENV.fetch(CF_API_TOKEN)
      Glare::Client.new.from_scoped_api_token(api_token)
    end

    def build_client
      client_with_api_token || client_with_api_key
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glare-0.9.0 lib/glare.rb