mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Allow dnsimple authentication via API tokens
This commit is contained in:
parent
b76f85fee3
commit
6b709de6c8
1 changed files with 23 additions and 7 deletions
|
@ -4,8 +4,7 @@ module Fog
|
|||
module DNS
|
||||
class DNSimple < Fog::Service
|
||||
|
||||
requires :dnsimple_email, :dnsimple_password
|
||||
recognizes :dnsimple_url, :host, :path, :port, :scheme, :persistent
|
||||
recognizes :dnsimple_email, :dnsimple_password, :dnsimple_token, :dnsimple_domain, :dnsimple_url, :host, :path, :port, :scheme, :persistent
|
||||
|
||||
model_path 'fog/dnsimple/models/dns'
|
||||
model :record
|
||||
|
@ -42,6 +41,8 @@ module Fog
|
|||
def initialize(options={})
|
||||
@dnsimple_email = options[:dnsimple_email]
|
||||
@dnsimple_password = options[:dnsimple_password]
|
||||
@dnsimple_token = options[:dnsimple_token]
|
||||
@dnsimple_domain = options[:dnsimple_domain]
|
||||
end
|
||||
|
||||
def data
|
||||
|
@ -59,6 +60,8 @@ module Fog
|
|||
def initialize(options={})
|
||||
@dnsimple_email = options[:dnsimple_email]
|
||||
@dnsimple_password = options[:dnsimple_password]
|
||||
@dnsimple_token = options[:dnsimple_token]
|
||||
@dnsimple_domain = options[:dnsimple_domain]
|
||||
@connection_options = options[:connection_options] || {}
|
||||
if options[:dnsimple_url]
|
||||
uri = URI.parse(options[:dnsimple_url])
|
||||
|
@ -79,13 +82,26 @@ module Fog
|
|||
|
||||
def request(params)
|
||||
params[:headers] ||= {}
|
||||
key = "#{@dnsimple_email}:#{@dnsimple_password}"
|
||||
params[:headers].merge!({ "Authorization" => "Basic " + Base64.encode64(key).gsub("\n",''),
|
||||
"Accept" => "application/json",
|
||||
"Content-Type" => "application/json" })
|
||||
|
||||
if(@dnsimple_password)
|
||||
key = "#{@dnsimple_email}:#{@dnsimple_password}"
|
||||
params[:headers].merge!("Authorization" => "Basic " + Base64.encode64(key).gsub("\n",''))
|
||||
elsif(@dnsimple_token)
|
||||
if(@dnsimple_domain)
|
||||
params[:headers].merge!("X-DNSimple-Domain-Token" => @dnsimple_token)
|
||||
else
|
||||
params[:headers].merge!("X-DNSimple-Token" => "#{@dnsimple_email}:#{@dnsimple_token}")
|
||||
end
|
||||
else
|
||||
raise ArgumentError.new("Insufficient credentials to properly authenticate!")
|
||||
end
|
||||
params[:headers].merge!(
|
||||
"Accept" => "application/json",
|
||||
"Content-Type" => "application/json"
|
||||
)
|
||||
|
||||
version = params.delete(:version) || 'v1'
|
||||
params[:path] = "/#{version}#{params[:path]}"
|
||||
params[:path] = File.join('/', version, params[:path])
|
||||
|
||||
response = @connection.request(params)
|
||||
|
||||
|
|
Loading…
Reference in a new issue