dnsimple-ruby 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/VERSION +1 -1
- data/bin/dnsimple.rb +3 -1
- data/lib/dnsimple/certificate.rb +62 -5
- data/lib/dnsimple/cli.rb +7 -1
- data/lib/dnsimple/commands/describe_certificate.rb +33 -0
- data/lib/dnsimple/commands/list_certificates.rb +15 -0
- data/lib/dnsimple/commands/purchase_certificate.rb +6 -2
- data/lib/dnsimple/error.rb +15 -1
- data/lib/dnsimple/user.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- metadata +7 -5
data/README
CHANGED
@@ -58,7 +58,7 @@ The following commands are available for managing contacts:
|
|
58
58
|
|
59
59
|
The following commands are available for purchasing certificates:
|
60
60
|
|
61
|
-
* dnsimple certificate:purchase domain.com name
|
61
|
+
* dnsimple certificate:purchase domain.com name contact_id
|
62
62
|
* dnsimple certificate:submit id
|
63
63
|
|
64
64
|
The contact name/value pairs are:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/bin/dnsimple.rb
CHANGED
@@ -80,7 +80,9 @@ service:available domain.com # List all of the se
|
|
80
80
|
service:add domain.com short_name # Add the service to the domain
|
81
81
|
service:remove domain.com short_name # Remove the service from the domain
|
82
82
|
|
83
|
-
certificate:
|
83
|
+
certificate:list domain.com # List all certificates for a domain
|
84
|
+
certificate:describe domain.com id # Get a specific certificate for a domain
|
85
|
+
certificate:purchase domain.com name contact_id # Purchase a certificate
|
84
86
|
certificate:submit domain.com id approver_email # Submit a certificate for processing
|
85
87
|
|
86
88
|
Please see the DNSimple documentation at https://dnsimple.com/documentation/api for additional
|
data/lib/dnsimple/certificate.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
module DNSimple #:nodoc:
|
2
|
+
# Represents an SSL certificate that has been purchased. The certificate
|
3
|
+
# must also be submitted using the #submit method before the Certificate
|
4
|
+
# Authority will issue a signed certificate.
|
2
5
|
class Certificate
|
3
6
|
include HTTParty
|
4
7
|
#debug_output $stdout
|
@@ -10,6 +13,30 @@ module DNSimple #:nodoc:
|
|
10
13
|
|
11
14
|
# The subdomain on the certificate
|
12
15
|
attr_accessor :name
|
16
|
+
|
17
|
+
# The private key, if DNSimple generated the Certificate Signing Request
|
18
|
+
attr_accessor :private_key
|
19
|
+
|
20
|
+
# The SSL certificate, if it has been issued by the Certificate Authority
|
21
|
+
attr_accessor :ssl_certificate
|
22
|
+
|
23
|
+
# The Certificate Signing Request
|
24
|
+
attr_accessor :csr
|
25
|
+
|
26
|
+
# The Certificate status
|
27
|
+
attr_accessor :certificate_status
|
28
|
+
|
29
|
+
# The date the Certificate order was placed
|
30
|
+
attr_accessor :order_date
|
31
|
+
|
32
|
+
# The date the Certificate will expire
|
33
|
+
attr_accessor :expiration_date
|
34
|
+
|
35
|
+
# The approver email address
|
36
|
+
attr_accessor :approver_email
|
37
|
+
|
38
|
+
# An array of all emails that can be used to approve the certificate
|
39
|
+
attr_accessor :available_approver_emails
|
13
40
|
|
14
41
|
# When the certificate was purchased
|
15
42
|
attr_accessor :created_at
|
@@ -17,6 +44,8 @@ module DNSimple #:nodoc:
|
|
17
44
|
# When the certificate was last updated
|
18
45
|
attr_accessor :updated_at
|
19
46
|
|
47
|
+
|
48
|
+
|
20
49
|
#:nodoc:
|
21
50
|
def initialize(attributes)
|
22
51
|
attributes.each do |key, value|
|
@@ -32,6 +61,8 @@ module DNSimple #:nodoc:
|
|
32
61
|
end
|
33
62
|
|
34
63
|
def submit(approver_email, options={})
|
64
|
+
raise DNSimple::Error, "Approver email is required" unless approver_email
|
65
|
+
|
35
66
|
options.merge!(DNSimple::Client.standard_options_with_credentials)
|
36
67
|
options.merge!(:body => {:certificate => {:approver_email => approver_email}})
|
37
68
|
|
@@ -43,9 +74,9 @@ module DNSimple #:nodoc:
|
|
43
74
|
when 200
|
44
75
|
return DNSimple::Certificate.new({:domain => domain}.merge(response["certificate"]))
|
45
76
|
when 401
|
46
|
-
raise
|
77
|
+
raise DNSimple::AuthenticationFailed, "Authentication failed"
|
47
78
|
else
|
48
|
-
raise DNSimple::Error.new("#{
|
79
|
+
raise DNSimple::Error.new("Error submitting certificate: #{response["errors"]}")
|
49
80
|
end
|
50
81
|
end
|
51
82
|
|
@@ -54,6 +85,13 @@ module DNSimple #:nodoc:
|
|
54
85
|
# subdomain part.
|
55
86
|
#
|
56
87
|
# Example: DNSimple::Certificate.purchase(domain, 'www', contact)
|
88
|
+
#
|
89
|
+
# Please note that by invoking this method DNSimple will immediately charge
|
90
|
+
# your credit card on file at DNSimple for the full certificate price.
|
91
|
+
#
|
92
|
+
# For wildcard certificates an asterisk must appear in the name.
|
93
|
+
#
|
94
|
+
# Example: DNSimple::Certificate.purchase(domain, '*', contact)
|
57
95
|
def self.purchase(domain, name, contact, options={})
|
58
96
|
certificate_hash = {
|
59
97
|
:name => name,
|
@@ -71,7 +109,7 @@ module DNSimple #:nodoc:
|
|
71
109
|
when 201
|
72
110
|
return DNSimple::Certificate.new({:domain => domain}.merge(response["certificate"]))
|
73
111
|
when 401
|
74
|
-
raise
|
112
|
+
raise DNSimple::AuthenticationFailed, "Authentication failed"
|
75
113
|
when 406
|
76
114
|
raise DNSimple::CertificateExists.new("#{name}.#{domain.name}", response["errors"])
|
77
115
|
else
|
@@ -91,11 +129,30 @@ module DNSimple #:nodoc:
|
|
91
129
|
when 200
|
92
130
|
response.map { |r| DNSimple::Certificate.new({:domain => domain}.merge(r["certificate"])) }
|
93
131
|
when 401
|
94
|
-
raise
|
132
|
+
raise DNSimple::AuthenticationFailed, "Authentication failed"
|
95
133
|
else
|
96
|
-
raise DNSimple::Error.new("
|
134
|
+
raise DNSimple::Error.new("List certificates error: #{response["errors"]}")
|
97
135
|
end
|
98
136
|
end
|
99
137
|
|
138
|
+
# Find a specific certificate for the given domain.
|
139
|
+
def self.find(domain, certificate_id, options={})
|
140
|
+
options.merge!(DNSimple::Client.standard_options_with_credentials)
|
141
|
+
|
142
|
+
response = self.get("#{DNSimple::Client.base_uri}/domains/#{domain.name}/certificates/#{certificate_id}", options)
|
143
|
+
|
144
|
+
pp response if DNSimple::Client.debug?
|
145
|
+
|
146
|
+
case response.code
|
147
|
+
when 200
|
148
|
+
DNSimple::Certificate.new({:domain => domain}.merge(response["certificate"]))
|
149
|
+
when 401
|
150
|
+
raise DNSimple::AuthenticationFailed, "Authentication failed"
|
151
|
+
when 404
|
152
|
+
raise DNSimple::CertificateNotFound, "Could not find certificate #{certificate_id} for domain #{domain.name}"
|
153
|
+
else
|
154
|
+
raise DNSimple::Error.new("Find certificate error: #{response["errors"]}")
|
155
|
+
end
|
156
|
+
end
|
100
157
|
end
|
101
158
|
end
|
data/lib/dnsimple/cli.rb
CHANGED
@@ -67,7 +67,10 @@ module DNSimple
|
|
67
67
|
'service:add' => DNSimple::Commands::AddService,
|
68
68
|
'service:remove' => DNSimple::Commands::RemoveService,
|
69
69
|
|
70
|
-
'certificate:
|
70
|
+
'certificate:list' => DNSimple::Commands::ListCertificates,
|
71
|
+
'certificate:describe' => DNSimple::Commands::DescribeCertificate,
|
72
|
+
'certificate:purchase' => DNSimple::Commands::PurchaseCertificate,
|
73
|
+
'certificate:submit' => DNSimple::Commands::SubmitCertificate
|
71
74
|
}
|
72
75
|
end
|
73
76
|
end
|
@@ -113,4 +116,7 @@ require 'dnsimple/commands/list_applied_services'
|
|
113
116
|
require 'dnsimple/commands/add_service'
|
114
117
|
require 'dnsimple/commands/remove_service'
|
115
118
|
|
119
|
+
require 'dnsimple/commands/list_certificates'
|
120
|
+
require 'dnsimple/commands/describe_certificate'
|
116
121
|
require 'dnsimple/commands/purchase_certificate'
|
122
|
+
require 'dnsimple/commands/submit_certificate'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class DescribeCertificate
|
4
|
+
def execute(args, options={})
|
5
|
+
domain_name = args.shift
|
6
|
+
certificate_id = args.shift
|
7
|
+
domain = Domain.find(domain_name)
|
8
|
+
certificate = Certificate.find(domain, certificate_id)
|
9
|
+
puts "Certificate: #{certificate.fqdn}"
|
10
|
+
puts "\tID: #{certificate.id}"
|
11
|
+
puts "\tStatus: #{certificate.certificate_status}"
|
12
|
+
puts "\tCreated: #{certificate.created_at}"
|
13
|
+
puts "\tOrder Date: #{certificate.order_date}"
|
14
|
+
puts "\tExpires: #{certificate.expiration_date}"
|
15
|
+
|
16
|
+
if certificate.approver_email =~ /\S+/
|
17
|
+
puts "\tApprover email: #{certificate.approver_email}"
|
18
|
+
else
|
19
|
+
puts "\tAvailable approver emails:"
|
20
|
+
certificate.available_approver_emails.split(",").each do |email|
|
21
|
+
puts "\t\t#{email}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
puts
|
26
|
+
puts "#{certificate.csr}"
|
27
|
+
puts
|
28
|
+
puts "#{certificate.private_key}"
|
29
|
+
puts
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DNSimple
|
2
|
+
module Commands
|
3
|
+
class ListCertificates
|
4
|
+
def execute(args, options={})
|
5
|
+
domain_name = args.shift
|
6
|
+
domain = DNSimple::Domain.find(domain_name)
|
7
|
+
certificates = DNSimple::Certificate.all(domain)
|
8
|
+
puts "Found #{certificates.length} certificate for #{domain_name}"
|
9
|
+
certificates.each do |certificate|
|
10
|
+
puts "\t#{certificate.fqdn} (id: #{certificate.id}, status: #{certificate.certificate_status})"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -5,9 +5,13 @@ module DNSimple
|
|
5
5
|
class PurchaseCertificate < Command
|
6
6
|
def execute(args, options={})
|
7
7
|
domain_name = args.shift
|
8
|
-
name = args.
|
8
|
+
name = args.shift
|
9
|
+
contact_id = args.shift
|
10
|
+
|
11
|
+
domain = Domain.find(domain_name)
|
12
|
+
contact = Contact.find(contact_id)
|
9
13
|
|
10
|
-
certificate = Certificate.purchase(
|
14
|
+
certificate = Certificate.purchase(domain, name, contact)
|
11
15
|
say "Purchased certificate for #{certificate.fqdn}"
|
12
16
|
end
|
13
17
|
end
|
data/lib/dnsimple/error.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
module DNSimple
|
2
2
|
class Error < StandardError
|
3
|
+
def initialize(message)
|
4
|
+
super(message)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class DomainError < DNSimple::Error
|
3
9
|
def initialize(domain, messages)
|
4
10
|
@domain = domain
|
5
11
|
@messages = messages
|
@@ -7,5 +13,13 @@ module DNSimple
|
|
7
13
|
end
|
8
14
|
end
|
9
15
|
|
10
|
-
class RecordExists <
|
16
|
+
class RecordExists < DomainError; end
|
17
|
+
|
18
|
+
class AuthenticationFailed < DNSimple::Error; end
|
19
|
+
|
20
|
+
class UserNotFound < DNSimple::Error; end
|
21
|
+
|
22
|
+
class CertificateExists < DNSimple::Error; end
|
23
|
+
|
24
|
+
class CertificateNotFound < DNSimple::Error; end
|
11
25
|
end
|
data/lib/dnsimple/user.rb
CHANGED
@@ -33,11 +33,11 @@ module DNSimple
|
|
33
33
|
when 200
|
34
34
|
return User.new(response["user"])
|
35
35
|
when 401
|
36
|
-
raise
|
36
|
+
raise DNSimple::AuthenticationFailed, "Authentication failed"
|
37
37
|
when 404
|
38
|
-
raise
|
38
|
+
raise DNSimple::UserNotFound, "Could not find user"
|
39
39
|
else
|
40
|
-
raise
|
40
|
+
raise DNSimple::Error, "Error: #{response.code} #{response.message}"
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,7 +14,7 @@ RSpec.configure do |c|
|
|
14
14
|
c.extend VCR::RSpec::Macros
|
15
15
|
end
|
16
16
|
|
17
|
-
config = YAML.load(File.new(File.expand_path('~/.dnsimple.
|
17
|
+
config = YAML.load(File.new(File.expand_path('~/.dnsimple.local')))
|
18
18
|
|
19
19
|
DNSimple::Client.base_uri = config['site'] || "https://test.dnsimple.com/"
|
20
20
|
DNSimple::Client.username = config['username']
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dnsimple-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Anthony Eden
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|
@@ -267,6 +267,7 @@ files:
|
|
267
267
|
- lib/dnsimple/commands/delete_record.rb
|
268
268
|
- lib/dnsimple/commands/delete_template.rb
|
269
269
|
- lib/dnsimple/commands/delete_template_record.rb
|
270
|
+
- lib/dnsimple/commands/describe_certificate.rb
|
270
271
|
- lib/dnsimple/commands/describe_contact.rb
|
271
272
|
- lib/dnsimple/commands/describe_domain.rb
|
272
273
|
- lib/dnsimple/commands/describe_record.rb
|
@@ -274,6 +275,7 @@ files:
|
|
274
275
|
- lib/dnsimple/commands/describe_user.rb
|
275
276
|
- lib/dnsimple/commands/list_applied_services.rb
|
276
277
|
- lib/dnsimple/commands/list_available_services.rb
|
278
|
+
- lib/dnsimple/commands/list_certificates.rb
|
277
279
|
- lib/dnsimple/commands/list_contacts.rb
|
278
280
|
- lib/dnsimple/commands/list_domains.rb
|
279
281
|
- lib/dnsimple/commands/list_extended_attributes.rb
|