splicer-dynect 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/splicer/dynect/client.rb +4 -0
- data/lib/splicer/dynect/config.rb +5 -1
- data/lib/splicer/dynect/provider.rb +110 -5
- data/lib/splicer/dynect/version.rb +1 -1
- data/spec/splicer/dynect/config_spec.rb +5 -0
- data/spec/splicer/dynect/provider_spec.rb +48 -1
- data/splicer-dynect.gemspec +2 -2
- metadata +9 -9
data/README.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module Splicer
|
2
2
|
module Dynect
|
3
3
|
|
4
|
+
# @author Matthew A. Johnston <warmwaffles@gmail.com>
|
4
5
|
class Client
|
5
6
|
attr_reader :base_url, :headers, :customer, :username, :password
|
6
7
|
|
8
|
+
# @param [String] customer
|
9
|
+
# @param [String] username
|
10
|
+
# @param [String] password
|
7
11
|
def initialize(customer, username, password)
|
8
12
|
@customer = customer
|
9
13
|
@username = username
|
@@ -4,7 +4,7 @@ module Splicer
|
|
4
4
|
# A simple configuration data structure
|
5
5
|
# @author Matthew A. Johnston <warmwaffles@gmail.com>
|
6
6
|
class Config
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :customer, :username, :password
|
8
8
|
|
9
9
|
def initialize(customer, username, password)
|
10
10
|
@customer = customer
|
@@ -15,6 +15,10 @@ module Splicer
|
|
15
15
|
def provider
|
16
16
|
Provider.new(self)
|
17
17
|
end
|
18
|
+
|
19
|
+
def client
|
20
|
+
Client.new(customer, username, password)
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
end
|
@@ -1,18 +1,123 @@
|
|
1
1
|
module Splicer
|
2
2
|
module Dynect
|
3
3
|
|
4
|
+
# @author Matthew A. Johnston <warmwaffles@gmail.com>
|
4
5
|
class Provider
|
6
|
+
attr_reader :client
|
7
|
+
|
5
8
|
def initialize(config)
|
6
|
-
@
|
9
|
+
@config = config
|
10
|
+
@client = config.client
|
7
11
|
end
|
8
12
|
|
13
|
+
# @param [Dynect::Zone] zone
|
14
|
+
# @param [Symbol] method the way you want the zone published
|
9
15
|
def publish(zone, method)
|
10
|
-
|
16
|
+
client.login
|
17
|
+
|
18
|
+
case method
|
19
|
+
when :rewrite
|
20
|
+
rewrite(zone)
|
21
|
+
when :merge
|
22
|
+
merge(zone)
|
23
|
+
else
|
24
|
+
raise Splicer::Errors::Error.new("invalid method: #{method}")
|
25
|
+
end
|
26
|
+
|
27
|
+
ensure
|
28
|
+
client.logout
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def rewrite(zone)
|
34
|
+
begin
|
35
|
+
client.get "Zone/#{zone.name}"
|
36
|
+
client.delete "Zone/#{zone.name}"
|
37
|
+
rescue Splicer::Errors::RequestError => error
|
38
|
+
end
|
39
|
+
|
40
|
+
client.post "Zone/#{zone.name}", rname: "admin@#{zone.name}", ttl: zone.ttl
|
41
|
+
|
42
|
+
zone.records.each do |record|
|
43
|
+
case record
|
44
|
+
when Splicer::Records::ARecord
|
45
|
+
create_record('ARecord', record, zone, rdata: { address: record.ip }, ttl: record.ttl)
|
46
|
+
when Splicer::Records::AAAARecord
|
47
|
+
create_record('AAAARecord', record, zone, rdata: { address: record.ip }, ttl: record.ttl)
|
48
|
+
when Splicer::Records::CNAMERecord
|
49
|
+
create_record('CNAMERecord', record, zone, rdata: { cname: record.cname }, ttl: record.ttl)
|
50
|
+
when Splicer::Records::MXRecord
|
51
|
+
create_record('MXRecord', record, zone, rdata: { exchange: record.exchanger, preference: record.priority }, ttl: record.ttl)
|
52
|
+
when Splicer::Records::NSRecord
|
53
|
+
create_record('NSRecord', record, zone, rdata: { nsdname: record.server }, ttl: record.ttl)
|
54
|
+
when Splicer::Records::PTRRecord
|
55
|
+
create_record('PTRRecord', record, zone,rdata: { ptrdname: record.host }, ttl: record.ttl)
|
56
|
+
when Splicer::Records::SPFRecord
|
57
|
+
create_record('SPFRecord', record, zone, rdata: { txtdata: record.text }, ttl: record.ttl)
|
58
|
+
when Splicer::Records::SRVRecord
|
59
|
+
create_record('SRVRecord', record, zone, rdata: { port: record.port, priority: record.priority, target: record.target, weight: record.weight }, ttl: record.ttl)
|
60
|
+
when Splicer::Records::TXTRecord
|
61
|
+
create_record('TXTRecord', record, zone, rdata: { txtdata: record.text }, ttl: record.ttl)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
client.put "Zone/#{zone.name}", publish: true
|
66
|
+
end
|
67
|
+
|
68
|
+
def merge(zone)
|
69
|
+
begin
|
70
|
+
client.get "Zone/#{zone.name}"
|
71
|
+
rescue Splicer::Errors::RequestError => error
|
72
|
+
client.post "Zone/#{zone.name}"
|
73
|
+
end
|
74
|
+
|
75
|
+
zone.records.each do |record|
|
76
|
+
case record
|
77
|
+
when Splicer::Records::ARecord
|
78
|
+
update_or_create_record('ARecord', record, zone, rdata: { address: record.ip }, ttl: record.ttl)
|
79
|
+
when Splicer::Records::AAAARecord
|
80
|
+
update_or_create_record('AAAARecord', record, zone, rdata: { address: record.ip }, ttl: record.ttl)
|
81
|
+
when Splicer::Records::CNAMERecord
|
82
|
+
update_or_create_record('CNAMERecord', record, zone, rdata: { cname: record.cname }, ttl: record.ttl)
|
83
|
+
when Splicer::Records::MXRecord
|
84
|
+
update_or_create_record('MXRecord', record, zone, rdata: { exchange: record.exchanger, preference: record.priority }, ttl: record.ttl)
|
85
|
+
when Splicer::Records::NSRecord
|
86
|
+
update_or_create_record('NSRecord', record, zone, rdata: { nsdname: record.server }, ttl: record.ttl)
|
87
|
+
when Splicer::Records::PTRRecord
|
88
|
+
update_or_create_record('PTRRecord', record, zone,rdata: { ptrdname: record.host }, ttl: record.ttl)
|
89
|
+
when Splicer::Records::SPFRecord
|
90
|
+
update_or_create_record('SPFRecord', record, zone, rdata: { txtdata: record.text }, ttl: record.ttl)
|
91
|
+
when Splicer::Records::SRVRecord
|
92
|
+
update_or_create_record('SRVRecord', record, zone, rdata: { port: record.port, priority: record.priority, target: record.target, weight: record.weight }, ttl: record.ttl)
|
93
|
+
when Splicer::Records::TXTRecord
|
94
|
+
update_or_create_record('TXTRecord', record, zone, rdata: { txtdata: record.text }, ttl: record.ttl)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
client.put "Zone/#{zone.name}", publish: true
|
99
|
+
end
|
11
100
|
|
12
|
-
|
13
|
-
|
101
|
+
private
|
102
|
+
|
103
|
+
def update_or_create_record(resource, record, zone, data={})
|
104
|
+
begin
|
105
|
+
client.put(resource_url(resource, record, zone), data)
|
106
|
+
rescue Splicer::Errors::RequestError => error
|
107
|
+
create_record(resource, record, zone, data)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def create_record(resource, record, zone, data={})
|
112
|
+
client.post(resource_url(resource, record, zone), data)
|
113
|
+
end
|
14
114
|
|
15
|
-
|
115
|
+
def resource_url(resource, record, zone)
|
116
|
+
if record.name.nil?
|
117
|
+
"#{resource}/#{zone.name}/#{zone.name}"
|
118
|
+
else
|
119
|
+
"#{resource}/#{zone.name}/#{record.name}.#{zone.name}"
|
120
|
+
end
|
16
121
|
end
|
17
122
|
end
|
18
123
|
|
@@ -1,5 +1,52 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Splicer::Dynect::Provider do
|
4
|
-
|
4
|
+
let(:config) { Splicer::Dynect::Config.new('customer','user','password') }
|
5
|
+
let(:provider) { Splicer::Dynect::Provider.new(config) }
|
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 raise a Splicer::Errors::Error' do
|
48
|
+
expect { subject }.to raise_error(Splicer::Errors::Error, /something/)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
5
52
|
end
|
data/splicer-dynect.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["warmwaffles@gmail.com"]
|
11
11
|
spec.description = %q{The splicer adapter for interacting Dynect}
|
12
12
|
spec.summary = %q{The splicer adapter for interacting Dynect}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/zippykid/splicer-dynect"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -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')
|
21
|
+
spec.add_dependency('splicer', '~> 1.0')
|
22
22
|
spec.add_dependency('rest-client')
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: splicer-dynect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: splicer
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
21
|
+
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
29
|
+
version: '1.0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rest-client
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,7 +116,7 @@ files:
|
|
116
116
|
- spec/splicer/dynect/config_spec.rb
|
117
117
|
- spec/splicer/dynect/provider_spec.rb
|
118
118
|
- splicer-dynect.gemspec
|
119
|
-
homepage:
|
119
|
+
homepage: https://github.com/zippykid/splicer-dynect
|
120
120
|
licenses:
|
121
121
|
- MIT
|
122
122
|
post_install_message:
|
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
131
|
version: '0'
|
132
132
|
segments:
|
133
133
|
- 0
|
134
|
-
hash:
|
134
|
+
hash: 3802336838267731040
|
135
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
136
|
none: false
|
137
137
|
requirements:
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
segments:
|
142
142
|
- 0
|
143
|
-
hash:
|
143
|
+
hash: 3802336838267731040
|
144
144
|
requirements: []
|
145
145
|
rubyforge_project:
|
146
146
|
rubygems_version: 1.8.25
|