fog-dnsimple 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-gemset +1 -0
- data/.travis.yml +15 -2
- data/CHANGELOG.md +5 -0
- data/LICENSE.md +20 -0
- data/README.md +55 -12
- data/Rakefile +6 -0
- data/fog-dnsimple.gemspec +10 -2
- data/lib/fog/bin/dnsimple.rb +28 -0
- data/lib/fog/dnsimple.rb +9 -2
- data/lib/fog/dnsimple/dns.rb +118 -0
- data/lib/fog/dnsimple/models/dns/record.rb +59 -0
- data/lib/fog/dnsimple/models/dns/records.rb +34 -0
- data/lib/fog/dnsimple/models/dns/zone.rb +46 -0
- data/lib/fog/dnsimple/models/dns/zones.rb +25 -0
- data/lib/fog/dnsimple/requests/dns/create_domain.rb +62 -0
- data/lib/fog/dnsimple/requests/dns/create_record.rb +67 -0
- data/lib/fog/dnsimple/requests/dns/delete_domain.rb +35 -0
- data/lib/fog/dnsimple/requests/dns/delete_record.rb +30 -0
- data/lib/fog/dnsimple/requests/dns/get_domain.rb +39 -0
- data/lib/fog/dnsimple/requests/dns/get_record.rb +49 -0
- data/lib/fog/dnsimple/requests/dns/list_domains.rb +34 -0
- data/lib/fog/dnsimple/requests/dns/list_records.rb +34 -0
- data/lib/fog/dnsimple/requests/dns/update_record.rb +53 -0
- data/lib/fog/dnsimple/version.rb +1 -1
- data/tests/dns/helper.rb +19 -0
- data/tests/dns/models/record_tests.rb +41 -0
- data/tests/dns/models/records_tests.rb +27 -0
- data/tests/dns/models/zone_tests.rb +15 -0
- data/tests/dns/models/zones_tests.rb +15 -0
- data/tests/helper.rb +11 -0
- data/tests/helpers/mock_helper.rb +6 -0
- data/tests/requests/dns/dns_tests.rb +122 -0
- metadata +101 -7
- data/.rspec +0 -2
- data/CODE_OF_CONDUCT.md +0 -49
- data/LICENSE.txt +0 -21
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'fog/core/model'
|
2
|
+
require 'fog/dnsimple/models/dns/records'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module DNS
|
6
|
+
class Dnsimple
|
7
|
+
class Zone < Fog::Model
|
8
|
+
identity :id
|
9
|
+
|
10
|
+
attribute :domain, :aliases => 'name'
|
11
|
+
attribute :created_at
|
12
|
+
attribute :updated_at
|
13
|
+
|
14
|
+
def destroy
|
15
|
+
service.delete_domain(identity)
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def records
|
20
|
+
@records ||= begin
|
21
|
+
Fog::DNS::Dnsimple::Records.new(
|
22
|
+
:zone => self,
|
23
|
+
:service => service
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def nameservers
|
29
|
+
%w(
|
30
|
+
ns1.dnsimple.com
|
31
|
+
ns2.dnsimple.com
|
32
|
+
ns3.dnsimple.com
|
33
|
+
ns4.dnsimple.com
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def save
|
38
|
+
requires :domain
|
39
|
+
data = service.create_domain(domain).body["domain"]
|
40
|
+
merge_attributes(data)
|
41
|
+
true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'fog/core/collection'
|
2
|
+
require 'fog/dnsimple/models/dns/zone'
|
3
|
+
|
4
|
+
module Fog
|
5
|
+
module DNS
|
6
|
+
class Dnsimple
|
7
|
+
class Zones < Fog::Collection
|
8
|
+
model Fog::DNS::Dnsimple::Zone
|
9
|
+
|
10
|
+
def all
|
11
|
+
clear
|
12
|
+
data = service.list_domains.body.map {|zone| zone['domain']}
|
13
|
+
load(data)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(zone_id)
|
17
|
+
data = service.get_domain(zone_id).body['domain']
|
18
|
+
new(data)
|
19
|
+
rescue Excon::Errors::NotFound
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Create a single domain in DNSimple in your account.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * name<~String> - domain name to host (ie example.com)
|
9
|
+
#
|
10
|
+
# ==== Returns
|
11
|
+
# * response<~Excon::Response>:
|
12
|
+
# * body<~Hash>:
|
13
|
+
# * 'domain'<~Hash> The representation of the domain.
|
14
|
+
def create_domain(name)
|
15
|
+
body = {
|
16
|
+
"domain" => {
|
17
|
+
"name" => name
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
request(
|
22
|
+
:body => Fog::JSON.encode(body),
|
23
|
+
:expects => 201,
|
24
|
+
:method => 'POST',
|
25
|
+
:path => "/domains"
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Mock
|
31
|
+
def create_domain(name)
|
32
|
+
body = {
|
33
|
+
"domain" => {
|
34
|
+
"id" => Fog::Mock.random_numbers(1).to_i,
|
35
|
+
"user_id" => 1,
|
36
|
+
"registrant_id" => nil,
|
37
|
+
"name" => name,
|
38
|
+
"unicode_name" => name,
|
39
|
+
"token" => "4fIFYWYiJayvL2tkf_mkBkqC4L+4RtYqDA",
|
40
|
+
"state" => "registered",
|
41
|
+
"language" => nil,
|
42
|
+
"lockable" => true,
|
43
|
+
"auto_renew" => nil,
|
44
|
+
"whois_protected" => false,
|
45
|
+
"record_count" => 0,
|
46
|
+
"service_count" => 0,
|
47
|
+
"expires_on" => Date.today + 365,
|
48
|
+
"created_at" => Time.now.iso8601,
|
49
|
+
"updated_at" => Time.now.iso8601,
|
50
|
+
}
|
51
|
+
}
|
52
|
+
self.data[:domains] << body
|
53
|
+
|
54
|
+
response = Excon::Response.new
|
55
|
+
response.status = 201
|
56
|
+
response.body = body
|
57
|
+
response
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Create a new host in the specified zone
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * domain<~String> - domain name or numeric ID
|
9
|
+
# * name<~String>
|
10
|
+
# * type<~String>
|
11
|
+
# * content<~String>
|
12
|
+
# * options<~Hash> - optional
|
13
|
+
# * priority<~Integer>
|
14
|
+
# * ttl<~Integer>
|
15
|
+
#
|
16
|
+
# ==== Returns
|
17
|
+
# * response<~Excon::Response>:
|
18
|
+
# * body<~Hash>:
|
19
|
+
# * 'record'<~Hash> The representation of the record.
|
20
|
+
def create_record(domain, name, type, content, options = {})
|
21
|
+
body = {
|
22
|
+
"record" => {
|
23
|
+
"name" => name,
|
24
|
+
"record_type" => type,
|
25
|
+
"content" => content
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
body["record"].merge!(options)
|
30
|
+
|
31
|
+
request(
|
32
|
+
:body => Fog::JSON.encode(body),
|
33
|
+
:expects => 201,
|
34
|
+
:method => 'POST',
|
35
|
+
:path => "/domains/#{domain}/records"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Mock
|
41
|
+
def create_record(domain, name, type, content, options = {})
|
42
|
+
body = {
|
43
|
+
"record" => {
|
44
|
+
"id" => Fog::Mock.random_numbers(1).to_i,
|
45
|
+
"domain_id" => domain,
|
46
|
+
"name" => name,
|
47
|
+
"content" => content,
|
48
|
+
"ttl" => 3600,
|
49
|
+
"prio" => nil,
|
50
|
+
"record_type" => type,
|
51
|
+
"system_record" => nil,
|
52
|
+
"created_at" => Time.now.iso8601,
|
53
|
+
"updated_at" => Time.now.iso8601,
|
54
|
+
}.merge(options)
|
55
|
+
}
|
56
|
+
self.data[:records][domain] ||= []
|
57
|
+
self.data[:records][domain] << body
|
58
|
+
|
59
|
+
response = Excon::Response.new
|
60
|
+
response.status = 201
|
61
|
+
response.body = body
|
62
|
+
response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Delete the given domain from your account. You may use
|
6
|
+
# either the domain ID or the domain name.
|
7
|
+
#
|
8
|
+
# Please note that for domains which are registered with
|
9
|
+
# DNSimple this will not delete the domain from the registry.
|
10
|
+
#
|
11
|
+
# ==== Parameters
|
12
|
+
# * domain<~String> - domain name or numeric ID
|
13
|
+
#
|
14
|
+
def delete_domain(domain)
|
15
|
+
request(
|
16
|
+
:expects => 200,
|
17
|
+
:method => 'DELETE',
|
18
|
+
:path => "/domains/#{domain}"
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Mock
|
24
|
+
def delete_domain(name)
|
25
|
+
self.data[:records].delete name
|
26
|
+
self.data[:domains].reject! { |domain| domain["domain"]["name"] == name }
|
27
|
+
|
28
|
+
response = Excon::Response.new
|
29
|
+
response.status = 200
|
30
|
+
response
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Delete the record with the given ID for the given domain.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * domain<~String> - domain name or numeric ID
|
9
|
+
# * record_id<~String>
|
10
|
+
def delete_record(domain, record_id)
|
11
|
+
request(
|
12
|
+
:expects => 200,
|
13
|
+
:method => "DELETE",
|
14
|
+
:path => "/domains/#{domain}/records/#{record_id}"
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Mock
|
20
|
+
def delete_record(domain, record_id)
|
21
|
+
self.data[:records][domain].reject! { |record| record["record"]["id"] == record_id }
|
22
|
+
|
23
|
+
response = Excon::Response.new
|
24
|
+
response.status = 200
|
25
|
+
response
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Get the details for a specific domain in your account. You
|
6
|
+
# may pass either the domain numeric ID or the domain name
|
7
|
+
# itself.
|
8
|
+
#
|
9
|
+
# ==== Parameters
|
10
|
+
# * domain<~String> - domain name or numeric ID
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Excon::Response>:
|
14
|
+
# * body<~Hash>:
|
15
|
+
# * 'domain'<~Hash> The representation of the domain.
|
16
|
+
def get_domain(domain)
|
17
|
+
request(
|
18
|
+
:expects => 200,
|
19
|
+
:method => "GET",
|
20
|
+
:path => "/domains/#{domain}"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Mock
|
26
|
+
def get_domain(id)
|
27
|
+
domain = self.data[:domains].find do |domain|
|
28
|
+
domain["domain"]["id"] == id || domain["domain"]["name"] == id
|
29
|
+
end
|
30
|
+
|
31
|
+
response = Excon::Response.new
|
32
|
+
response.status = 200
|
33
|
+
response.body = domain
|
34
|
+
response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Gets record from given domain.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * domain<~String> - domain name or numeric ID
|
9
|
+
# * record_id<~String>
|
10
|
+
#
|
11
|
+
# ==== Returns
|
12
|
+
# * response<~Excon::Response>:
|
13
|
+
# * body<~Hash>:
|
14
|
+
# * 'record'<~Hash> The representation of the record.
|
15
|
+
def get_record(domain, record_id)
|
16
|
+
request(
|
17
|
+
:expects => 200,
|
18
|
+
:method => "GET",
|
19
|
+
:path => "/domains/#{domain}/records/#{record_id}"
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Mock
|
25
|
+
def get_record(domain, record_id)
|
26
|
+
response = Excon::Response.new
|
27
|
+
|
28
|
+
if self.data[:records].key?(domain)
|
29
|
+
response.status = 200
|
30
|
+
response.body = self.data[:records][domain].find { |record| record["record"]["id"] == record_id }
|
31
|
+
|
32
|
+
if response.body.nil?
|
33
|
+
response.status = 404
|
34
|
+
response.body = {
|
35
|
+
"error" => "Couldn't find Record with id = #{record_id}"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
else
|
39
|
+
response.status = 404
|
40
|
+
response.body = {
|
41
|
+
"error" => "Couldn't find Domain with name = #{domain}"
|
42
|
+
}
|
43
|
+
end
|
44
|
+
response
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Get the details for a specific domain in your account. You
|
6
|
+
# may pass either the domain numeric ID or the domain name itself.
|
7
|
+
#
|
8
|
+
# ==== Parameters
|
9
|
+
#
|
10
|
+
# ==== Returns
|
11
|
+
# * response<~Excon::Response>:
|
12
|
+
# * body<~Hash>:
|
13
|
+
# * <~Array>:
|
14
|
+
# * 'domain'<~Hash> The representation of the domain.
|
15
|
+
def list_domains
|
16
|
+
request(
|
17
|
+
:expects => 200,
|
18
|
+
:method => 'GET',
|
19
|
+
:path => '/domains'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Mock
|
25
|
+
def list_domains
|
26
|
+
response = Excon::Response.new
|
27
|
+
response.status = 200
|
28
|
+
response.body = self.data[:domains]
|
29
|
+
response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Get the list of records for the specific domain.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * domain<~String> - domain name or numeric ID
|
9
|
+
#
|
10
|
+
# ==== Returns
|
11
|
+
# * response<~Excon::Response>:
|
12
|
+
# * body<~Hash>:
|
13
|
+
# * <~Array>:
|
14
|
+
# * 'record'<~Hash> The representation of the record.
|
15
|
+
def list_records(domain)
|
16
|
+
request(
|
17
|
+
:expects => 200,
|
18
|
+
:method => "GET",
|
19
|
+
:path => "/domains/#{domain}/records"
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Mock
|
25
|
+
def list_records(domain)
|
26
|
+
response = Excon::Response.new
|
27
|
+
response.status = 200
|
28
|
+
response.body = self.data[:records][domain] || []
|
29
|
+
response
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Fog
|
2
|
+
module DNS
|
3
|
+
class Dnsimple
|
4
|
+
class Real
|
5
|
+
# Update the given record for the given domain.
|
6
|
+
#
|
7
|
+
# ==== Parameters
|
8
|
+
# * domain<~String> - domain name or numeric ID
|
9
|
+
# * record_id<~String>
|
10
|
+
# * options<~Hash> - optional
|
11
|
+
# * type<~String>
|
12
|
+
# * content<~String>
|
13
|
+
# * priority<~Integer>
|
14
|
+
# * ttl<~Integer>
|
15
|
+
#
|
16
|
+
# ==== Returns
|
17
|
+
# * response<~Excon::Response>:
|
18
|
+
# * body<~Hash>:
|
19
|
+
# * 'record'<~Hash> The representation of the record.
|
20
|
+
def update_record(domain, record_id, options)
|
21
|
+
body = {
|
22
|
+
"record" => options
|
23
|
+
}
|
24
|
+
|
25
|
+
request(
|
26
|
+
:body => Fog::JSON.encode(body),
|
27
|
+
:expects => 200,
|
28
|
+
:method => "PUT",
|
29
|
+
:path => "/domains/#{domain}/records/#{record_id}"
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Mock
|
35
|
+
def update_record(domain, record_id, options)
|
36
|
+
record = self.data[:records][domain].find { |record| record["record"]["id"] == record_id }
|
37
|
+
response = Excon::Response.new
|
38
|
+
|
39
|
+
if record.nil?
|
40
|
+
response.status = 400
|
41
|
+
else
|
42
|
+
response.status = 200
|
43
|
+
record["record"].merge!(options)
|
44
|
+
record["record"]["updated_at"] = Time.now.iso8601
|
45
|
+
response.body = record
|
46
|
+
end
|
47
|
+
|
48
|
+
response
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|