2011-08-31 16:52:53 -04:00
|
|
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'bluebox'))
|
|
|
|
require 'fog/dns'
|
|
|
|
|
2011-01-24 20:30:57 -05:00
|
|
|
module Fog
|
2011-06-15 20:25:01 -04:00
|
|
|
module DNS
|
|
|
|
class Bluebox < Fog::Service
|
2011-06-16 19:39:51 -04:00
|
|
|
|
2011-01-24 20:30:57 -05:00
|
|
|
requires :bluebox_api_key, :bluebox_customer_id
|
|
|
|
recognizes :bluebox_host, :bluebox_port, :bluebox_scheme, :persistent
|
|
|
|
|
2011-08-24 20:58:47 -04:00
|
|
|
model_path 'fog/bluebox/models/dns'
|
2011-01-24 20:30:57 -05:00
|
|
|
model :record
|
|
|
|
collection :records
|
|
|
|
model :zone
|
|
|
|
collection :zones
|
|
|
|
|
2011-08-24 20:58:47 -04:00
|
|
|
request_path 'fog/bluebox/requests/dns'
|
2011-01-24 20:30:57 -05:00
|
|
|
request :create_record
|
2011-01-24 21:35:51 -05:00
|
|
|
request :update_record
|
2011-01-24 20:30:57 -05:00
|
|
|
request :delete_record
|
2011-02-17 02:27:23 -05:00
|
|
|
request :create_zone
|
|
|
|
request :update_zone
|
|
|
|
request :delete_zone
|
2011-01-24 20:30:57 -05:00
|
|
|
request :get_record
|
|
|
|
request :get_records
|
|
|
|
request :get_zone
|
|
|
|
request :get_zones
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, key|
|
|
|
|
hash[key] = {}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-19 10:05:33 -04:00
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
2011-01-24 20:30:57 -05:00
|
|
|
def initialize(options={})
|
|
|
|
@bluebox_customer_id = options[:bluebox_customer_id]
|
|
|
|
@bluebox_api_key = options[:bluebox_api_key]
|
2011-05-19 18:35:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@bluebox_customer_id]
|
2011-03-10 14:16:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset_data
|
|
|
|
self.class.data.delete(@bluebox_customer_id)
|
2011-01-24 20:30:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
def initialize(options ={})
|
|
|
|
@bluebox_customer_id = options[:bluebox_customer_id]
|
|
|
|
@bluebox_api_key = options[:bluebox_api_key]
|
2011-09-12 11:01:48 -04:00
|
|
|
@connection_options = options[:connection_options] || {}
|
|
|
|
@host = options[:bluebox_host] || "boxpanel.bluebox.net"
|
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@port = options[:bluebox_port] || 443
|
|
|
|
@scheme = options[:bluebox_scheme] || 'https'
|
|
|
|
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
|
2011-01-24 20:30:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
params[:headers] ||= {}
|
|
|
|
|
|
|
|
params[:headers]['Authorization'] = "Basic #{auth_header}"
|
|
|
|
|
2011-01-24 21:23:58 -05:00
|
|
|
params[:headers]['Accept'] = 'application/xml'
|
2011-01-24 20:30:57 -05:00
|
|
|
case params[:method]
|
|
|
|
when 'POST', 'PUT'
|
|
|
|
params[:headers]['Content-Type'] = 'application/xml'
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
response = @connection.request(params.merge!({:host => @host}))
|
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
raise case error
|
|
|
|
when Excon::Errors::NotFound
|
2011-06-15 20:25:01 -04:00
|
|
|
Fog::DNS::Bluebox::NotFound.slurp(error)
|
2011-01-24 20:30:57 -05:00
|
|
|
else
|
|
|
|
error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
response
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def auth_header
|
|
|
|
@auth_header ||= Base64.encode64("#{@bluebox_customer_id}:#{@bluebox_api_key}").gsub("\n",'')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|