1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/dns/slicehost.rb

106 lines
3 KiB
Ruby
Raw Normal View History

module Fog
module Slicehost
class DNS < Fog::Service
requires :slicehost_password
recognizes :host, :port, :scheme, :persistent
2011-01-07 21:14:39 -05:00
recognizes :provider # remove post deprecation
2011-01-07 19:12:04 -05:00
model_path 'fog/dns/models/slicehost'
2010-12-23 18:36:08 -05:00
model :record
collection :records
model :zone
collection :zones
2011-01-07 19:12:04 -05:00
request_path 'fog/dns/requests/slicehost'
request :create_record
request :create_zone
request :delete_record
request :delete_zone
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
def self.reset_data(keys=data.keys)
for key in [*keys]
data.delete(key)
end
end
def initialize(options={})
2011-01-07 21:14:39 -05:00
unless options.delete(:provider)
location = caller.first
warning = "[yellow][WARN] Fog::Slicehost::DNS.new is deprecated, use Fog::DNS.new(:provider => 'Slicehost') instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
end
@slicehost_password = options[:slicehost_password]
@data = self.class.data[@slicehost_password]
end
end
class Real
def initialize(options={})
2011-01-07 21:14:39 -05:00
unless options.delete(:provider)
location = caller.first
warning = "[yellow][WARN] Fog::Slicehost::DNS.new is deprecated, use Fog::DNS.new(:provider => 'Slicehost') instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
end
2011-02-16 20:25:50 -05:00
require 'fog/core/parser'
@slicehost_password = options[:slicehost_password]
@host = options[:host] || "api.slicehost.com"
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", options[:persistent])
end
def reload
@connection.reset
end
def request(params)
params[:headers] ||= {}
params[:headers].merge!({
'Authorization' => "Basic #{Base64.encode64(@slicehost_password).delete("\r\n")}"
})
case params[:method]
when 'DELETE', 'GET', 'HEAD'
params[:headers]['Accept'] = 'application/xml'
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
Fog::Slicehost::DNS::NotFound.slurp(error)
else
error
end
end
response
end
end
end
end
end