splicer-dynect 1.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ N2VlNGRiOWEwYzM3N2M3MTJkOGRmNjY0ODE5MjRlMDVjNTdmYTVhZg==
5
+ data.tar.gz: !binary |-
6
+ ZWYzNzliNTA4MmRhYmVkNGRiYmMwNzNjMzdkNzYzNDc2YmI5ZTkzMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ Yzg1MTZiMzRlYzI2OTNiZTYxN2FhMTRmMGRiNTIxMDFkM2FmYTc0ZDE3ZGEz
10
+ ZGJjODdhNGMyMzM5ZTY5YzY4NmJiM2Y5MDcyMmQxYmVkMWJiMTZiNjIyYjg1
11
+ NjBhZDkzMDM4NTU1ZjM1ZTJkY2FlODQ1YTYwNWQ1ZDc5NGU5MDU=
12
+ data.tar.gz: !binary |-
13
+ ZmU5MWY1ZjI3OWIxNjkzNzAwMWE5ODY4MTRhZDUxOWJjNjQ4N2E0MTE5OWM0
14
+ N2QyODUyZmQxZWJiNzQ4ZjUyYzA2YjkwMzZlNzc0OTc3OTAyYjBjZjFkNGJm
15
+ Njk5MTcwZmEwOWIzNzc3ZDAzMzQ4NzgxZjFjNDUyOGU0MjI4NGQ=
@@ -2,7 +2,7 @@ module Splicer
2
2
  module Dynect
3
3
 
4
4
  # @author Matthew A. Johnston <warmwaffles@gmail.com>
5
- class Provider
5
+ class Provider < Splicer::Provider
6
6
  attr_reader :client
7
7
 
8
8
  def initialize(config)
@@ -10,121 +10,132 @@ module Splicer
10
10
  @client = config.client
11
11
  end
12
12
 
13
- # @param [Dynect::Zone] zone
14
- # @param [Symbol] method the way you want the zone published
15
- def publish(zone, method)
13
+ def create_zone(zone)
16
14
  client.login
17
15
 
18
- case method
19
- when :rewrite
20
- rewrite(zone)
21
- when :merge
22
- merge(zone)
23
- else
24
- false
16
+ client.post "Zone/#{zone.name}", rname: "admin@#{zone.name}", ttl: zone.ttl
17
+
18
+ zone.records.each do |record|
19
+ create_record(record, zone)
25
20
  end
26
21
 
22
+ publish_zone(zone)
27
23
  ensure
28
24
  client.logout
29
25
  end
30
26
 
31
- def destroy(zone)
27
+ def update_zone(zone)
32
28
  client.login
33
- delete_zone(zone)
29
+ get_zone(zone)
30
+
31
+ zone.records.each do |record|
32
+ update_record(record, zone)
33
+ end
34
+
35
+ publish_zone(zone)
34
36
  ensure
35
37
  client.logout
36
38
  end
37
39
 
38
- private
39
-
40
- def rewrite(zone)
40
+ def rewrite_zone(zone)
41
41
  delete_zone(zone)
42
+ create_zone(zone)
43
+ end
42
44
 
43
- client.post "Zone/#{zone.name}", rname: "admin@#{zone.name}", ttl: zone.ttl
45
+ def delete_zone(zone)
46
+ client.login
47
+ get_zone(zone)
48
+ client.delete "Zone/#{zone.name}"
49
+ ensure
50
+ client.logout
51
+ end
44
52
 
45
- zone.records.each do |record|
46
- case record
47
- when Splicer::Records::ARecord
48
- create_record('ARecord', record, zone, rdata: { address: record.ip }, ttl: record.ttl)
49
- when Splicer::Records::AAAARecord
50
- create_record('AAAARecord', record, zone, rdata: { address: record.ip }, ttl: record.ttl)
51
- when Splicer::Records::CNAMERecord
52
- create_record('CNAMERecord', record, zone, rdata: { cname: record.cname }, ttl: record.ttl)
53
- when Splicer::Records::MXRecord
54
- create_record('MXRecord', record, zone, rdata: { exchange: record.exchanger, preference: record.priority }, ttl: record.ttl)
55
- when Splicer::Records::NSRecord
56
- create_record('NSRecord', record, zone, rdata: { nsdname: record.server }, ttl: record.ttl)
57
- when Splicer::Records::PTRRecord
58
- create_record('PTRRecord', record, zone,rdata: { ptrdname: record.host }, ttl: record.ttl)
59
- when Splicer::Records::SPFRecord
60
- create_record('SPFRecord', record, zone, rdata: { txtdata: record.text }, ttl: record.ttl)
61
- when Splicer::Records::SRVRecord
62
- create_record('SRVRecord', record, zone, rdata: { port: record.port, priority: record.priority, target: record.target, weight: record.weight }, ttl: record.ttl)
63
- when Splicer::Records::TXTRecord
64
- create_record('TXTRecord', record, zone, rdata: { txtdata: record.text }, ttl: record.ttl)
65
- end
66
- end
53
+ def delete_record_in_zone(record, zone)
54
+ client.login
55
+ id = find_record_id(record, zone)
56
+ return false unless id
67
57
 
68
- client.put "Zone/#{zone.name}", publish: true
58
+ url = record_resource_url(record, zone).concat("/#{id}")
59
+ client.delete(url)
60
+ publish_zone(zone)
61
+ ensure
62
+ client.logout
69
63
  end
70
64
 
71
- def merge(zone)
72
- begin
73
- client.get "Zone/#{zone.name}"
74
- rescue Splicer::Errors::RequestError => error
75
- client.post "Zone/#{zone.name}"
76
- end
77
-
78
- zone.records.each do |record|
79
- case record
80
- when Splicer::Records::ARecord
81
- update_or_create_record('ARecord', record, zone, rdata: { address: record.ip }, ttl: record.ttl)
82
- when Splicer::Records::AAAARecord
83
- update_or_create_record('AAAARecord', record, zone, rdata: { address: record.ip }, ttl: record.ttl)
84
- when Splicer::Records::CNAMERecord
85
- update_or_create_record('CNAMERecord', record, zone, rdata: { cname: record.cname }, ttl: record.ttl)
86
- when Splicer::Records::MXRecord
87
- update_or_create_record('MXRecord', record, zone, rdata: { exchange: record.exchanger, preference: record.priority }, ttl: record.ttl)
88
- when Splicer::Records::NSRecord
89
- update_or_create_record('NSRecord', record, zone, rdata: { nsdname: record.server }, ttl: record.ttl)
90
- when Splicer::Records::PTRRecord
91
- update_or_create_record('PTRRecord', record, zone,rdata: { ptrdname: record.host }, ttl: record.ttl)
92
- when Splicer::Records::SPFRecord
93
- update_or_create_record('SPFRecord', record, zone, rdata: { txtdata: record.text }, ttl: record.ttl)
94
- when Splicer::Records::SRVRecord
95
- update_or_create_record('SRVRecord', record, zone, rdata: { port: record.port, priority: record.priority, target: record.target, weight: record.weight }, ttl: record.ttl)
96
- when Splicer::Records::TXTRecord
97
- update_or_create_record('TXTRecord', record, zone, rdata: { txtdata: record.text }, ttl: record.ttl)
98
- end
99
- end
65
+ def update_record_in_zone(record, zone)
66
+ client.login
67
+ update_record(record, zone)
68
+ publish_zone(zone)
69
+ ensure
70
+ client.logout
71
+ end
100
72
 
101
- client.put "Zone/#{zone.name}", publish: true
73
+ def create_record_in_zone(record, zone)
74
+ client.login
75
+ create_record(record, zone)
76
+ publish_zone(zone)
77
+ ensure
78
+ client.logout
102
79
  end
103
80
 
104
81
  private
105
82
 
106
- def delete_zone(zone)
83
+ def get_zone(zone)
107
84
  client.get "Zone/#{zone.name}"
108
- client.delete "Zone/#{zone.name}"
109
- true
110
- rescue Splicer::Errors::RequestError => error
111
- false
112
85
  end
113
86
 
114
- def update_or_create_record(resource, record, zone, data={})
115
- begin
116
- client.put(resource_url(resource, record, zone), data)
117
- rescue Splicer::Errors::RequestError => error
118
- create_record(resource, record, zone, data)
87
+ def publish_zone(zone)
88
+ client.put "Zone/#{zone.name}", publish: true
89
+ end
90
+
91
+ def find_record_id(record, zone)
92
+ resources = client.get(record_resource_url(record, zone))
93
+ if resources['data'].empty?
94
+ return false
95
+ else
96
+ resources['data'].first.split('/').last
97
+ end
98
+ end
99
+
100
+ # Returns the proper record data for a specific record
101
+ # @param [Splicer::Records::Record] record
102
+ # @return [Hash]
103
+ def record_payload(record)
104
+ case record
105
+ when Splicer::Records::ARecord
106
+ { rdata: { address: record.ip }, ttl: record.ttl}
107
+ when Splicer::Records::AAAARecord
108
+ { rdata: { address: record.ip }, ttl: record.ttl}
109
+ when Splicer::Records::CNAMERecord
110
+ { rdata: { cname: record.cname }, ttl: record.ttl}
111
+ when Splicer::Records::MXRecord
112
+ { rdata: { exchange: record.exchanger, preference: record.priority }, ttl: record.ttl}
113
+ when Splicer::Records::NSRecord
114
+ { rdata: { nsdname: record.server }, ttl: record.ttl}
115
+ when Splicer::Records::PTRRecord
116
+ { rdata: { ptrdname: record.host }, ttl: record.ttl}
117
+ when Splicer::Records::SPFRecord
118
+ { rdata: { txtdata: record.text }, ttl: record.ttl}
119
+ when Splicer::Records::SRVRecord
120
+ { rdata: { port: record.port, priority: record.priority, target: record.target, weight: record.weight }, ttl: record.ttl}
121
+ when Splicer::Records::TXTRecord
122
+ { rdata: { txtdata: record.text }, ttl: record.ttl}
123
+ else
124
+ { }
119
125
  end
120
126
  end
121
127
 
122
- def create_record(resource, record, zone, data={})
123
- client.post(resource_url(resource, record, zone), data)
128
+ def update_record(record, zone)
129
+ client.put(record_resource_url(record, zone), record_payload(record))
130
+ end
131
+
132
+ def create_record(record, zone)
133
+ client.post(record_resource_url(record, zone), record_payload(record))
124
134
  end
125
135
 
126
- def resource_url(resource, record, zone)
127
- if record.name.nil? || record.name == zone.name
136
+ def record_resource_url(record, zone)
137
+ resource = record.class.name.split('::').last
138
+ if record.name.nil?
128
139
  "#{resource}/#{zone.name}/#{zone.name}"
129
140
  else
130
141
  "#{resource}/#{zone.name}/#{record.name}.#{zone.name}"
@@ -1,5 +1,5 @@
1
1
  module Splicer
2
2
  module Dynect
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
@@ -4,47 +4,31 @@ describe Splicer::Dynect::Provider do
4
4
  let(:config) { Splicer::Dynect::Config.new('customer','user','password') }
5
5
  let(:provider) { Splicer::Dynect::Provider.new(config) }
6
6
 
7
- let(:client) { double('Splicer::Dynect::Client', login: true, logout: true) }
8
- let(:zone) { double('Splicer::Zone') }
9
-
10
- before { config.stub(:client).and_return(client) }
11
-
12
- describe '#publish' do
13
- context 'when merging a zone' do
14
- subject { provider.publish(zone, :merge) }
15
-
16
- context 'and dynect returns successfully' do
17
- before { provider.stub(:merge).and_return(true) }
18
- it { should eq(true) }
19
- end
20
-
21
- context 'and dynect returns an error' do
22
- before { provider.stub(:merge).and_raise(Splicer::Errors::RequestError) }
23
- it 'should raise Splicer::Errors::RequestError' do
24
- expect { subject }.to raise_error(Splicer::Errors::RequestError)
25
- end
26
- end
27
- end
28
-
29
- context 'when rewriting a zone' do
30
- subject { provider.publish(zone, :rewrite) }
31
-
32
- context 'and dynect returns successfully' do
33
- before { provider.stub(:rewrite).and_return(true) }
34
- it { should eq(true) }
35
- end
36
-
37
- context 'and dynect returns an error' do
38
- before { provider.stub(:rewrite).and_raise(Splicer::Errors::RequestError) }
39
- it 'should raise and Splicer::Errors::RequestError' do
40
- expect { subject }.to raise_error(Splicer::Errors::RequestError)
41
- end
42
- end
43
- end
44
-
45
- context 'when doing something undefined' do
46
- subject { provider.publish(zone, :something) }
47
- it { should eq(false) }
48
- end
7
+ describe '#create_zone' do
8
+ subject { provider.create_zone(zone) }
9
+ end
10
+
11
+ describe '#update_zone' do
12
+ subject { provider.update_zone(zone) }
13
+ end
14
+
15
+ describe '#rewrite_zone' do
16
+ subject { provider.rewrite_zone(zone) }
17
+ end
18
+
19
+ describe '#delete_zone' do
20
+ subject { provider.delete_zone(zone) }
21
+ end
22
+
23
+ describe '#delete_record_in_zone' do
24
+ subject { provider.delete_record_in_zone(record, zone) }
25
+ end
26
+
27
+ describe '#update_record_in_zone' do
28
+ subject { provider.update_record_in_zone(record, zone) }
29
+ end
30
+
31
+ describe '#create_record_in_zone' do
32
+ subject { provider.create_record_in_zone(record, zone) }
49
33
  end
50
34
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency('splicer', '~> 1.0')
21
+ spec.add_dependency('splicer', '~> 1.1')
22
22
  spec.add_dependency('rest-client')
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
metadata CHANGED
@@ -1,36 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splicer-dynect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
5
- prerelease:
4
+ version: 1.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Matthew Johnston
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-10 00:00:00.000000000 Z
11
+ date: 2013-05-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: splicer
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: '1.0'
19
+ version: '1.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: '1.0'
26
+ version: '1.1'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rest-client
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -119,33 +108,26 @@ files:
119
108
  homepage: https://github.com/zippykid/splicer-dynect
120
109
  licenses:
121
110
  - MIT
111
+ metadata: {}
122
112
  post_install_message:
123
113
  rdoc_options: []
124
114
  require_paths:
125
115
  - lib
126
116
  required_ruby_version: !ruby/object:Gem::Requirement
127
- none: false
128
117
  requirements:
129
118
  - - ! '>='
130
119
  - !ruby/object:Gem::Version
131
120
  version: '0'
132
- segments:
133
- - 0
134
- hash: -2750849641139883288
135
121
  required_rubygems_version: !ruby/object:Gem::Requirement
136
- none: false
137
122
  requirements:
138
123
  - - ! '>='
139
124
  - !ruby/object:Gem::Version
140
125
  version: '0'
141
- segments:
142
- - 0
143
- hash: -2750849641139883288
144
126
  requirements: []
145
127
  rubyforge_project:
146
- rubygems_version: 1.8.25
128
+ rubygems_version: 2.0.3
147
129
  signing_key:
148
- specification_version: 3
130
+ specification_version: 4
149
131
  summary: The splicer adapter for interacting Dynect
150
132
  test_files:
151
133
  - spec/spec_helper.rb