fog-dynect 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +15 -0
  4. data/CHANGELOG.md +3 -0
  5. data/CONTRIBUTING.md +18 -0
  6. data/CONTRIBUTORS.md +27 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.md +20 -0
  9. data/README.md +58 -0
  10. data/Rakefile +8 -0
  11. data/fog-dynect.gemspec +29 -0
  12. data/gemfiles/Gemfile-1.8.7 +6 -0
  13. data/lib/fog/dynect.rb +1 -0
  14. data/lib/fog/dynect/core.rb +27 -0
  15. data/lib/fog/dynect/dns.rb +157 -0
  16. data/lib/fog/dynect/models/dns/record.rb +67 -0
  17. data/lib/fog/dynect/models/dns/records.rb +48 -0
  18. data/lib/fog/dynect/models/dns/zone.rb +56 -0
  19. data/lib/fog/dynect/models/dns/zones.rb +25 -0
  20. data/lib/fog/dynect/requests/dns/delete_record.rb +55 -0
  21. data/lib/fog/dynect/requests/dns/delete_zone.rb +41 -0
  22. data/lib/fog/dynect/requests/dns/get_all_records.rb +56 -0
  23. data/lib/fog/dynect/requests/dns/get_node_list.rb +55 -0
  24. data/lib/fog/dynect/requests/dns/get_record.rb +83 -0
  25. data/lib/fog/dynect/requests/dns/get_zone.rb +57 -0
  26. data/lib/fog/dynect/requests/dns/post_record.rb +71 -0
  27. data/lib/fog/dynect/requests/dns/post_session.rb +43 -0
  28. data/lib/fog/dynect/requests/dns/post_zone.rb +70 -0
  29. data/lib/fog/dynect/requests/dns/put_record.rb +76 -0
  30. data/lib/fog/dynect/requests/dns/put_zone.rb +76 -0
  31. data/lib/fog/dynect/version.rb +5 -0
  32. data/tests/dns/helper.rb +22 -0
  33. data/tests/dns/models/record_tests.rb +44 -0
  34. data/tests/dns/models/records_tests.rb +30 -0
  35. data/tests/dns/models/zone_tests.rb +18 -0
  36. data/tests/dns/models/zones_tests.rb +18 -0
  37. data/tests/dynect/requests/dns/dns_tests.rb +258 -0
  38. data/tests/helper.rb +13 -0
  39. metadata +168 -0
@@ -0,0 +1,18 @@
1
+ for provider, config in dns_providers
2
+
3
+ # FIXME: delay/timing breaks things :(
4
+ next if [:dnsmadeeasy, :rage4].include?(provider)
5
+
6
+ domain_name = uniq_id + '.com'
7
+
8
+ Shindo.tests("Fog::DNS[:#{provider}] | zone", [provider.to_s]) do
9
+
10
+ zone_attributes = {
11
+ :domain => domain_name
12
+ }.merge!(config[:zone_attributes] || {})
13
+
14
+ model_tests(Fog::DNS[provider].zones, zone_attributes, config[:mocked])
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,18 @@
1
+ for provider, config in dns_providers
2
+
3
+ # FIXME: delay/timing breaks things :(
4
+ next if [:dnsmadeeasy, :rage4].include?(provider)
5
+
6
+ domain_name = uniq_id + '.com'
7
+
8
+ Shindo.tests("Fog::DNS[:#{provider}] | zones", [provider.to_s]) do
9
+
10
+ zone_attributes = {
11
+ :domain => domain_name
12
+ }.merge!(config[:zone_attributes] || {})
13
+
14
+ collection_tests(Fog::DNS[provider].zones, zone_attributes, config[:mocked])
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,258 @@
1
+ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
2
+
3
+ shared_format = {
4
+ 'job_id' => Integer,
5
+ 'msgs' => [{
6
+ 'ERR_CD' => Fog::Nullable::String,
7
+ 'INFO' => String,
8
+ 'LVL' => String,
9
+ 'SOURCE' => String
10
+ }],
11
+ 'status' => String
12
+ }
13
+
14
+ tests "success" do
15
+
16
+ @dns = Fog::DNS[:dynect]
17
+ @domain = generate_unique_domain
18
+ @fqdn = "www.#{@domain}"
19
+
20
+ post_session_format = shared_format.merge({
21
+ 'data' => {
22
+ 'token' => String,
23
+ 'version' => String
24
+ }
25
+ })
26
+
27
+ tests("post_session").formats(post_session_format) do
28
+ @dns.post_session.body
29
+ end
30
+
31
+ post_zone_format = shared_format.merge({
32
+ 'data' => {
33
+ 'serial' => Integer,
34
+ 'zone' => String,
35
+ 'zone_type' => String,
36
+ 'serial_style' => String
37
+ }
38
+ })
39
+
40
+ tests("post_zone('netops@#{@domain}', 3600, '#{@domain}')").formats(post_zone_format) do
41
+ @dns.post_zone("netops@#{@domain}", 3600, @domain).body
42
+ end
43
+
44
+ get_zones_format = shared_format.merge({
45
+ 'data' => [String]
46
+ })
47
+
48
+ tests("get_zone").formats(get_zones_format) do
49
+ @dns.get_zone.body
50
+ end
51
+
52
+ get_zone_format = shared_format.merge({
53
+ 'data' => {
54
+ "serial" => Integer,
55
+ "serial_style" => String,
56
+ "zone" => String,
57
+ "zone_type" => String
58
+ }
59
+ })
60
+
61
+ tests("get_zone('zone' => '#{@domain}')").formats(get_zone_format) do
62
+ @dns.get_zone('zone' => @domain).body
63
+ end
64
+
65
+ post_record_format = shared_format.merge({
66
+ 'data' => {
67
+ 'fqdn' => String,
68
+ 'rdata' => {
69
+ 'address' => String
70
+ },
71
+ 'record_id' => Integer,
72
+ 'record_type' => String,
73
+ 'ttl' => Integer,
74
+ 'zone' => String
75
+ }
76
+ })
77
+
78
+ tests("post_record('A', '#{@domain}', '#{@fqdn}', 'address' => '1.2.3.4')").formats(post_record_format) do
79
+ @dns.post_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body
80
+ end
81
+
82
+ put_record_format = shared_format.merge({
83
+ 'data' => {
84
+ 'fqdn' => String,
85
+ 'ARecords' => [
86
+ {
87
+ 'rdata' => {
88
+ 'address' => String
89
+ }
90
+ }
91
+ ],
92
+ 'record_id' => Integer,
93
+ 'record_type' => String,
94
+ 'ttl' => Integer,
95
+ 'zone' => String
96
+ }
97
+ })
98
+
99
+ tests("put_record('A', '#{@domain}', '#{@fqdn}', 'address' => '1.2.3.4')").formats(post_record_format) do
100
+ @dns.put_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body
101
+ end
102
+
103
+ publish_zone_format = shared_format.merge({
104
+ 'data' => {
105
+ 'serial' => Integer,
106
+ 'serial_style' => String,
107
+ 'zone' => String,
108
+ 'zone_type' => String
109
+ }
110
+ })
111
+
112
+ tests("put_zone('#{@domain}', 'publish' => true)").formats(publish_zone_format) do
113
+ @dns.put_zone(@domain, 'publish' => true).body
114
+ end
115
+
116
+ freeze_zone_format = shared_format.merge({
117
+ 'data' => {}
118
+ })
119
+
120
+ tests("put_zone('#{@domain}', 'freeze' => true)").formats(freeze_zone_format) do
121
+ @dns.put_zone(@domain, 'freeze' => true).body
122
+ end
123
+
124
+ thaw_zone_format = shared_format.merge({
125
+ 'data' => {}
126
+ })
127
+
128
+ tests("put_zone('#{@domain}', 'thaw' => true)").formats(thaw_zone_format) do
129
+ @dns.put_zone(@domain, 'thaw' => true).body
130
+ end
131
+
132
+ get_node_list_format = shared_format.merge({
133
+ 'data' => [String]
134
+ })
135
+
136
+ tests("get_node_list('#{@domain}')").formats(get_node_list_format) do
137
+ @dns.get_node_list(@domain).body
138
+ end
139
+
140
+ get_all_records_format = shared_format.merge({
141
+ 'data' => [String]
142
+ })
143
+
144
+ tests("get_all_records('#{@domain}')").formats(get_all_records_format) do
145
+ @dns.get_all_records(@domain).body
146
+ end
147
+
148
+ get_records_format = shared_format.merge({
149
+ 'data' => [String]
150
+ })
151
+
152
+ tests("get_record('A', '#{@domain}', '#{@fqdn}')").formats(get_records_format) do
153
+ data = @dns.get_record('A', @domain, @fqdn).body
154
+ @record_id = data['data'].first.split('/').last
155
+ data
156
+ end
157
+
158
+ sleep 5 unless Fog.mocking?
159
+
160
+ @dns.post_record('CNAME', @domain, "cname.#{@fqdn}", {'cname' => "#{@fqdn}."})
161
+
162
+ tests("get_record('ANY', '#{@domain}', 'cname.#{@fqdn}')").formats(get_records_format) do
163
+ @dns.get_record('ANY', @domain, "cname.#{@fqdn}").body
164
+ end
165
+
166
+ get_record_format = shared_format.merge({
167
+ 'data' => {
168
+ 'zone' => String,
169
+ 'ttl' => Integer,
170
+ 'fqdn' => String,
171
+ 'record_type' => String,
172
+ 'rdata' => {
173
+ 'address' => String
174
+ },
175
+ 'record_id' => Integer
176
+ }
177
+ })
178
+
179
+ tests("get_record('A', '#{@domain}', '#{@fqdn}', 'record_id' => '#{@record_id}')").formats(get_record_format) do
180
+ @dns.get_record('A', @domain, @fqdn, 'record_id' => @record_id).body
181
+ end
182
+
183
+ delete_record_format = shared_format.merge({
184
+ 'data' => {}
185
+ })
186
+
187
+ tests("delete_record('A', '#{@domain}', '#{@fqdn}', '#{@record_id}')").formats(delete_record_format) do
188
+ @dns.delete_record('A', @domain, "#{@fqdn}", @record_id).body
189
+ end
190
+
191
+ delete_zone_format = shared_format.merge({
192
+ 'data' => {}
193
+ })
194
+
195
+ sleep 5 unless Fog.mocking?
196
+
197
+ tests("delete_zone('#{@domain}')").formats(delete_zone_format) do
198
+ @dns.delete_zone(@domain).body
199
+ end
200
+
201
+ tests("job handling") do
202
+ pending unless Fog.mocking?
203
+
204
+ old_mock_value = Excon.defaults[:mock]
205
+ Excon.stubs.clear
206
+
207
+ tests("returns final response from a complete job").returns({"status" => "success"}) do
208
+ begin
209
+ Excon.defaults[:mock] = true
210
+
211
+ Excon.stub({:method => :post, :path => "/REST/Session"}, {:body=>"{\"status\": \"success\", \"data\": {\"token\": \"foobar\", \"version\": \"2.3.1\"}, \"job_id\": 150583906, \"msgs\": [{\"INFO\": \"login: Login successful\", \"SOURCE\": \"BLL\", \"ERR_CD\": null, \"LVL\": \"INFO\"}]}", :headers=>{"Content-Type"=>"application/json"}, :status=>200})
212
+
213
+ Excon.stub({:method => :get, :path => "/REST/Zone/example.com"}, {:status => 307, :body => '/REST/Job/150576635', :headers => {'Content-Type' => 'text/html', 'Location' => '/REST/Job/150576635'}})
214
+ Excon.stub({:method => :get, :path => "/REST/Job/150576635"}, {:status => 307, :body => '{"status":"success"}', :headers => {'Content-Type' => 'application/json'}})
215
+
216
+ Fog::DNS::Dynect::Real.new.request(:method => :get, :path => "Zone/example.com").body
217
+ ensure
218
+ Excon.stubs.clear
219
+ Excon.defaults[:mock] = old_mock_value
220
+ end
221
+ end
222
+
223
+ tests("passes expects through when polling a job").returns({"status" => "success"}) do
224
+ begin
225
+ Excon.defaults[:mock] = true
226
+
227
+ Excon.stub({:method => :post, :path => "/REST/Session"}, {:body=>"{\"status\": \"success\", \"data\": {\"token\": \"foobar\", \"version\": \"2.3.1\"}, \"job_id\": 150583906, \"msgs\": [{\"INFO\": \"login: Login successful\", \"SOURCE\": \"BLL\", \"ERR_CD\": null, \"LVL\": \"INFO\"}]}", :headers=>{"Content-Type"=>"application/json"}, :status=>200})
228
+
229
+ Excon.stub({:method => :get, :path => "/REST/Zone/example.com"}, {:status => 307, :body => '/REST/Job/150576635', :headers => {'Content-Type' => 'text/html', 'Location' => '/REST/Job/150576635'}})
230
+ Excon.stub({:method => :get, :path => "/REST/Job/150576635"}, {:status => 404, :body => '{"status":"success"}', :headers => {'Content-Type' => 'application/json'}})
231
+
232
+ Fog::DNS::Dynect::Real.new.request(:method => :get, :expects => 404, :path => "Zone/example.com").body
233
+ ensure
234
+ Excon.stubs.clear
235
+ Excon.defaults[:mock] = old_mock_value
236
+ end
237
+ end
238
+ end
239
+ end
240
+
241
+ tests('failure') do
242
+ tests("#auth_token with expired credentials").raises(Excon::Errors::BadRequest) do
243
+ pending if Fog.mocking?
244
+ @dns = Fog::DNS[:dynect]
245
+ @dns.instance_variable_get(:@connection).stub(:request) { raise Excon::Errors::BadRequest.new('Expected(200) <=> Actual(400 Bad Request) request => {:headers=>{"Content-Type"=>"application/json", "API-Version"=>"2.3.1", "Auth-Token"=>"auth-token", "Host"=>"api2.dynect.net:443", "Content-Length"=>0}, :host=>"api2.dynect.net", :mock=>nil, :path=>"/REST/CNAMERecord/domain.com/www.domain.com", :port=>"443", :query=>nil, :scheme=>"https", :expects=>200, :method=>:get} response => #<Excon::Response:0x00000008478b98 @body="{"status": "failure", "data": {}, "job_id": 21326025, "msgs": [{"INFO": "login: Bad or expired credentials", "SOURCE": "BLL", "ERR_CD": "INVALID_DATA", "LVL": "ERROR"}, {"INFO": "login: There was a problem with your credentials", "SOURCE": "BLL", "ERR_CD": null, "LVL": "INFO"}]}", @headers={"Server"=>"nginx/0.7.67", "Date"=>"Thu, 08 Sep 2011 20:04:21 GMT", "Content-Type"=>"application/json", "Transfer-Encoding"=>"chunked", "Connection"=>"keep-alive"}, @status=400>') }
246
+ @dns.instance_variable_get(:@connection).should_receive(:request).exactly(2).times
247
+ @dns.auth_token
248
+ end
249
+
250
+ tests("#auth_token with inactivity logout").raises(Excon::Errors::BadRequest) do
251
+ pending if Fog.mocking?
252
+ @dns = Fog::DNS[:dynect]
253
+ @dns.instance_variable_get(:@connection).stub(:request) { raise Excon::Errors::BadRequest.new('Expected(200) <=> Actual(400 Bad Request) request => {:headers=>{"Content-Type"=>"application/json", "API-Version"=>"2.3.1", "Auth-Token"=>"auth-token", "Host"=>"api2.dynect.net:443", "Content-Length"=>0}, :host=>"api2.dynect.net", :mock=>nil, :path=>"/REST/CNAMERecord/domain.com/www.domain.com", :port=>"443", :query=>nil, :scheme=>"https", :expects=>200, :method=>:get} response => #<Excon::Response:0x00000008478b98 @body="{"status": "failure", "data": {}, "job_id": 21326025, "msgs": [{"INFO": "login: inactivity logout", "SOURCE": "BLL", "ERR_CD": "INVALID_DATA", "LVL": "ERROR"}, {"INFO": "login: There was a problem with your credentials", "SOURCE": "BLL", "ERR_CD": null, "LVL": "INFO"}]}", @headers={"Server"=>"nginx/0.7.67", "Date"=>"Thu, 08 Sep 2011 20:04:21 GMT", "Content-Type"=>"application/json", "Transfer-Encoding"=>"chunked", "Connection"=>"keep-alive"}, @status=400>') }
254
+ @dns.instance_variable_get(:@connection).should_receive(:request).exactly(2).times
255
+ @dns.auth_token
256
+ end
257
+ end
258
+ end
@@ -0,0 +1,13 @@
1
+ begin
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ rescue LoadError => e
5
+ $stderr.puts "not recording test coverage: #{e.inspect}"
6
+ end
7
+
8
+ require 'fog/test_helpers'
9
+ require File.expand_path('../../lib/fog/dynect', __FILE__)
10
+
11
+ Bundler.require(:test)
12
+
13
+ Excon.defaults.merge!(:debug_request => true, :debug_response => true)
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fog-dynect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Wesley Beary
8
+ - The fog team
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: shindo
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: fog-core
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: fog-json
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: fog-xml
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: |-
99
+ This library can be used as a module for `fog` or as
100
+ standalone provider to use Dynect DNS in applications.
101
+ email:
102
+ - geemus@gmail.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".travis.yml"
109
+ - CHANGELOG.md
110
+ - CONTRIBUTING.md
111
+ - CONTRIBUTORS.md
112
+ - Gemfile
113
+ - LICENSE.md
114
+ - README.md
115
+ - Rakefile
116
+ - fog-dynect.gemspec
117
+ - gemfiles/Gemfile-1.8.7
118
+ - lib/fog/dynect.rb
119
+ - lib/fog/dynect/core.rb
120
+ - lib/fog/dynect/dns.rb
121
+ - lib/fog/dynect/models/dns/record.rb
122
+ - lib/fog/dynect/models/dns/records.rb
123
+ - lib/fog/dynect/models/dns/zone.rb
124
+ - lib/fog/dynect/models/dns/zones.rb
125
+ - lib/fog/dynect/requests/dns/delete_record.rb
126
+ - lib/fog/dynect/requests/dns/delete_zone.rb
127
+ - lib/fog/dynect/requests/dns/get_all_records.rb
128
+ - lib/fog/dynect/requests/dns/get_node_list.rb
129
+ - lib/fog/dynect/requests/dns/get_record.rb
130
+ - lib/fog/dynect/requests/dns/get_zone.rb
131
+ - lib/fog/dynect/requests/dns/post_record.rb
132
+ - lib/fog/dynect/requests/dns/post_session.rb
133
+ - lib/fog/dynect/requests/dns/post_zone.rb
134
+ - lib/fog/dynect/requests/dns/put_record.rb
135
+ - lib/fog/dynect/requests/dns/put_zone.rb
136
+ - lib/fog/dynect/version.rb
137
+ - tests/dns/helper.rb
138
+ - tests/dns/models/record_tests.rb
139
+ - tests/dns/models/records_tests.rb
140
+ - tests/dns/models/zone_tests.rb
141
+ - tests/dns/models/zones_tests.rb
142
+ - tests/dynect/requests/dns/dns_tests.rb
143
+ - tests/helper.rb
144
+ homepage: http://github.com/fog/fog-dynect
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.4.8
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Module for the 'fog' gem to support Dynect DNS.
168
+ test_files: []