2011-08-31 16:52:53 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'dnsmadeeasy'))
|
|
|
|
require 'fog/dns'
|
|
|
|
|
2011-05-29 19:41:27 -04:00
|
|
|
module Fog
|
2011-06-15 20:25:01 -04:00
|
|
|
module DNS
|
|
|
|
class DNSMadeEasy < Fog::Service
|
2011-05-29 19:41:27 -04:00
|
|
|
|
|
|
|
requires :dnsmadeeasy_api_key, :dnsmadeeasy_secret_key
|
|
|
|
recognizes :host, :path, :port, :scheme, :persistent
|
|
|
|
|
2011-08-24 20:54:20 -04:00
|
|
|
model_path 'fog/dnsmadeeasy/models/dns'
|
2011-05-29 19:41:27 -04:00
|
|
|
model :record
|
|
|
|
collection :records
|
|
|
|
model :zone
|
|
|
|
collection :zones
|
|
|
|
|
2011-08-24 20:54:20 -04:00
|
|
|
request_path 'fog/dnsmadeeasy/requests/dns'
|
2011-05-29 19:41:27 -04:00
|
|
|
request :list_domains
|
|
|
|
request :get_domain
|
|
|
|
request :create_domain
|
|
|
|
request :delete_domain
|
2011-06-05 15:37:52 -04:00
|
|
|
request :delete_all_domains
|
2011-05-29 19:41:27 -04:00
|
|
|
|
|
|
|
request :list_records
|
|
|
|
request :create_record
|
|
|
|
request :update_record
|
|
|
|
request :get_record
|
|
|
|
request :delete_record
|
|
|
|
|
|
|
|
request :list_secondary
|
|
|
|
request :delete_all_secondary
|
|
|
|
request :get_secondary
|
|
|
|
request :create_secondary
|
|
|
|
request :update_secondary
|
|
|
|
request :delete_secondary
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@dnsmadeeasy_api_key = options[:dnsmadeeasy_api_key]
|
|
|
|
@dnsmadeeasy_secret_key = options[:dnsmadeeasy_secret_key]
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@dnsmadeeasy_api_key]
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@dnsmadeeasy_api_key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
|
|
|
|
# Initialize connection to DNS Made Easy
|
|
|
|
#
|
|
|
|
# ==== Notes
|
|
|
|
# options parameter must include values for :dnsmadeeasy_api_key and
|
|
|
|
# :dnsmadeeasy_secret_key in order to create a connection
|
|
|
|
#
|
|
|
|
# ==== Examples
|
|
|
|
# dns = Fog::DNSMadeEasy::DNS.new(
|
|
|
|
# :dnsmadeeasy_api_key => your_dnsmadeeasy_api_key,
|
|
|
|
# :dnsmadeeasy_secret_key => your_dnsmadeeasy_secret_key
|
|
|
|
# )
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * dns object with connection to aws.
|
|
|
|
def initialize(options={})
|
|
|
|
require 'fog/core/parser'
|
2011-07-15 22:34:16 -04:00
|
|
|
require 'multi_json'
|
2011-05-29 19:41:27 -04:00
|
|
|
|
|
|
|
@dnsmadeeasy_api_key = options[:dnsmadeeasy_api_key]
|
|
|
|
@dnsmadeeasy_secret_key = options[:dnsmadeeasy_secret_key]
|
2011-05-29 19:48:52 -04:00
|
|
|
@host = options[:host] || 'api.dnsmadeeasy.com'
|
2011-05-29 19:41:27 -04:00
|
|
|
@port = options[:port] || 80 #443 Not yet
|
|
|
|
@scheme = options[:scheme] || 'http' #'https Not yet
|
|
|
|
unless options.has_key?(:persistent)
|
|
|
|
options[:persistent] = true
|
|
|
|
end
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:headers] ||= {}
|
|
|
|
params[:headers]['x-dnsme-apiKey'] = @dnsmadeeasy_api_key
|
|
|
|
params[:headers]['x-dnsme-requestDate'] = Fog::Time.now.to_date_header
|
|
|
|
params[:headers]['x-dnsme-hmac'] = signature(params)
|
|
|
|
params[:headers]['Accept'] = 'application/json'
|
|
|
|
params[:headers]['Content-Type'] = 'application/json'
|
|
|
|
|
|
|
|
begin
|
|
|
|
response = @connection.request(params)
|
|
|
|
|
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
2011-06-15 20:25:01 -04:00
|
|
|
Fog::DNS::DNSMadeEasy::NotFound.slurp(error)
|
2011-05-29 19:41:27 -04:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
unless response.body.empty?
|
2011-07-20 12:08:11 -04:00
|
|
|
response.body = MultiJson.decode(response.body)
|
2011-05-29 19:41:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def signature(params)
|
|
|
|
string_to_sign = params[:headers]['x-dnsme-requestDate']
|
|
|
|
signed_string = OpenSSL::HMAC.hexdigest('sha1', @dnsmadeeasy_secret_key, string_to_sign)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|