2011-02-07 22:12:56 -05:00
|
|
|
module Fog
|
|
|
|
module Dynect
|
|
|
|
class DNS < Fog::Service
|
|
|
|
|
|
|
|
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'
|
|
|
|
request :session
|
2011-06-17 06:51:37 -04:00
|
|
|
request :list_zones
|
|
|
|
request :get_zone
|
2011-06-19 04:09:58 -04:00
|
|
|
request :list_any_records
|
|
|
|
request :node_list
|
2011-02-07 22:12:56 -05:00
|
|
|
|
|
|
|
class Real
|
|
|
|
def initialize(options={})
|
2011-06-15 12:38:26 -04:00
|
|
|
require 'builder'
|
|
|
|
|
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
|
|
|
|
@auth_token ||= session.body['Auth-Token']
|
|
|
|
end
|
|
|
|
|
2011-02-07 22:12:56 -05:00
|
|
|
def request(params)
|
|
|
|
begin
|
|
|
|
params[:headers] ||= {}
|
|
|
|
params[:headers]['Content-Type'] = 'text/xml'
|
|
|
|
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-06-19 04:09:58 -04:00
|
|
|
response = handle_redirect(response) if response.status == 307
|
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
|
|
|
|
|
2011-06-19 04:09:58 -04:00
|
|
|
def handle_redirect(response)
|
|
|
|
raise request({
|
|
|
|
:expects => 200,
|
|
|
|
:method => "GET",
|
|
|
|
:path => response.body
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2011-02-07 22:12:56 -05:00
|
|
|
end
|
|
|
|
|
2011-06-19 04:09:58 -04:00
|
|
|
# class Mock
|
|
|
|
# end
|
|
|
|
|
2011-02-07 22:12:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|