2011-02-07 22:12:56 -05:00
|
|
|
module Fog
|
2011-07-14 20:22:43 -04:00
|
|
|
module DNS
|
|
|
|
class Dynect < Fog::Service
|
2011-02-07 22:12:56 -05:00
|
|
|
|
|
|
|
requires :dynect_customer, :dynect_username, :dynect_password
|
|
|
|
recognizes :timeout, :persistent
|
|
|
|
recognizes :provider # remove post deprecation
|
|
|
|
|
2011-06-16 17:51:13 -04:00
|
|
|
model_path 'fog/dns/models/dynect'
|
|
|
|
model :record
|
|
|
|
collection :records
|
|
|
|
model :zone
|
|
|
|
collection :zones
|
2011-02-07 22:12:56 -05:00
|
|
|
|
|
|
|
request_path 'fog/dns/requests/dynect'
|
2011-07-14 20:22:43 -04:00
|
|
|
request :delete_record
|
|
|
|
request :delete_zone
|
|
|
|
request :get_node_list
|
|
|
|
request :get_record
|
2011-06-17 06:51:37 -04:00
|
|
|
request :get_zone
|
2011-07-14 20:22:43 -04:00
|
|
|
request :post_record
|
|
|
|
request :post_session
|
|
|
|
request :post_zone
|
|
|
|
request :put_zone
|
|
|
|
|
|
|
|
class Mock
|
2011-08-16 12:57:17 -04:00
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@dynect_customer = options[:dynect_customer]
|
|
|
|
@dynect_username = options[:dynect_username]
|
|
|
|
@dynect_password = options[:dynect_password]
|
|
|
|
end
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
end
|
2011-02-07 22:12:56 -05:00
|
|
|
|
|
|
|
class Real
|
|
|
|
def initialize(options={})
|
2011-07-14 20:22:43 -04:00
|
|
|
require 'multi_json'
|
2011-06-15 12:38:26 -04:00
|
|
|
|
2011-02-07 22:12:56 -05:00
|
|
|
@dynect_customer = options[:dynect_customer]
|
|
|
|
@dynect_username = options[:dynect_username]
|
|
|
|
@dynect_password = options[:dynect_password]
|
|
|
|
|
2011-02-08 21:31:24 -05:00
|
|
|
@host = "api2.dynect.net"
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@path = options[:path] || '/REST'
|
|
|
|
@scheme = options[:scheme] || 'https'
|
|
|
|
@version = options[:version] || '2.3.1'
|
2011-02-07 22:12:56 -05:00
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent] || true)
|
|
|
|
end
|
|
|
|
|
2011-02-08 21:47:44 -05:00
|
|
|
def auth_token
|
2011-07-14 20:22:43 -04:00
|
|
|
@auth_token ||= post_session.body['data']['token']
|
2011-02-08 21:47:44 -05:00
|
|
|
end
|
|
|
|
|
2011-02-07 22:12:56 -05:00
|
|
|
def request(params)
|
|
|
|
begin
|
|
|
|
params[:headers] ||= {}
|
2011-07-14 20:22:43 -04:00
|
|
|
params[:headers]['Content-Type'] = 'application/json'
|
2011-02-07 22:12:56 -05:00
|
|
|
params[:headers]['API-Version'] = @version
|
2011-02-08 21:47:44 -05:00
|
|
|
params[:headers]['Auth-Token'] = auth_token unless params[:path] == "Session"
|
2011-02-08 21:31:24 -05:00
|
|
|
params[:path] = "#{@path}/#{params[:path]}"
|
2011-02-07 22:12:56 -05:00
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
2011-07-14 20:22:43 -04:00
|
|
|
|
|
|
|
unless response.body.empty?
|
|
|
|
response.body = MultiJson.decode(response.body)
|
|
|
|
end
|
|
|
|
response
|
|
|
|
|
2011-02-07 22:12:56 -05:00
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
2011-02-08 21:47:44 -05:00
|
|
|
raise error
|
2011-02-07 22:12:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|