dnsimple-ruby 1.7.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +3 -9
- data/{CHANGELOG.markdown → CHANGELOG.md} +4 -0
- data/Gemfile +0 -2
- data/LICENSE +1 -1
- data/README.md +5 -0
- data/Rakefile +0 -15
- data/dnsimple-ruby.gemspec +11 -19
- data/lib/dnsimple-ruby.rb +2 -0
- metadata +20 -288
- data/README.markdown +0 -159
- data/bin/dnsimple +0 -4
- data/bin/dnsimple.rb +0 -156
- data/features/README.md +0 -9
- data/features/cli/certificates/purchase_certificate.feature +0 -10
- data/features/cli/contacts/create_contact.feature +0 -10
- data/features/cli/domains/check_domain.feature +0 -10
- data/features/cli/domains/create_domain.feature +0 -10
- data/features/cli/domains/delete_domain.feature +0 -11
- data/features/cli/domains/register_domain.feature +0 -10
- data/features/cli/records/create_ptr_record.feature +0 -11
- data/features/cli/records/create_record.feature +0 -12
- data/features/cli/records/delete_record.feature +0 -14
- data/features/cli/templates/apply_template.feature +0 -11
- data/features/step_definitions/certificate_steps.rb +0 -3
- data/features/step_definitions/cli_steps.rb +0 -8
- data/features/step_definitions/domain_steps.rb +0 -32
- data/features/step_definitions/record_steps.rb +0 -38
- data/features/step_definitions/template_steps.rb +0 -9
- data/features/support/env.rb +0 -19
- data/lib/dnsimple.rb +0 -33
- data/lib/dnsimple/base.rb +0 -10
- data/lib/dnsimple/certificate.rb +0 -140
- data/lib/dnsimple/cli.rb +0 -121
- data/lib/dnsimple/client.rb +0 -128
- data/lib/dnsimple/commands/certificate_describe.rb +0 -34
- data/lib/dnsimple/commands/certificate_list.rb +0 -15
- data/lib/dnsimple/commands/certificate_purchase.rb +0 -17
- data/lib/dnsimple/commands/certificate_submit.rb +0 -17
- data/lib/dnsimple/commands/contact_create.rb +0 -23
- data/lib/dnsimple/commands/contact_delete.rb +0 -14
- data/lib/dnsimple/commands/contact_describe.rb +0 -25
- data/lib/dnsimple/commands/contact_list.rb +0 -13
- data/lib/dnsimple/commands/contact_update.rb +0 -25
- data/lib/dnsimple/commands/domain_apply_template.rb +0 -15
- data/lib/dnsimple/commands/domain_check.rb +0 -11
- data/lib/dnsimple/commands/domain_clear.rb +0 -16
- data/lib/dnsimple/commands/domain_create.rb +0 -16
- data/lib/dnsimple/commands/domain_delete.rb +0 -14
- data/lib/dnsimple/commands/domain_describe.rb +0 -14
- data/lib/dnsimple/commands/domain_list.rb +0 -13
- data/lib/dnsimple/commands/domain_register.rb +0 -33
- data/lib/dnsimple/commands/domain_transfer.rb +0 -21
- data/lib/dnsimple/commands/extended_attribute_list.rb +0 -25
- data/lib/dnsimple/commands/me.rb +0 -18
- data/lib/dnsimple/commands/record_create.rb +0 -18
- data/lib/dnsimple/commands/record_delete.rb +0 -16
- data/lib/dnsimple/commands/record_describe.rb +0 -16
- data/lib/dnsimple/commands/record_list.rb +0 -19
- data/lib/dnsimple/commands/record_update.rb +0 -23
- data/lib/dnsimple/commands/service_add.rb +0 -14
- data/lib/dnsimple/commands/service_describe.rb +0 -12
- data/lib/dnsimple/commands/service_list.rb +0 -14
- data/lib/dnsimple/commands/service_list_applied.rb +0 -16
- data/lib/dnsimple/commands/service_list_available.rb +0 -16
- data/lib/dnsimple/commands/service_remove.rb +0 -14
- data/lib/dnsimple/commands/template_create.rb +0 -14
- data/lib/dnsimple/commands/template_delete.rb +0 -13
- data/lib/dnsimple/commands/template_list.rb +0 -13
- data/lib/dnsimple/commands/template_record_create.rb +0 -18
- data/lib/dnsimple/commands/template_record_delete.rb +0 -16
- data/lib/dnsimple/commands/template_record_list.rb +0 -17
- data/lib/dnsimple/contact.rb +0 -154
- data/lib/dnsimple/domain.rb +0 -217
- data/lib/dnsimple/error.rb +0 -32
- data/lib/dnsimple/extended_attribute.rb +0 -52
- data/lib/dnsimple/record.rb +0 -94
- data/lib/dnsimple/service.rb +0 -42
- data/lib/dnsimple/template.rb +0 -63
- data/lib/dnsimple/template_record.rb +0 -80
- data/lib/dnsimple/transfer_order.rb +0 -34
- data/lib/dnsimple/user.rb +0 -51
- data/lib/dnsimple/version.rb +0 -3
- data/spec/ci/.dnsimple.test +0 -3
- data/spec/commands/certificate_purchase_spec.rb +0 -25
- data/spec/commands/certificate_submit_spec.rb +0 -18
- data/spec/commands/record_create_spec.rb +0 -23
- data/spec/commands/record_list_spec.rb +0 -23
- data/spec/commands/service_add_spec.rb +0 -20
- data/spec/dnsimple/certificate_spec.rb +0 -59
- data/spec/dnsimple/client_spec.rb +0 -154
- data/spec/dnsimple/contact_spec.rb +0 -45
- data/spec/dnsimple/domain_spec.rb +0 -133
- data/spec/dnsimple/extended_attributes_spec.rb +0 -54
- data/spec/dnsimple/record_spec.rb +0 -51
- data/spec/dnsimple/template_spec.rb +0 -31
- data/spec/dnsimple/user_spec.rb +0 -70
- data/spec/files/2fa/error-badtoken.http +0 -22
- data/spec/files/2fa/error-required.http +0 -23
- data/spec/files/2fa/exchange-token.http +0 -25
- data/spec/files/account/user/success.http +0 -19
- data/spec/files/certificates/index/success.http +0 -19
- data/spec/files/certificates/show/notfound.http +0 -17
- data/spec/files/certificates/show/success.http +0 -19
- data/spec/files/contacts/show/notfound.http +0 -17
- data/spec/files/contacts/show/success.http +0 -19
- data/spec/files/domains/auto_renewal_disable/notfound.http +0 -21
- data/spec/files/domains/auto_renewal_disable/success.http +0 -23
- data/spec/files/domains/auto_renewal_enable/notfound.http +0 -21
- data/spec/files/domains/auto_renewal_enable/success.http +0 -23
- data/spec/files/domains/show/notfound.http +0 -17
- data/spec/files/domains/show/success.http +0 -19
- data/spec/files/extended_attributes/ca.http +0 -19
- data/spec/files/extended_attributes/com.http +0 -19
- data/spec/files/extended_attributes/success.http +0 -19
- data/spec/files/records/index/success.http +0 -19
- data/spec/files/records/show/notfound.http +0 -17
- data/spec/files/records/show/success.http +0 -19
- data/spec/files/templates/show/notfound.http +0 -17
- data/spec/files/templates/show/success.http +0 -19
- data/spec/spec_helper.rb +0 -39
- data/spec/support/helpers.rb +0 -15
- data/spec/support/webmock.rb +0 -11
@@ -1,8 +0,0 @@
|
|
1
|
-
Given /^I have set up my credentials$/ do
|
2
|
-
path = DNSimple::Client.config_path
|
3
|
-
File.exists?(File.expand_path(path)).should be_truthy, "Please set up your #{path} file to continue"
|
4
|
-
credentials = YAML.load(File.new(File.expand_path(path)))
|
5
|
-
expect(credentials['username']).to_not be_nil, "You must specify a username in your #{path} file"
|
6
|
-
expect(credentials['password']).to_not be_nil, "You must specify a password in your #{path} file"
|
7
|
-
expect(credentials['base_uri']).to_not be_nil, "For cucumber to run, you must specify a base_uri in your #{path} file"
|
8
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
When /^I run `(.*)` with a new domain$/ do |cmd|
|
2
|
-
@domain_name = "cli-test-#{Time.now.to_i}.com"
|
3
|
-
steps %Q(When I run `#{cmd} #{@domain_name}`)
|
4
|
-
end
|
5
|
-
|
6
|
-
When /^I run `(.*)` with a in\-addr\.arpa domain$/ do |cmd|
|
7
|
-
@domain_name = '0.0.10.in-addr.arpa'
|
8
|
-
steps %Q(When I run `#{cmd} #{@domain_name}`)
|
9
|
-
end
|
10
|
-
|
11
|
-
When /^I run `(.*)` with a domain I created$/ do |cmd|
|
12
|
-
steps %Q(
|
13
|
-
When I run `dnsimple create` with a new domain
|
14
|
-
)
|
15
|
-
steps %Q(
|
16
|
-
And I run `#{cmd} #{@domain_name}`
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
Then /^the output should show that the domain was created$/ do
|
21
|
-
steps %Q(Then the output should contain "Created #{@domain_name}")
|
22
|
-
end
|
23
|
-
|
24
|
-
Then /^the output should show that the domain was deleted$/ do
|
25
|
-
steps %Q(Then the output should contain "Deleted #{@domain_name}")
|
26
|
-
end
|
27
|
-
|
28
|
-
Then /^the output should show that the domain was registered$/ do
|
29
|
-
steps %Q(Then the output should contain "Registered #{@domain_name}")
|
30
|
-
end
|
31
|
-
|
32
|
-
|
@@ -1,38 +0,0 @@
|
|
1
|
-
When /^I run `(.*)` with the domain I added and no name and the type "([^\"]*)" and the content "([^\"]*)"$/ do |cmd, type, content|
|
2
|
-
steps %Q(When I run `#{cmd} #{@domain_name} '' #{type} #{content}`)
|
3
|
-
end
|
4
|
-
|
5
|
-
When /^I run `(.*)` with the domain I added and the name "([^\"]*)" and the type "([^\"]*)" and the content "([^\"]*)"$/ do |cmd, name, type, content|
|
6
|
-
steps %Q(When I run `#{cmd} #{@domain_name} #{name} #{type} #{content}`)
|
7
|
-
end
|
8
|
-
|
9
|
-
When /^I run `(.*)` with the id of the record$/ do |cmd|
|
10
|
-
steps %Q(When I run `#{cmd} #{@domain_name} #{@record_id}`)
|
11
|
-
end
|
12
|
-
|
13
|
-
When /^I note the id of the record I added$/ do
|
14
|
-
ps = only_processes.last
|
15
|
-
fail "No last process" unless ps
|
16
|
-
m = ps.stdout.match(/id:(\d+)/)
|
17
|
-
fail "Unable to find ID of record" unless m
|
18
|
-
@record_id = m[1]
|
19
|
-
end
|
20
|
-
|
21
|
-
Then /^the output should show that the "([^\"]*)" record was created$/ do |type|
|
22
|
-
steps %Q(Then the output should contain "Created #{type} record for #{@domain_name}")
|
23
|
-
end
|
24
|
-
|
25
|
-
Then /^the output should include the record id$/ do
|
26
|
-
steps %Q(Then the output should match /id:(\\d+)/)
|
27
|
-
end
|
28
|
-
|
29
|
-
Then /^the output should show that the record was deleted$/ do
|
30
|
-
steps %Q(Then the output should contain "Deleted #{@record_id} from #{@domain_name}")
|
31
|
-
end
|
32
|
-
|
33
|
-
Then /^I the domain should have (\d+) records$/ do |n|
|
34
|
-
steps %Q(
|
35
|
-
When I run `dnsimple record:list #{@domain_name}`
|
36
|
-
Then the output should contain "Found #{n} records for #{@domain_name}"
|
37
|
-
)
|
38
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
When /^I run `(.*)` with the domain and the template named "([^\"]*)"$/ do |cmd, template|
|
2
|
-
@template_name = template
|
3
|
-
steps %Q(When I run `#{cmd} #{@domain_name} #{template}`)
|
4
|
-
end
|
5
|
-
|
6
|
-
Then /^the output should show that the template was applied$/ do
|
7
|
-
steps %Q(Then the output should contain "Applied template #{@template_name} to #{@domain_name}")
|
8
|
-
end
|
9
|
-
|
data/features/support/env.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler/setup'
|
3
|
-
require 'aruba/cucumber'
|
4
|
-
|
5
|
-
$:.unshift(File.dirname(__FILE__) + '/lib')
|
6
|
-
require 'dnsimple'
|
7
|
-
|
8
|
-
Before do
|
9
|
-
@aruba_timeout_seconds = 30
|
10
|
-
ENV['DNSIMPLE_CONFIG'] = '~/.dnsimple.test'
|
11
|
-
end
|
12
|
-
|
13
|
-
After do |scenario|
|
14
|
-
unless ENV['NODELETE'] || scenario.source_tag_names.include?('@skip-delete')
|
15
|
-
if @domain_name && (@domain_name =~ /^cli-/ || @domain_name =~ /in-addr\.arpa/)
|
16
|
-
steps %Q(When I run `dnsimple delete #{@domain_name}`)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/dnsimple.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
|
3
|
-
module DNSimple
|
4
|
-
|
5
|
-
BLANK_REGEX = /\S+/
|
6
|
-
|
7
|
-
# Echoes a deprecation warning message.
|
8
|
-
#
|
9
|
-
# @param [String] message The message to display.
|
10
|
-
# @return [void]
|
11
|
-
#
|
12
|
-
# @api internal
|
13
|
-
# @private
|
14
|
-
def self.deprecate(message = nil)
|
15
|
-
message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
|
16
|
-
warn("DEPRECATION WARNING: #{message}")
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
require 'dnsimple/base'
|
22
|
-
require 'dnsimple/client'
|
23
|
-
require 'dnsimple/error'
|
24
|
-
require 'dnsimple/user'
|
25
|
-
require 'dnsimple/contact'
|
26
|
-
require 'dnsimple/domain'
|
27
|
-
require 'dnsimple/record'
|
28
|
-
require 'dnsimple/template'
|
29
|
-
require 'dnsimple/template_record'
|
30
|
-
require 'dnsimple/transfer_order'
|
31
|
-
require 'dnsimple/extended_attribute'
|
32
|
-
require 'dnsimple/service'
|
33
|
-
require 'dnsimple/certificate'
|
data/lib/dnsimple/base.rb
DELETED
data/lib/dnsimple/certificate.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
|
3
|
-
# Represents an SSL certificate that has been purchased.
|
4
|
-
#
|
5
|
-
# The certificate must also be submitted using the #submit method
|
6
|
-
# before the Certificate Authority will issue a signed certificate.
|
7
|
-
class Certificate < Base
|
8
|
-
|
9
|
-
# The Fixnum certificate ID in DNSimple.
|
10
|
-
attr_accessor :id
|
11
|
-
|
12
|
-
# The Fixnum associated domain ID.
|
13
|
-
attr_accessor :domain_id
|
14
|
-
|
15
|
-
# The Fixnum associated contact ID.
|
16
|
-
attr_accessor :contact_id
|
17
|
-
|
18
|
-
# The String subdomain on the certificate.
|
19
|
-
attr_accessor :name
|
20
|
-
|
21
|
-
# The String state.
|
22
|
-
attr_accessor :state
|
23
|
-
|
24
|
-
# The String Certificate Signing Request.
|
25
|
-
attr_accessor :csr
|
26
|
-
|
27
|
-
# The String SSL certificate.
|
28
|
-
# It is set only if the order issued by the Certificate Authority.
|
29
|
-
attr_accessor :ssl_certificate
|
30
|
-
|
31
|
-
# The String private key.
|
32
|
-
# It is set only if DNSimple generated the Certificate Signing Request.
|
33
|
-
attr_accessor :private_key
|
34
|
-
|
35
|
-
# The String approver email address
|
36
|
-
# It is set only if the state is submitted.
|
37
|
-
attr_accessor :approver_email
|
38
|
-
|
39
|
-
# The Array of all emails that can be used to approve the certificate.
|
40
|
-
# It is set only if the state is configured.
|
41
|
-
attr_accessor :approver_emails
|
42
|
-
|
43
|
-
# The Date the certificate was purchased
|
44
|
-
attr_accessor :created_at
|
45
|
-
|
46
|
-
# The Date the certificate was last updated
|
47
|
-
attr_accessor :updated_at
|
48
|
-
|
49
|
-
# The Date the certificate was configured
|
50
|
-
attr_accessor :configured_at
|
51
|
-
|
52
|
-
# The Date the Certificate will expire
|
53
|
-
attr_accessor :expires_on
|
54
|
-
|
55
|
-
# The associated Domain.
|
56
|
-
attr_accessor :domain
|
57
|
-
|
58
|
-
|
59
|
-
# Purchase a certificate under the given domain with the given name. The
|
60
|
-
# name will be appended to the domain name, and thus should only be the
|
61
|
-
# subdomain part.
|
62
|
-
#
|
63
|
-
# Example: DNSimple::Certificate.purchase(domain, 'www', contact)
|
64
|
-
#
|
65
|
-
# Please note that by invoking this method DNSimple will immediately charge
|
66
|
-
# your credit card on file at DNSimple for the full certificate price.
|
67
|
-
#
|
68
|
-
# For wildcard certificates an asterisk must appear in the name.
|
69
|
-
#
|
70
|
-
# Example: DNSimple::Certificate.purchase(domain, '*', contact)
|
71
|
-
def self.purchase(domain, name, contact, options={})
|
72
|
-
certificate_hash = {
|
73
|
-
:name => name,
|
74
|
-
:contact_id => contact.id
|
75
|
-
}
|
76
|
-
|
77
|
-
options.merge!({:body => {:certificate => certificate_hash}})
|
78
|
-
|
79
|
-
response = DNSimple::Client.post("/v1/domains/#{domain.name}/certificates", options)
|
80
|
-
|
81
|
-
case response.code
|
82
|
-
when 201
|
83
|
-
new({ :domain => domain }.merge(response["certificate"]))
|
84
|
-
when 406
|
85
|
-
raise RecordExists, "Certificate for #{domain.name} already exists"
|
86
|
-
else
|
87
|
-
raise RequestError.new("Error purchasing certificate", response)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# Get an array of all certificates for the given domain.
|
92
|
-
def self.all(domain, options={})
|
93
|
-
response = DNSimple::Client.get("/v1/domains/#{domain.name}/certificates", options)
|
94
|
-
|
95
|
-
case response.code
|
96
|
-
when 200
|
97
|
-
response.map { |r| new({:domain => domain}.merge(r["certificate"])) }
|
98
|
-
else
|
99
|
-
raise RequestError.new("Error listing certificates", response)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Find a specific certificate for the given domain.
|
104
|
-
def self.find(domain, id, options = {})
|
105
|
-
response = DNSimple::Client.get("/v1/domains/#{domain.name}/certificates/#{id}", options)
|
106
|
-
|
107
|
-
case response.code
|
108
|
-
when 200
|
109
|
-
new({:domain => domain}.merge(response["certificate"]))
|
110
|
-
when 404
|
111
|
-
raise RecordNotFound, "Could not find certificate #{id} for domain #{domain.name}"
|
112
|
-
else
|
113
|
-
raise RequestError.new("Error finding certificate", response)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
# Get the fully-qualified domain name for the certificate. This is the
|
119
|
-
# domain.name joined with the certificate name, separated by a period.
|
120
|
-
def fqdn
|
121
|
-
[name, domain.name].delete_if { |p| p !~ DNSimple::BLANK_REGEX }.join(".")
|
122
|
-
end
|
123
|
-
|
124
|
-
def submit(approver_email, options={})
|
125
|
-
raise DNSimple::Error, "Approver email is required" unless approver_email
|
126
|
-
|
127
|
-
options.merge!(:body => {:certificate => {:approver_email => approver_email}})
|
128
|
-
|
129
|
-
response = DNSimple::Client.put("/v1/domains/#{domain.name}/certificates/#{id}/submit", options)
|
130
|
-
|
131
|
-
case response.code
|
132
|
-
when 200
|
133
|
-
Certificate.new({ :domain => domain }.merge(response["certificate"]))
|
134
|
-
else
|
135
|
-
raise RequestError.new("Error submitting certificate", response)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
end
|
data/lib/dnsimple/cli.rb
DELETED
@@ -1,121 +0,0 @@
|
|
1
|
-
module DNSimple
|
2
|
-
|
3
|
-
class CommandNotFound < RuntimeError
|
4
|
-
end
|
5
|
-
|
6
|
-
class CLI
|
7
|
-
|
8
|
-
def execute(command_name, args, options={})
|
9
|
-
DNSimple::Client.load_credentials_if_necessary
|
10
|
-
command = commands[command_name]
|
11
|
-
if command
|
12
|
-
begin
|
13
|
-
command.new.execute(args, options)
|
14
|
-
rescue DNSimple::Error => e
|
15
|
-
puts "An error occurred: #{e.message}"
|
16
|
-
rescue RuntimeError => e
|
17
|
-
puts "An error occurred: #{e.message}"
|
18
|
-
end
|
19
|
-
else
|
20
|
-
raise CommandNotFound, "Unknown command: #{command_name}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def commands
|
25
|
-
{
|
26
|
-
'info' => DNSimple::Commands::Me,
|
27
|
-
|
28
|
-
'list' => DNSimple::Commands::DomainList,
|
29
|
-
'describe' => DNSimple::Commands::DomainDescribe,
|
30
|
-
'check' => DNSimple::Commands::DomainCheck,
|
31
|
-
'create' => DNSimple::Commands::DomainCreate,
|
32
|
-
'register' => DNSimple::Commands::DomainRegister,
|
33
|
-
'transfer' => DNSimple::Commands::DomainTransfer,
|
34
|
-
'delete' => DNSimple::Commands::DomainDelete,
|
35
|
-
'clear' => DNSimple::Commands::DomainClear,
|
36
|
-
'apply' => DNSimple::Commands::DomainApplyTemplate,
|
37
|
-
|
38
|
-
'record:describe' => DNSimple::Commands::RecordDescribe,
|
39
|
-
'record:create' => DNSimple::Commands::RecordCreate,
|
40
|
-
'record:list' => DNSimple::Commands::RecordList,
|
41
|
-
'record:update' => DNSimple::Commands::RecordUpdate,
|
42
|
-
'record:delete' => DNSimple::Commands::RecordDelete,
|
43
|
-
|
44
|
-
'template:create' => DNSimple::Commands::TemplateCreate,
|
45
|
-
'template:list' => DNSimple::Commands::TemplateList,
|
46
|
-
'template:delete' => DNSimple::Commands::TemplateDelete,
|
47
|
-
|
48
|
-
'template:list_records' => DNSimple::Commands::TemplateRecordList,
|
49
|
-
'template:add_record' => DNSimple::Commands::TemplateRecordCreate,
|
50
|
-
'template:delete_record' => DNSimple::Commands::TemplateRecordDelete,
|
51
|
-
|
52
|
-
'contact:create' => DNSimple::Commands::ContactCreate,
|
53
|
-
'contact:list' => DNSimple::Commands::ContactList,
|
54
|
-
'contact:describe' => DNSimple::Commands::ContactDescribe,
|
55
|
-
'contact:update' => DNSimple::Commands::ContactUpdate,
|
56
|
-
'contact:delete' => DNSimple::Commands::ContactDelete,
|
57
|
-
|
58
|
-
'extended-attributes:list' => DNSimple::Commands::ExtendedAttributeList,
|
59
|
-
|
60
|
-
'service:list' => DNSimple::Commands::ServiceList,
|
61
|
-
'service:describe' => DNSimple::Commands::ServiceDescribe,
|
62
|
-
|
63
|
-
'service:applied' => DNSimple::Commands::ServiceListApplied,
|
64
|
-
'service:available' => DNSimple::Commands::ServiceListAvailable,
|
65
|
-
'service:add' => DNSimple::Commands::ServiceAdd,
|
66
|
-
'service:remove' => DNSimple::Commands::ServiceRemove,
|
67
|
-
|
68
|
-
'certificate:list' => DNSimple::Commands::CertificateList,
|
69
|
-
'certificate:describe' => DNSimple::Commands::CertificateDescribe,
|
70
|
-
'certificate:purchase' => DNSimple::Commands::CertificatePurchase,
|
71
|
-
'certificate:submit' => DNSimple::Commands::CertificateSubmit,
|
72
|
-
}
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
require 'dnsimple/commands/me'
|
78
|
-
|
79
|
-
require 'dnsimple/commands/domain_list'
|
80
|
-
require 'dnsimple/commands/domain_describe'
|
81
|
-
require 'dnsimple/commands/domain_check'
|
82
|
-
require 'dnsimple/commands/domain_create'
|
83
|
-
require 'dnsimple/commands/domain_register'
|
84
|
-
require 'dnsimple/commands/domain_transfer'
|
85
|
-
require 'dnsimple/commands/domain_delete'
|
86
|
-
require 'dnsimple/commands/domain_clear'
|
87
|
-
require 'dnsimple/commands/domain_apply_template'
|
88
|
-
|
89
|
-
require 'dnsimple/commands/record_list'
|
90
|
-
require 'dnsimple/commands/record_describe'
|
91
|
-
require 'dnsimple/commands/record_create'
|
92
|
-
require 'dnsimple/commands/record_update'
|
93
|
-
require 'dnsimple/commands/record_delete'
|
94
|
-
|
95
|
-
require 'dnsimple/commands/template_list'
|
96
|
-
require 'dnsimple/commands/template_create'
|
97
|
-
require 'dnsimple/commands/template_delete'
|
98
|
-
require 'dnsimple/commands/template_record_list'
|
99
|
-
require 'dnsimple/commands/template_record_create'
|
100
|
-
require 'dnsimple/commands/template_record_delete'
|
101
|
-
|
102
|
-
require 'dnsimple/commands/contact_list'
|
103
|
-
require 'dnsimple/commands/contact_describe'
|
104
|
-
require 'dnsimple/commands/contact_create'
|
105
|
-
require 'dnsimple/commands/contact_update'
|
106
|
-
require 'dnsimple/commands/contact_delete'
|
107
|
-
|
108
|
-
require 'dnsimple/commands/extended_attribute_list'
|
109
|
-
|
110
|
-
require 'dnsimple/commands/service_list'
|
111
|
-
require 'dnsimple/commands/service_describe'
|
112
|
-
|
113
|
-
require 'dnsimple/commands/service_list_available'
|
114
|
-
require 'dnsimple/commands/service_list_applied'
|
115
|
-
require 'dnsimple/commands/service_add'
|
116
|
-
require 'dnsimple/commands/service_remove'
|
117
|
-
|
118
|
-
require 'dnsimple/commands/certificate_list'
|
119
|
-
require 'dnsimple/commands/certificate_describe'
|
120
|
-
require 'dnsimple/commands/certificate_purchase'
|
121
|
-
require 'dnsimple/commands/certificate_submit'
|
data/lib/dnsimple/client.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'dnsimple/version'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
module DNSimple
|
5
|
-
class Client
|
6
|
-
|
7
|
-
DEFAULT_BASE_URI = "https://api.dnsimple.com/"
|
8
|
-
HEADER_2FA_STRICT = "X-DNSimple-2FA-Strict"
|
9
|
-
HEADER_API_TOKEN = "X-DNSimple-Token"
|
10
|
-
HEADER_DOMAIN_API_TOKEN = "X-DNSimple-Domain-Token"
|
11
|
-
HEADER_OTP_TOKEN = "X-DNSimple-OTP"
|
12
|
-
HEADER_EXCHANGE_TOKEN = "X-DNSimple-OTP-Token"
|
13
|
-
|
14
|
-
class << self
|
15
|
-
# @return [Boolean] if the debug mode is enabled.
|
16
|
-
# Defaults to false.
|
17
|
-
attr_accessor :debug
|
18
|
-
|
19
|
-
attr_accessor :username, :password, :exchange_token, :api_token, :domain_api_token
|
20
|
-
end
|
21
|
-
|
22
|
-
# Gets the qualified API base uri.
|
23
|
-
#
|
24
|
-
# @return [String] The qualified API base uri.
|
25
|
-
def self.base_uri
|
26
|
-
@base_uri ||= DEFAULT_BASE_URI.chomp("/")
|
27
|
-
end
|
28
|
-
|
29
|
-
# Sets the qualified API base uri.
|
30
|
-
#
|
31
|
-
# @param [String] value The qualified API base uri.
|
32
|
-
def self.base_uri=(value)
|
33
|
-
@base_uri = value.to_s.chomp("/")
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.http_proxy
|
37
|
-
@http_proxy
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.load_credentials_if_necessary
|
41
|
-
load_credentials unless credentials_loaded?
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.config_path
|
45
|
-
ENV['DNSIMPLE_CONFIG'] || '~/.dnsimple'
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.load_credentials(path = config_path)
|
49
|
-
begin
|
50
|
-
credentials = YAML.load_file(File.expand_path(path))
|
51
|
-
self.username = credentials['username']
|
52
|
-
self.password = credentials['password']
|
53
|
-
self.exchange_token = credentials['exchange_token']
|
54
|
-
self.api_token = credentials['api_token']
|
55
|
-
self.domain_api_token = credentials['domain_api_token']
|
56
|
-
self.base_uri = credentials['site'] if credentials['site']
|
57
|
-
self.base_uri = credentials['base_uri'] if credentials['base_uri']
|
58
|
-
@http_proxy = { :addr => credentials['proxy_addr'], :port => credentials['proxy_port'] } if credentials['proxy_addr'] || credentials['proxy_port']
|
59
|
-
@credentials_loaded = true
|
60
|
-
puts "Credentials loaded from #{path}"
|
61
|
-
rescue => error
|
62
|
-
puts "Error loading your credentials: #{error.message}"
|
63
|
-
exit 1
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.credentials_loaded?
|
68
|
-
(@credentials_loaded ||= false) or domain_api_token or (username and (password or api_token))
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.base_options
|
72
|
-
options = {
|
73
|
-
:format => :json,
|
74
|
-
:headers => { 'Accept' => 'application/json', 'User-Agent' => "dnsimple-ruby/#{DNSimple::VERSION}" },
|
75
|
-
}
|
76
|
-
|
77
|
-
if http_proxy
|
78
|
-
options.merge!(
|
79
|
-
:http_proxyaddr => http_proxy[:addr],
|
80
|
-
:http_proxyport => http_proxy[:port]
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
if exchange_token
|
85
|
-
options[:basic_auth] = { :username => exchange_token, :password => "x-2fa-basic" }
|
86
|
-
elsif password
|
87
|
-
options[:basic_auth] = { :username => username, :password => password }
|
88
|
-
elsif domain_api_token
|
89
|
-
options[:headers][HEADER_DOMAIN_API_TOKEN] = domain_api_token
|
90
|
-
elsif api_token
|
91
|
-
options[:headers][HEADER_API_TOKEN] = "#{username}:#{api_token}"
|
92
|
-
else
|
93
|
-
raise Error, 'A password or API token is required for all API requests.'
|
94
|
-
end
|
95
|
-
|
96
|
-
options
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.get(path, options = {})
|
100
|
-
request :get, path, options
|
101
|
-
end
|
102
|
-
|
103
|
-
def self.post(path, options = {})
|
104
|
-
request :post, path, options
|
105
|
-
end
|
106
|
-
|
107
|
-
def self.put(path, options = {})
|
108
|
-
request :put, path, options
|
109
|
-
end
|
110
|
-
|
111
|
-
def self.delete(path, options = {})
|
112
|
-
request :delete, path, options
|
113
|
-
end
|
114
|
-
|
115
|
-
def self.request(method, path, options)
|
116
|
-
response = HTTParty.send(method, "#{base_uri}#{path}", base_options.merge(options))
|
117
|
-
|
118
|
-
if response.code == 401 && response.headers[HEADER_OTP_TOKEN] == "required"
|
119
|
-
raise TwoFactorAuthenticationRequired, response["message"]
|
120
|
-
elsif response.code == 401
|
121
|
-
raise AuthenticationFailed, response["message"]
|
122
|
-
end
|
123
|
-
|
124
|
-
response
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
end
|