smart_proxy_dns_route53 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9425c48e0e02858ba2c5fc8745b0b7412a432895
4
- data.tar.gz: d53e7bace7f3b919c0ae85cc03d3d487ddb012a1
3
+ metadata.gz: afc68be7898dff76e610ac85e992e403f86d6c92
4
+ data.tar.gz: e88894baa652431ea063b23287c9f9ff909da377
5
5
  SHA512:
6
- metadata.gz: 412561d3bfde71176d188c4208bfa1a7a1d78e60afbfe1a015de485178b4028ada0c7a1993146feb7243290c041296480896385cff6e6522e7116e0ca6cfe3a0
7
- data.tar.gz: c7af876d6513e401d1be94f3c669374904470f44860e565f361e3d3656c6328c0df3d70b8398401b3a4ddf379403a7eb96bd29df3d8a41c9296ec874a026c405
6
+ metadata.gz: 64b97a5cbfd2150c4df89b57d86acc26b07c10cc4ca6f630f39533bbfe35ad3e417bf39e998f60b5ec64726fcd7319e5555b3ae05a62c8ca2bac5b11a86dc12b
7
+ data.tar.gz: 39da40207db0a7083db676da32b085edb38b53c7a63f528a92638c5c4304521995d5e48cdc8210cdf70db5079b4805f4318cd5c64b6618f7eabac2b7fc7b8750
data/README.md CHANGED
@@ -1,13 +1,18 @@
1
- # SmartProxyDnsRoute53
1
+ # Route 53 smart proxy plugin
2
2
 
3
- This plugin adds a new DNS provider for managing records in Amazon's Route53 service.
3
+ This plugin adds a new DNS provider for managing records in Amazon's Route 53 service.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  See [How_to_Install_a_Smart-Proxy_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Smart-Proxy_Plugin)
8
8
  for how to install Smart Proxy plugins
9
9
 
10
- This plugin is compatible with Smart Proxy 1.10 or higher.
10
+ ## Compatibility
11
+
12
+ | Smart Proxy Version | Plugin Version |
13
+ | ------------------- | --------------:|
14
+ | >= 1.10, < 1.11 | ~> 1.0 |
15
+ | >= 1.11 | ~> 2.0 |
11
16
 
12
17
  ## Configuration
13
18
 
@@ -15,7 +20,7 @@ To enable this DNS provider, edit `/etc/foreman-proxy/settings.d/dns.yml` and se
15
20
 
16
21
  :use_provider: dns_route53
17
22
 
18
- You will need an active Amazon Web Services account and to create a new IAM account with access to manage Route53 for the Smart Proxy plugin to work.
23
+ You will need an active Amazon Web Services account and to create a new IAM account with access to manage Route 53 for the Smart Proxy plugin to work.
19
24
 
20
25
  Configuration options for this plugin are in `/etc/foreman-proxy/settings.d/dns_route53.yml` and include:
21
26
 
@@ -1,4 +1,5 @@
1
1
  require 'dns/dns'
2
+ require 'dns_common/dns_common'
2
3
  require 'resolv'
3
4
  require 'route53'
4
5
 
@@ -9,92 +10,72 @@ module Proxy::Dns::Route53
9
10
 
10
11
  attr_reader :aws_access_key, :aws_secret_key
11
12
 
12
- def self.record(attrs = {})
13
- new(attrs.merge(
14
- :aws_access_key => ::Proxy::Dns::Route53::Plugin.settings.aws_access_key,
15
- :aws_secret_key => ::Proxy::Dns::Route53::Plugin.settings.aws_secret_key
16
- ))
13
+ def initialize(a_server = nil, a_ttl = nil)
14
+ @aws_access_key = Proxy::Dns::Route53::Plugin.settings.aws_access_key
15
+ @aws_secret_key = Proxy::Dns::Route53::Plugin.settings.aws_secret_key
16
+ super(a_server, a_ttl || ::Proxy::Dns::Plugin.settings.dns_ttl)
17
17
  end
18
18
 
19
- def initialize options = {}
20
- @aws_access_key = options[:aws_access_key]
21
- @aws_secret_key = options[:aws_secret_key]
22
- raise "dns_route53 provider needs AWS access and secret key options" unless aws_access_key && aws_secret_key
23
- super(options)
19
+ def create_a_record(fqdn, ip)
20
+ if found = dns_find(fqdn)
21
+ raise(Proxy::Dns::Collision, "#{fqdn} is already used by #{ip}") unless found == ip
22
+ else
23
+ zone = get_zone(fqdn)
24
+ new_record = Route53::DNSRecord.new(fqdn, 'A', ttl, [ip], zone)
25
+ resp = new_record.create
26
+ raise "AWS Response Error: #{resp}" if resp.error?
27
+ true
28
+ end
29
+ end
30
+
31
+ def create_ptr_record(fqdn, ip)
32
+ if found = dns_find(ip)
33
+ raise(Proxy::Dns::Collision, "#{ip} is already used by #{found}") unless found == fqdn
34
+ else
35
+ zone = get_zone(ip)
36
+ new_record = Route53::DNSRecord.new(ip, 'PTR', ttl, [fqdn], zone)
37
+ resp = new_record.create
38
+ raise "AWS Response Error: #{resp}" if resp.error?
39
+ true
40
+ end
24
41
  end
25
42
 
26
- def create
27
- case @type
28
- when "A"
29
- if ip = dns_find(@fqdn)
30
- raise(Proxy::Dns::Collision, "#{@fqdn} is already used by #{ip}") unless ip == @value
31
- else
32
- zone = get_zone(@fqdn)
33
- new_record = Route53::DNSRecord.new(@fqdn, 'A', @ttl, [@value], zone)
34
- resp = new_record.create
35
- raise "AWS Response Error: #{resp}" if resp.error?
36
- true
37
- end
38
- when "PTR"
39
- if name = dns_find(@value)
40
- raise(Proxy::Dns::Collision, "#{@value} is already used by #{name}") unless name == @fqdn
41
- else
42
- zone = get_zone(@value)
43
- new_record = Route53::DNSRecord.new(@value, 'PTR', @ttl, [@fqdn], zone)
44
- resp = new_record.create
45
- raise "AWS Response Error: #{resp}" if resp.error?
46
- true
47
- end
43
+ def remove_a_record(fqdn)
44
+ zone = get_zone(fqdn)
45
+ recordset = zone.get_records
46
+ recordset.each do |rec|
47
+ if rec.name == fqdn + '.'
48
+ resp = rec.delete
49
+ raise "AWS Response Error: #{resp}" if resp.error?
50
+ return true
51
+ end
48
52
  end
53
+ raise Proxy::Dns::NotFound, "Could not find forward record #{fqdn}"
49
54
  end
50
55
 
51
- def remove
52
- case @type
53
- when "A"
54
- zone = get_zone(@fqdn)
55
- recordset = zone.get_records
56
- recordset.each do |rec|
57
- if rec.name == @fqdn + '.'
58
- resp = rec.delete
59
- raise "AWS Response Error: #{resp}" if resp.error?
60
- return true
61
- end
62
- end
63
- raise Proxy::Dns::NotFound, "Could not find forward record #{@fqdn}"
64
- when "PTR"
65
- zone = get_zone(@value)
66
- recordset = zone.get_records
67
- recordset.each do |rec|
68
- if rec.name == @value + '.'
69
- resp = rec.delete
70
- raise "AWS Response Error: #{resp}" if resp.error?
71
- return true
72
- end
73
- end
74
- raise Proxy::Dns::NotFound, "Could not find reverse record #{@value}"
56
+ def remove_ptr_record(ip)
57
+ zone = get_zone(ip)
58
+ recordset = zone.get_records
59
+ recordset.each do |rec|
60
+ if rec.name == ip + '.'
61
+ resp = rec.delete
62
+ raise "AWS Response Error: #{resp}" if resp.error?
63
+ return true
64
+ end
75
65
  end
66
+ raise Proxy::Dns::NotFound, "Could not find reverse record #{ip}"
76
67
  end
77
68
 
78
69
  private
79
70
 
80
71
  def conn
81
- @conn ||= Route53::Connection.new(@aws_access_key, @aws_secret_key)
72
+ @conn ||= Route53::Connection.new(aws_access_key, aws_secret_key)
82
73
  end
83
74
 
84
75
  def resolver
85
76
  @resolver ||= Resolv::DNS.new
86
77
  end
87
78
 
88
- def dns_find key
89
- if match = key.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/)
90
- resolver.getname(match[1..4].reverse.join(".")).to_s
91
- else
92
- resolver.getaddress(key).to_s
93
- end
94
- rescue Resolv::ResolvError
95
- false
96
- end
97
-
98
79
  def get_zone(fqdn)
99
80
  domain = fqdn.split('.', 2).last + '.'
100
81
  conn.get_zones(domain)[0]
@@ -2,13 +2,15 @@ require 'smart_proxy_dns_route53/dns_route53_version'
2
2
 
3
3
  module Proxy::Dns::Route53
4
4
  class Plugin < ::Proxy::Provider
5
- plugin :dns_route53, ::Proxy::Dns::Route53::VERSION,
6
- :factory => proc { |attrs| ::Proxy::Dns::Route53::Record.record(attrs) }
5
+ plugin :dns_route53, ::Proxy::Dns::Route53::VERSION
7
6
 
8
- requires :dns, '>= 1.10'
7
+ requires :dns, '>= 1.11'
8
+
9
+ validate_presence :aws_access_key, :aws_secret_key
9
10
 
10
11
  after_activation do
11
12
  require 'smart_proxy_dns_route53/dns_route53_main'
13
+ require 'smart_proxy_dns_route53/route53_dependencies'
12
14
  end
13
15
  end
14
16
  end
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module Dns
3
3
  module Route53
4
- VERSION = '1.0.0'
4
+ VERSION = '2.0.0'
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,5 @@
1
+ require 'dns_common/dependency_injection/dependencies'
2
+
3
+ class Proxy::Dns::DependencyInjection::Dependencies
4
+ dependency :dns_provider, Proxy::Dns::Route53::Record
5
+ end
@@ -1,97 +1,92 @@
1
1
  require 'test_helper'
2
2
 
3
+ require 'smart_proxy_dns_route53/dns_route53_plugin'
3
4
  require 'smart_proxy_dns_route53/dns_route53_main'
4
5
 
5
6
  class DnsRoute53RecordTest < Test::Unit::TestCase
6
- # Test that a missing :example_setting throws an error
7
- def test_initialize_without_settings
8
- assert_raise(RuntimeError) do
9
- klass.new(settings.delete_if { |k,v| k == :aws_secret_key || k == :aws_access_key })
10
- end
11
- end
12
-
13
7
  # Test that correct initialization works
14
- def test_initialize_with_settings
15
- assert_nothing_raised do
16
- klass.new(settings)
17
- end
8
+ def test_provider_initialization
9
+ Proxy::Dns::Route53::Plugin.load_test_settings(:aws_access_key => 'foo', :aws_secret_key => 'bar')
10
+ provider = klass.new
11
+ assert_equal 'foo', provider.aws_access_key
12
+ assert_equal 'bar', provider.aws_secret_key
18
13
  end
19
14
 
20
15
  # Test A record creation
21
16
  def test_create_a
22
- record = klass.new(settings)
17
+ record = klass.new
23
18
  record.expects(:dns_find).returns(false)
24
19
 
25
20
  zone = mock()
26
21
  record.expects(:get_zone).with('test.example.com').returns(zone)
27
22
 
28
23
  dnsrecord = mock(:create => mock(:error? => false))
29
- Route53::DNSRecord.expects(:new).with('test.example.com', 'A', '86400', ['10.1.1.1'], zone).returns(dnsrecord)
24
+ Route53::DNSRecord.expects(:new).with('test.example.com', 'A', 86400, ['10.1.1.1'], zone).returns(dnsrecord)
30
25
 
31
- assert record.create
26
+ assert record.create_a_record(fqdn, ip)
32
27
  end
33
28
 
34
29
  # Test A record creation fails if the record exists
35
30
  def test_create_a_conflict
36
- record = klass.new(settings)
31
+ record = klass.new
37
32
  record.expects(:dns_find).returns('10.2.2.2')
38
- assert_raise(Proxy::Dns::Collision) { record.create }
33
+ assert_raise(Proxy::Dns::Collision) { record.create_a_record(fqdn, ip) }
39
34
  end
40
35
 
41
36
  # Test PTR record creation
42
37
  def test_create_ptr
43
- record = klass.new(settings.merge(:type => 'PTR'))
38
+ record = klass.new
44
39
  record.expects(:dns_find).returns(false)
45
40
 
46
41
  zone = mock()
47
42
  record.expects(:get_zone).with('10.1.1.1').returns(zone)
48
43
 
49
44
  dnsrecord = mock(:create => mock(:error? => false))
50
- Route53::DNSRecord.expects(:new).with('10.1.1.1', 'PTR', '86400', ['test.example.com'], zone).returns(dnsrecord)
45
+ Route53::DNSRecord.expects(:new).with('10.1.1.1', 'PTR', 86400, ['test.example.com'], zone).returns(dnsrecord)
51
46
 
52
- assert record.create
47
+ assert record.create_ptr_record(fqdn, ip)
53
48
  end
54
49
 
55
50
  # Test PTR record creation fails if the record exists
56
51
  def test_create_ptr_conflict
57
- record = klass.new(settings.merge(:type => 'PTR'))
52
+ record = klass.new
58
53
  record.expects(:dns_find).returns('else.example.com')
59
- assert_raise(Proxy::Dns::Collision) { record.create }
54
+ assert_raise(Proxy::Dns::Collision) { record.create_ptr_record(fqdn, ip) }
60
55
  end
61
56
 
62
57
  # Test A record removal
63
58
  def test_remove_a
64
59
  zone = mock(:get_records => [mock(:name => 'test.example.com.', :delete => mock(:error? => false))])
65
- record = klass.new(settings)
60
+ record = klass.new
66
61
  record.expects(:get_zone).with('test.example.com').returns(zone)
67
- assert record.remove
62
+ assert record.remove_a_record(fqdn)
68
63
  end
69
64
 
70
65
  # Test A record removal fails if the record doesn't exist
71
66
  def test_remove_a_not_found
72
- record = klass.new(settings)
67
+ record = klass.new
73
68
  record.expects(:get_zone).with('test.example.com').returns(mock(:get_records => []))
74
- assert_raise(Proxy::Dns::NotFound) { assert record.remove }
69
+ assert_raise(Proxy::Dns::NotFound) { assert record.remove_a_record(fqdn) }
75
70
  end
76
71
 
77
72
  # Test PTR record removal
78
73
  def test_remove_ptr
79
74
  # FIXME: record name seems incorrect for rDNS
80
75
  zone = mock(:get_records => [mock(:name => '10.1.1.1.', :delete => mock(:error? => false))])
81
- record = klass.new(settings.merge(:type => 'PTR'))
76
+ record = klass.new
82
77
  record.expects(:get_zone).with('10.1.1.1').returns(zone)
83
- assert record.remove
78
+ assert record.remove_ptr_record(ip)
84
79
  end
85
80
 
86
81
  # Test PTR record removal fails if the record doesn't exist
87
82
  def test_remove_ptr_not_found
88
- record = klass.new(settings.merge(:type => 'PTR'))
83
+ record = klass.new
89
84
  record.expects(:get_zone).with('10.1.1.1').returns(mock(:get_records => []))
90
- assert_raise(Proxy::Dns::NotFound) { assert record.remove }
85
+ assert_raise(Proxy::Dns::NotFound) { assert record.remove_ptr_record(ip) }
91
86
  end
92
87
 
93
88
  def test_get_zone_forward
94
- record = klass.new(settings)
89
+ record = klass.new
95
90
  conn = mock()
96
91
  conn.expects(:get_zones).with('example.com.').returns([:zone])
97
92
  record.expects(:conn).returns(conn)
@@ -99,7 +94,7 @@ class DnsRoute53RecordTest < Test::Unit::TestCase
99
94
  end
100
95
 
101
96
  def test_get_zone_reverse
102
- record = klass.new(settings)
97
+ record = klass.new
103
98
  conn = mock()
104
99
  conn.expects(:get_zones).with('1.1.1.').returns([:zone]) # FIXME, incorrect rDNS zone
105
100
  record.expects(:conn).returns(conn)
@@ -107,7 +102,7 @@ class DnsRoute53RecordTest < Test::Unit::TestCase
107
102
  end
108
103
 
109
104
  def test_dns_find_forward
110
- record = klass.new(settings)
105
+ record = klass.new
111
106
  resolver = mock()
112
107
  resolver.expects(:getaddress).with('test.example.com').returns('10.1.1.1')
113
108
  record.expects(:resolver).returns(resolver)
@@ -115,7 +110,7 @@ class DnsRoute53RecordTest < Test::Unit::TestCase
115
110
  end
116
111
 
117
112
  def test_dns_find_forward_not_found
118
- record = klass.new(settings)
113
+ record = klass.new
119
114
  resolver = mock()
120
115
  resolver.expects(:getaddress).with('test.example.com').raises(Resolv::ResolvError)
121
116
  record.expects(:resolver).returns(resolver)
@@ -123,7 +118,7 @@ class DnsRoute53RecordTest < Test::Unit::TestCase
123
118
  end
124
119
 
125
120
  def test_dns_find_reverse
126
- record = klass.new(settings)
121
+ record = klass.new
127
122
  resolver = mock()
128
123
  resolver.expects(:getname).with('3.2.1.10').returns('test.example.com')
129
124
  record.expects(:resolver).returns(resolver)
@@ -131,7 +126,7 @@ class DnsRoute53RecordTest < Test::Unit::TestCase
131
126
  end
132
127
 
133
128
  def test_dns_find_reverse_not_found
134
- record = klass.new(settings)
129
+ record = klass.new
135
130
  resolver = mock()
136
131
  resolver.expects(:getname).with('3.2.1.10').raises(Resolv::ResolvError)
137
132
  record.expects(:resolver).returns(resolver)
@@ -144,13 +139,11 @@ class DnsRoute53RecordTest < Test::Unit::TestCase
144
139
  Proxy::Dns::Route53::Record
145
140
  end
146
141
 
147
- def settings
148
- {
149
- :aws_access_key => 'foo',
150
- :aws_secret_key => 'bar',
151
- :fqdn => 'test.example.com',
152
- :value => '10.1.1.1',
153
- :type => 'A'
154
- }
142
+ def fqdn
143
+ 'test.example.com'
144
+ end
145
+
146
+ def ip
147
+ '10.1.1.1'
155
148
  end
156
149
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dns_route53
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Foreman developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: route53
@@ -26,6 +26,20 @@ dependencies:
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: '11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: mocha
56
+ name: test-unit
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -52,7 +66,7 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
- description: Route53 DNS provider plugin for Foreman's smart proxy
69
+ description: Route 53 DNS provider plugin for Foreman's smart proxy
56
70
  email:
57
71
  - foreman-dev@googlegroups.com
58
72
  executables: []
@@ -67,6 +81,7 @@ files:
67
81
  - lib/smart_proxy_dns_route53/dns_route53_main.rb
68
82
  - lib/smart_proxy_dns_route53/dns_route53_plugin.rb
69
83
  - lib/smart_proxy_dns_route53/dns_route53_version.rb
84
+ - lib/smart_proxy_dns_route53/route53_dependencies.rb
70
85
  - test/dns_route53_record_test.rb
71
86
  - test/test_helper.rb
72
87
  homepage: https://github.com/theforeman/smart_proxy_dns_route53
@@ -92,7 +107,7 @@ rubyforge_project:
92
107
  rubygems_version: 2.2.1
93
108
  signing_key:
94
109
  specification_version: 4
95
- summary: Route53 DNS provider plugin for Foreman's smart proxy
110
+ summary: Route 53 DNS provider plugin for Foreman's smart proxy
96
111
  test_files:
97
112
  - test/dns_route53_record_test.rb
98
113
  - test/test_helper.rb