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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6cce60eb5ac84071ad2ad5764bc0ee528b9ded8
4
+ data.tar.gz: 6e90dedb8e5a609e8f180d9b6f59fc30c234f285
5
+ SHA512:
6
+ metadata.gz: 1dbffd955de33d3e5a8fa097fa4a5cd63cdbdfec824e9ad595bf3a4f6249b66734666749e226035cb693348ee241be96d26e5c172aeb1444a6a53091951d8832
7
+ data.tar.gz: 202a91636bd1c6e5f60ad5b36b06e75adfbde4be38b0864231aa5a60443de526b61446fe3f97983cc1a5cc5dfc74e291e3961afc8b520330da79e6c3bd916776
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ gemfiles/*.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.2
5
+ - 2.1
6
+ - 2.0
7
+ - 1.9
8
+ - jruby
9
+
10
+ matrix:
11
+ include:
12
+ - rvm: 1.8.7
13
+ gemfile: gemfiles/Gemfile-1.8.7
14
+ - rvm: jruby-18mode
15
+ gemfile: gemfiles/Gemfile-1.8.7
@@ -0,0 +1,3 @@
1
+ v0.0.1
2
+
3
+ Initial extraction from fog v1.18.0-2712-g388983f.
@@ -0,0 +1,18 @@
1
+ ## Getting Involved
2
+
3
+ New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another.
4
+
5
+ ### Coding
6
+
7
+ * Pick a task:
8
+ * Offer feedback on open [pull requests](https://github.com/fog/fog-dynect/pulls).
9
+ * Review open [issues](https://github.com/fog/fog-dynect/issues) for things to help on.
10
+ * [Create an issue](https://github.com/fog/fog-dynect/issues/new) to start a discussion on additions or features.
11
+ * Fork the project, add your changes and tests to cover them in a topic branch.
12
+ * Commit your changes and rebase against `fog/fog-dynect` to ensure everything is up to date.
13
+ * [Submit a pull request](https://github.com/fog/fog-dynect/compare/).
14
+
15
+ ### Non-Coding
16
+
17
+ * Offer feedback on open [issues](https://github.com/fog/fog-dynect/issues).
18
+ * Organize or volunteer at events.
@@ -0,0 +1,27 @@
1
+ * Brett Lentz <blentz@redhat.com>
2
+ * Chris Chalstrom <cchalstr@nsidc-chalstrom.ad.int.nsidc.org>
3
+ * Dan Peterson <dpiddy@gmail.com>
4
+ * Dylan Egan <dylanegan@gmail.com>
5
+ * Dylan Egan <me@dylanegan.com>
6
+ * Eric Hankins <ehankins@rednovalabs.com>
7
+ * Frederick Cheung <frederick.cheung@gmail.com>
8
+ * geemus <geemus@gmail.com>
9
+ * James Herdman <james.herdman@me.com>
10
+ * Josh Blancett <joshblancett@gmail.com>
11
+ * Kevin Menard <nirvdrum@gmail.com>
12
+ * Kyle Rames <kyle.rames@rackspace.com>
13
+ * Lance Ivy <lance@cainlevy.net>
14
+ * Marc Seeger <mail@marc-seeger.de>
15
+ * Matt Darby <matt.darby@rackspace.com>
16
+ * Michael Hale <mike@hales.ws>
17
+ * Nick Janus <nickjanus@gmail.com>
18
+ * Paul Thornthwaite <paul@brightbox.co.uk>
19
+ * Paul Thornthwaite <tokengeek@gmail.com>
20
+ * Peter Drake <peter.drake@acquia.com>
21
+ * Richard Henning <rhenning@weblinc.com>
22
+ * Shawn Catanzarite <me@shawncatz.com>
23
+ * Steve Smith <github@scsworld.co.uk>
24
+ * Wesley Beary <geemus+github@gmail.com>
25
+ * Wesley Beary <geemus@gmail.com>
26
+ * Wesley Beary <wesley@heroku.com>
27
+ * Weston Platter <westonplatter@gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-dynect.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 [CONTRIBUTORS.md](https://github.com/fog/fog-dynect/blob/master/CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Fog::Dynect
2
+
3
+ [![Build Status](https://travis-ci.org/fog/fog-dynect.svg?branch=master)](https://travis-ci.org/fog/fog-dynect)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fog-dynect'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fog-dynect
20
+
21
+ ## Usage
22
+
23
+ Initialize a `Fog::DNS` object using the Dynect provider.
24
+
25
+ ```ruby
26
+
27
+ dns = Fog::DNS.new({
28
+ :provider => 'Dynect',
29
+ :dynect_customer => 'dynect_customer',
30
+ :dynect_username => 'dynect_username',
31
+ :dynect_password => 'dynect_password'
32
+ })
33
+
34
+ ```
35
+
36
+ This can then be used like other [Fog DNS](http://fog.io/dns/) providers.
37
+
38
+ ```ruby
39
+
40
+ zone = dns.zones.create(
41
+ :domain => 'example.com',
42
+ :email => 'admin@example.com'
43
+ )
44
+ record = zone.records.create(
45
+ :value => '1.2.3.4',
46
+ :name => 'example.com',
47
+ :type => 'A'
48
+ )
49
+
50
+ ```
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( https://github.com/fog/fog-dynect/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task :default => :test
4
+
5
+ mock = ENV['FOG_MOCK'] || 'true'
6
+ task :test do
7
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
8
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fog/dynect/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fog-dynect'
8
+ spec.version = Fog::Dynect::VERSION
9
+ spec.authors = ['Wesley Beary', 'The fog team']
10
+ spec.email = ['geemus@gmail.com']
11
+ spec.summary = "Module for the 'fog' gem to support Dynect DNS."
12
+ spec.description = 'This library can be used as a module for `fog` or as
13
+ standalone provider to use Dynect DNS in applications.'
14
+ spec.homepage = 'http://github.com/fog/fog-dynect'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'shindo', '~> 0.3'
25
+
26
+ spec.add_dependency 'fog-core'
27
+ spec.add_dependency 'fog-json'
28
+ spec.add_dependency 'fog-xml'
29
+ end
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'mime-types', '~> 1.16'
4
+ gem 'nokogiri', '~> 1.5.11'
5
+
6
+ gemspec :path => "../"
@@ -0,0 +1 @@
1
+ require 'fog/dynect/dns'
@@ -0,0 +1,27 @@
1
+ require 'nokogiri'
2
+
3
+ require 'fog/core'
4
+ require 'fog/json'
5
+ require 'fog/xml'
6
+
7
+ module Fog
8
+ module Dynect
9
+ extend Fog::Provider
10
+
11
+ service(:dns, 'DNS')
12
+
13
+ class Mock
14
+ def self.job_id
15
+ Fog::Mock.random_numbers(8).to_i
16
+ end
17
+
18
+ def self.token
19
+ Fog::Mock.random_hex(48)
20
+ end
21
+
22
+ def self.version
23
+ [Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1), Fog::Mock.random_numbers(1)].join('.')
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,157 @@
1
+ require 'fog/dynect/core'
2
+
3
+ module Fog
4
+ module DNS
5
+ class Dynect < Fog::Service
6
+ requires :dynect_customer, :dynect_username, :dynect_password
7
+ recognizes :timeout, :persistent, :job_poll_timeout
8
+ recognizes :provider # remove post deprecation
9
+
10
+ model_path 'fog/dynect/models/dns'
11
+ model :record
12
+ collection :records
13
+ model :zone
14
+ collection :zones
15
+
16
+ request_path 'fog/dynect/requests/dns'
17
+ request :delete_record
18
+ request :delete_zone
19
+ request :get_node_list
20
+ request :get_all_records
21
+ request :get_record
22
+ request :get_zone
23
+ request :post_record
24
+ request :post_session
25
+ request :post_zone
26
+ request :put_zone
27
+ request :put_record
28
+
29
+ class JobIncomplete < Error; end
30
+
31
+ class Mock
32
+ def initialize(options={})
33
+ @dynect_customer = options[:dynect_customer]
34
+ @dynect_username = options[:dynect_username]
35
+ @dynect_password = options[:dynect_password]
36
+ end
37
+
38
+ def self.data
39
+ @data ||= {
40
+ :zones => {}
41
+ }
42
+ end
43
+
44
+ def self.reset
45
+ @data = nil
46
+ end
47
+
48
+ def auth_token
49
+ @auth_token ||= Fog::Dynect::Mock.token
50
+ end
51
+
52
+ def data
53
+ self.class.data
54
+ end
55
+
56
+ def reset_data
57
+ self.class.reset
58
+ end
59
+ end
60
+
61
+ class Real
62
+ def initialize(options={})
63
+ @dynect_customer = options[:dynect_customer]
64
+ @dynect_username = options[:dynect_username]
65
+ @dynect_password = options[:dynect_password]
66
+
67
+ @connection_options = options[:connection_options] || {}
68
+ @host = 'api-v4.dynect.net'
69
+ @port = options[:port] || 443
70
+ @path = options[:path] || '/REST'
71
+ @persistent = options[:persistent] || false
72
+ @scheme = options[:scheme] || 'https'
73
+ @version = options[:version] || '3.5.2'
74
+ @job_poll_timeout = options[:job_poll_timeout] || 10
75
+ @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
76
+ end
77
+
78
+ def auth_token
79
+ @auth_token ||= post_session.body['data']['token']
80
+ end
81
+
82
+ def request(params)
83
+ begin
84
+ # any request could redirect to a job
85
+ params[:expects] = Array(params[:expects]) | [307]
86
+
87
+ params[:headers] ||= {}
88
+ params[:headers]['Content-Type'] = 'application/json'
89
+ params[:headers]['API-Version'] = @version
90
+ params[:headers]['Auth-Token'] = auth_token unless params[:path] == 'Session'
91
+ params[:path] = "#{@path}/#{params[:path]}" unless params[:path] =~ %r{^#{Regexp.escape(@path)}/}
92
+
93
+ response = @connection.request(params)
94
+
95
+ if response.body.empty?
96
+ response.body = {}
97
+ elsif response.headers['Content-Type'] == 'application/json'
98
+ response.body = Fog::JSON.decode(response.body)
99
+ end
100
+
101
+ if response.body['status'] == 'failure'
102
+ raise Error, response.body['msgs'].first['INFO']
103
+ end
104
+
105
+ if params[:path] !~ %r{^/REST/Job/}
106
+ if response.status == 307
107
+ response = poll_job(response, params[:expects], @job_poll_timeout)
108
+
109
+ # Dynect intermittently returns 200 with an incomplete status. When this
110
+ # happens, the job should still be polled.
111
+ elsif response.status == 200 && response.body['status'].eql?('incomplete')
112
+ response.headers['Location'] = "/REST/Job/#{ response.body['job_id'] }"
113
+ response = poll_job(response, params[:expects], @job_poll_timeout)
114
+ end
115
+ end
116
+
117
+ response
118
+ rescue Excon::Errors::HTTPStatusError => error
119
+ if @auth_token && error.message =~ /login: (Bad or expired credentials|inactivity logout)/
120
+ @auth_token = nil
121
+ retry
122
+ else
123
+ raise error
124
+ end
125
+ end
126
+
127
+ response
128
+ end
129
+
130
+ def poll_job(response, original_expects, time_to_wait)
131
+ job_location = response.headers['Location']
132
+
133
+ begin
134
+ Fog.wait_for(time_to_wait) do
135
+ response = request(
136
+ :expects => original_expects,
137
+ :idempotent => true,
138
+ :method => :get,
139
+ :path => job_location
140
+ )
141
+ response.body['status'] != 'incomplete'
142
+ end
143
+
144
+ rescue Errors::TimeoutError => error
145
+ if response.body['status'] == 'incomplete'
146
+ raise JobIncomplete.new("Job #{response.body['job_id']} is still incomplete")
147
+ else
148
+ raise error
149
+ end
150
+ end
151
+
152
+ response
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,67 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module DNS
5
+ class Dynect
6
+ class Record < Fog::Model
7
+ extend Fog::Deprecation
8
+
9
+ identity :id
10
+ attribute :name, :aliases => [:fqdn, 'fqdn']
11
+ attribute :rdata
12
+ attribute :serial_style
13
+ attribute :ttl
14
+ attribute :type, :aliases => 'record_type'
15
+
16
+ def destroy
17
+ requires :identity, :name, :type, :zone
18
+ service.delete_record(type, zone.identity, name, identity)
19
+ true
20
+ end
21
+
22
+ def save(replace=false)
23
+ requires :name, :type, :rdata, :zone
24
+
25
+ options = {
26
+ :ttl => ttl
27
+ }
28
+ options.delete_if {|key, value| value.nil?}
29
+
30
+ if replace
31
+ data = service.put_record(type, zone.identity, name, rdata, options).body['data']
32
+ else
33
+ data = service.post_record(type, zone.identity, name, rdata, options).body['data']
34
+ end
35
+ # avoid overwriting zone object with zone string
36
+ data = data.reject {|key, value| key == 'zone'}
37
+ merge_attributes(data)
38
+
39
+ zone.publish
40
+ records = service.get_record(type, zone.identity, name).body['data']
41
+ # data in format ['/REST/xRecord/domain/fqdn/identity]
42
+ records.map! do |record|
43
+ tokens = record.split('/')
44
+ {
45
+ :identity => tokens.last,
46
+ :type => tokens[2][0...-6] # everything before 'Record'
47
+ }
48
+ end
49
+ record = records.find {|record| record[:type] == type}
50
+ merge_attributes(record)
51
+
52
+ true
53
+ end
54
+
55
+ def zone
56
+ @zone
57
+ end
58
+
59
+ private
60
+
61
+ def zone=(new_zone)
62
+ @zone = new_zone
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end