/
dns.rb
204 lines (195 loc) · 7.92 KB
/
dns.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
require 'fog/digitalocean/core'
require 'active_support/core_ext/hash/indifferent_access'
module Fog
module DNS
class DigitalOcean < Fog::Service
requires :digitalocean_token
model_path 'fog/digitalocean/models/dns'
model :domain
collection :domains
model :record
collection :records
request_path 'fog/digitalocean/requests/dns'
request :list_domains
request :create_domain
request :get_domain
request :delete_domain
request :list_records
request :create_record
request :get_record
request :update_record
request :delete_record
class Mock
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
:domains => [
{
"name" => "domain.com",
"ttl" => 1800,
"zone_file" => "$ORIGIN domain.com.\n$TTL 1800\ndomain.com. IN SOA ns1.digitalocean.com. hostmaster.domain.com. 1490145863 10800 3600 604800 1800\ndomain.com. 1800 IN NS ns1.digitalocean.com.\ndomain.com. 1800 IN NS ns2.digitalocean.com.\ndomain.com. 1800 IN NS ns3.digitalocean.com.\ndomain.com. 1800 IN A 127.0.0.3\n"
},
{
"name" => "domain.net",
"ttl" => 1800,
"zone_file" => "$ORIGIN domain.net.\n$TTL 1800\ndomain.net. IN SOA ns1.digitalocean.com. hostmaster.domain.net. 1488909707 10800 3600 604800 1800\ndomain.net. 1800 IN NS ns1.digitalocean.com.\ndomain.net. 1800 IN NS ns2.digitalocean.com.\ndomain.net. 1800 IN NS ns3.digitalocean.com.\ndomain.net. 1800 IN A 64.99.64.37\n"
},
{
"name" => "domain.org",
"ttl" => 1800,
"zone_file" => "$ORIGIN domain.org.\n$TTL 1800\ndomain.org. IN SOA ns1.digitalocean.com. hostmaster.domain.org. 1488395060 10800 3600 604800 1800\ndomain.org. 1800 IN NS ns1.digitalocean.com.\ndomain.org. 1800 IN NS ns2.digitalocean.com.\ndomain.org. 1800 IN NS ns3.digitalocean.com.\ndomain.org. 3600 IN A 208.38.128.210\ndomain.org. 1800 IN MX 1 aspmx.l.google.com.\ndomain.org. 1800 IN MX 5 alt1.aspmx.l.google.com.\ndomain.org. 1800 IN MX 5 alt2.aspmx.l.google.com.\ndomain.org. 1800 IN MX 10 alt3.aspmx.l.google.com.\ndomain.org. 1800 IN MX 10 alt4.aspmx.l.google.com.\n"
}
],
:domain_records => {
'domain.com' =>
[
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns1.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns2.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns3.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "A",
"name" => "@",
"data" => "127.0.0.1",
"priority" => nil,
"port" => nil,
"weight" => nil
}
],
'domain.net' =>
[
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns1.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns2.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns3.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "A",
"name" => "@",
"data" => "127.0.0.1",
"priority" => nil,
"port" => nil,
"weight" => nil
}
],
'domain.org' =>
[
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns1.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns2.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "NS",
"name" => "@",
"data" => "ns3.digitalocean.com",
"priority" => nil,
"port" => nil,
"weight" => nil
},
{ "id" => Fog::Mock.random_numbers(8).to_i,
"type" => "A",
"name" => "@",
"data" => "127.0.0.1",
"priority" => nil,
"port" => nil,
"weight" => nil
}
],
}
}
end
end
def initialize(options={})
@digitalocean_token = options[:digitalocean_token]
end
def data
self.class.data[@digitalocean_token]
end
def reset_data
self.class.data.delete(@digitalocean_token)
end
end
class Real < Fog::Compute::DigitalOcean::Real
# def initialize(options={})
# digitalocean_token = options[:digitalocean_token]
# persistent = false
# options = {
# headers: {
# 'Authorization' => "Bearer #{digitalocean_token}",
# }
# }
# @connection = Fog::Core::Connection.new 'https://api.digitalocean.com', persistent, options
# end
#
# def request(params)
# params[:headers] ||= {}
# begin
# response = @connection.request(params)
# rescue Excon::Errors::HTTPStatusError => error
# raise case error
# when Excon::Errors::NotFound
# NotFound.slurp(error)
# else
# error
# end
# end
# unless response.body.empty?
# response.body = Fog::JSON.decode(response.body)
# end
# response
# end
end
end
end
end