smart_proxy_dns_infoblox 0.0.4 → 0.0.6

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: f067a373f17dd6adba9aea33e3084c5e005d3b26
4
- data.tar.gz: 6e19878e4ac1cd475a30da5a23632cf35e245ab6
3
+ metadata.gz: 93913c19fdbb004b2265f61341b782c234eb4b7d
4
+ data.tar.gz: 063e1118acfb2a85593c2b774d382663239493dc
5
5
  SHA512:
6
- metadata.gz: 0f67055c0fb692c6380c6bcda4b1f56c046d9b39c5c526f80622256b9e31a937efa3c5485b14f9589890e85a2d8322e8f9a52df0d0c09aefd623cba28f0cc410
7
- data.tar.gz: 422837060375ce89e38fbedbf5f98ea48c515c21e2c961fb70d57a30391ea659bd9add9e3ab21eae78824dd0f189556ad08a974a4230241c716ee60edbf21efb
6
+ metadata.gz: 9fd8344ceffca0e6344b0ba7c2b86fd540df89fc2089f51e32d11e3179092f6dcf5137b46673c9a8e73a53acadd644bdc275bb8a32ca9412b661d64c22fea612
7
+ data.tar.gz: 90300ea7cc4e2083ed376fe7138c93e00352287847494ab020bbd0cc0eda8668d1be9138631cfc2d9c28fc03c049d00e19e30c5463dcdc68198ecb113e6e855b
@@ -1,2 +1,5 @@
1
1
  gem 'smart_proxy_dns_infoblox'
2
- gem 'infoblox'
2
+
3
+ group :dns_infoblox do
4
+ gem 'infoblox'
5
+ end
@@ -8,51 +8,74 @@ module Proxy::Dns::Infoblox
8
8
  super(host, ttl)
9
9
  end
10
10
 
11
- def create_a_record(fqdn, ip)
12
- case a_record_conflicts(fqdn, ip) #returns -1, 0, 1
13
- when 1
14
- raise(Proxy::Dns::Collision, "'#{fqdn} 'is already in use")
15
- when 0 then
16
- return nil
17
- else
18
- do_create(Infoblox::Arecord, :connection => connection, :name => fqdn, :ipv4addr => ip)
19
- end
11
+ def do_create(name, value, type)
12
+ method = "ib_create_#{type.downcase}_record".to_sym
13
+ raise(Proxy::Dns::Error, "Creation of #{type} records not implemented") unless respond_to?(method, true)
14
+ send(method, name, value)
20
15
  end
21
16
 
22
- def create_ptr_record(fqdn, ptr)
23
- case ptr_record_conflicts(fqdn, ptr_to_ip(ptr)) #returns -1, 0, 1
24
- when 1
25
- raise(Proxy::Dns::Collision, "'#{fqdn} 'is already in use")
26
- when 0 then
27
- return nil
28
- else
29
- do_create(Infoblox::Ptr, :connection => connection, :ptrdname => fqdn, :ipv4addr => ptr_to_ip(ptr))
30
- end
31
- # FIXME: add a reverse 'PTR' record with ip, fqdn
17
+ def do_remove(name, type)
18
+ method = "ib_remove_#{type.downcase}_record".to_sym
19
+ raise(Proxy::Dns::Error, "Deletion of #{type} records not implemented") unless respond_to?(method, true)
20
+ send(method, name)
32
21
  end
33
22
 
34
- def remove_a_record(fqdn)
35
- do_delete(Infoblox::Arecord.find(connection, :name => fqdn, :_max_results => 1).first, fqdn)
23
+ private
24
+
25
+ def ib_create_a_record(fqdn, address)
26
+ ib_create(Infoblox::Arecord, :name => fqdn, :ipv4addr => address)
36
27
  end
37
28
 
38
- def remove_ptr_record(ptr)
39
- ptr_record = Infoblox::Ptr.find(connection, :ipv4addr => ptr_to_ip(ptr), :_max_results => 1).first
40
- unless ptr_record.nil?
41
- ptr_record.ipv6addr = nil
42
- ptr_record.view = nil
43
- end
29
+ def ib_remove_a_record(fqdn)
30
+ ib_delete(Infoblox::Arecord, :name => fqdn)
31
+ end
44
32
 
45
- do_delete(ptr_record, ptr)
46
- # FIXME: remove the reverse 'PTR' record with ip
33
+ def ib_create_aaaa_record(fqdn, address)
34
+ ib_create(Infoblox::AAAArecord, :name => fqdn, :ipv6addr => address)
47
35
  end
48
36
 
49
- def do_create(clazz, params)
50
- clazz.new(params).post
37
+ def ib_remove_aaaa_record(fqdn)
38
+ ib_delete(Infoblox::AAAArecord, :name => fqdn)
51
39
  end
52
40
 
53
- def do_delete(record, id)
54
- raise Proxy::Dns::NotFound, "Cannot find DNS entry for #{id}" if record.nil?
55
- record.delete || (raise Proxy::Dns::NotFound, "Cannot find DNS entry for #{id}")
41
+ def ib_create_cname_record(fqdn, target)
42
+ ib_create(Infoblox::Cname, :name => fqdn, :canonical => target)
43
+ end
44
+
45
+ def ib_remove_cname_record(fqdn)
46
+ ib_delete(Infoblox::Cname, :name => fqdn)
47
+ end
48
+
49
+ def ib_create_ptr_record(ptr, fqdn)
50
+ ip = IPAddr.new(ptr_to_ip(ptr))
51
+
52
+ params = {
53
+ :ptrdname => fqdn,
54
+ :name => ptr
55
+ }
56
+ params["ipv#{ip.ipv4? ? 4 : 6}addr".to_sym] = ip.to_s
57
+
58
+ ib_create(Infoblox::Ptr, params)
59
+ end
60
+
61
+ def ib_remove_ptr_record(ptr)
62
+ ip = IPAddr.new(ptr_to_ip(ptr))
63
+
64
+ params = {}
65
+ params["ipv#{ip.ipv4? ? 4 : 6}addr".to_sym] = ip.to_s
66
+
67
+ ib_delete(Infoblox::Ptr, params)
68
+ end
69
+
70
+ def ib_create(clazz, params)
71
+ clazz.new({ :connection => connection }.merge(params)).post
72
+ end
73
+
74
+ def ib_delete(clazz, params)
75
+ record = clazz.find(connection, params.merge(:_max_results => 1)).first
76
+
77
+ raise Proxy::Dns::NotFound, "Cannot find #{clazz.class.name} entry for #{params}" if record.nil?
78
+ record.delete || (raise Proxy::Dns::NotFound, "Cannot find #{clazz.class.name} entry for #{params}")
56
79
  end
57
80
  end
58
81
  end
@@ -1,7 +1,7 @@
1
1
  module Proxy
2
2
  module Dns
3
3
  module Infoblox
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.6'
5
5
  end
6
6
  end
7
7
  end
@@ -10,35 +10,31 @@ class InfobloxTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def setup
13
- @connection = Object.new
14
- @record = DummyRecord.new
15
- @provider = Proxy::Dns::Infoblox::Record.new('a_host', @connection, 999)
13
+ @provider = Proxy::Dns::Infoblox::Record.new('a_host', nil, 999)
16
14
  end
17
15
 
18
16
  def test_create_a
19
17
  fqdn = 'test.example.com'
20
18
  ip = '10.1.1.1'
21
19
 
22
- @provider.expects(:a_record_conflicts).with(fqdn, ip).returns(-1)
23
- @provider.expects(:do_create).with(Infoblox::Arecord, :connection => @connection, :name => fqdn, :ipv4addr => ip)
24
-
25
- @provider.create_a_record(fqdn, ip)
20
+ @provider.expects(:ib_create).with(Infoblox::Arecord, :name => fqdn, :ipv4addr => ip)
21
+ @provider.do_create(fqdn, ip, 'A')
26
22
  end
27
23
 
28
- def test_create_a_conflicting_record
24
+ def test_create_aaaa
29
25
  fqdn = 'test.example.com'
30
- ip = '10.1.1.1'
26
+ ip = '2002:fc80::2'
31
27
 
32
- @provider.expects(:a_record_conflicts).with(fqdn, ip).returns(1)
33
- assert_raises(Proxy::Dns::Collision) { @provider.create_a_record(fqdn, ip) }
28
+ @provider.expects(:ib_create).with(Infoblox::AAAArecord, :name => fqdn, :ipv6addr => ip)
29
+ @provider.do_create(fqdn, ip, 'AAAA')
34
30
  end
35
31
 
36
- def test_create_a_already_exists
32
+ def test_create_cname
37
33
  fqdn = 'test.example.com'
38
- ip = '10.1.1.1'
34
+ target = 'test-2.example.com'
39
35
 
40
- @provider.expects(:a_record_conflicts).with(fqdn, ip).returns(0)
41
- assert_nil @provider.create_a_record(fqdn, ip)
36
+ @provider.expects(:ib_create).with(Infoblox::Cname, :name => fqdn, :canonical => target)
37
+ @provider.do_create(fqdn, target, 'CNAME')
42
38
  end
43
39
 
44
40
  def test_create_ptr
@@ -46,70 +42,53 @@ class InfobloxTest < Test::Unit::TestCase
46
42
  ptr = '1.1.1.10.in-addr.arpa'
47
43
  ip = '10.1.1.1'
48
44
 
49
- @provider.expects(:ptr_record_conflicts).with(fqdn, ip).returns(-1)
50
- @provider.expects(:do_create).with(Infoblox::Ptr, :connection => @connection, :ptrdname => fqdn, :ipv4addr => ip)
51
-
52
- @provider.create_ptr_record(fqdn, ptr)
45
+ @provider.expects(:ib_create).with(Infoblox::Ptr, :name => ptr, :ptrdname => fqdn, :ipv4addr => ip)
46
+ @provider.do_create(ptr, fqdn, 'PTR')
53
47
  end
54
48
 
55
- def test_create_ptr_conflicting_record
49
+ def test_create_ptr_v6
56
50
  fqdn = 'test.example.com'
57
- ptr = '1.1.1.10.in-addr.arpa'
58
- ip = '10.1.1.1'
51
+ ptr = '8.0.0.0.7.0.0.0.6.0.0.0.5.0.0.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.ip6.arpa'
52
+ ip = '1:2:3:4:5:6:7:8'
59
53
 
60
- @provider.expects(:ptr_record_conflicts).with(fqdn, ip).returns(1)
61
- assert_raises(Proxy::Dns::Collision) { @provider.create_ptr_record(fqdn, ptr) }
54
+ @provider.expects(:ib_create).with(Infoblox::Ptr, :name => ptr, :ptrdname => fqdn, :ipv6addr => ip)
55
+ @provider.do_create(ptr, fqdn, 'PTR')
62
56
  end
63
57
 
64
- def test_create_ptr_already_exists
58
+ def test_remove_a
65
59
  fqdn = 'test.example.com'
66
- ptr = '1.1.1.10.in-addr.arpa'
67
- ip = '10.1.1.1'
68
60
 
69
- @provider.expects(:ptr_record_conflicts).with(fqdn, ip).returns(0)
70
- assert_nil @provider.create_ptr_record(fqdn, ptr)
61
+ @provider.expects(:ib_delete).with(Infoblox::Arecord, :name => fqdn)
62
+ @provider.do_remove(fqdn, 'A')
71
63
  end
72
64
 
73
- def test_remove_a
65
+ def test_remove_aaaa
74
66
  fqdn = 'test.example.com'
75
- Infoblox::Arecord.expects(:find).with(@connection, :name => fqdn, :_max_results => 1).returns([@record])
76
- @record.expects(:delete).returns(true)
77
- @provider.remove_a_record(fqdn)
78
- end
79
67
 
80
- def test_remove_a_not_found
81
- fqdn = 'test.example.com'
82
- Infoblox::Arecord.expects(:find).with(@connection, :name => fqdn, :_max_results => 1).returns([])
83
- assert_raises(Proxy::Dns::NotFound) { @provider.remove_a_record(fqdn) }
68
+ @provider.expects(:ib_delete).with(Infoblox::AAAArecord, :name => fqdn)
69
+ @provider.do_remove(fqdn, 'AAAA')
84
70
  end
85
71
 
86
- def test_remove_a_returns_with_a_non_200_status
72
+ def test_remove_cname
87
73
  fqdn = 'test.example.com'
88
- Infoblox::Arecord.expects(:find).with(@connection, :name => fqdn, :_max_results => 1).returns([@record])
89
- @record.expects(:delete).returns(false)
90
- assert_raises(Proxy::Dns::NotFound) { @provider.remove_a_record(fqdn) }
74
+
75
+ @provider.expects(:ib_delete).with(Infoblox::Cname, :name => fqdn)
76
+ @provider.do_remove(fqdn, 'CNAME')
91
77
  end
92
78
 
93
79
  def test_remove_ptr
94
80
  ptr = '1.1.1.10.in-addr.arpa'
95
81
  ip = '10.1.1.1'
96
- Infoblox::Ptr.expects(:find).with(@connection, :ipv4addr => ip, :_max_results => 1).returns([@record])
97
- @record.expects(:delete).returns(true)
98
- @provider.remove_ptr_record(ptr)
99
- end
100
82
 
101
- def test_remove_ptr_not_found
102
- ptr = '1.1.1.10.in-addr.arpa'
103
- ip = '10.1.1.1'
104
- Infoblox::Ptr.expects(:find).with(@connection, :ipv4addr => ip, :_max_results => 1).returns([])
105
- assert_raises(Proxy::Dns::NotFound) { @provider.remove_ptr_record(ptr) }
83
+ @provider.expects(:ib_delete).with(Infoblox::Ptr, :ipv4addr => ip)
84
+ @provider.do_remove(ptr, 'PTR')
106
85
  end
107
86
 
108
- def test_remove_ptr_returns_with_a_non_200_status
109
- ptr = '1.1.1.10.in-addr.arpa'
110
- ip = '10.1.1.1'
111
- Infoblox::Ptr.expects(:find).with(@connection, :ipv4addr => ip, :_max_results => 1).returns([@record])
112
- @record.expects(:delete).returns(false)
113
- assert_raises(Proxy::Dns::NotFound) { @provider.remove_ptr_record(ptr) }
87
+ def test_remove_ptr_v6
88
+ ptr = '8.0.0.0.7.0.0.0.6.0.0.0.5.0.0.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.ip6.arpa'
89
+ ip = '1:2:3:4:5:6:7:8'
90
+
91
+ @provider.expects(:ib_delete).with(Infoblox::Ptr, :ipv6addr => ip)
92
+ @provider.do_remove(ptr, 'PTR')
114
93
  end
115
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dns_infoblox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Nicholson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-08 00:00:00.000000000 Z
11
+ date: 2017-07-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Infoblox DNS provider plugin for Foreman's smart proxy
14
14
  email:
@@ -29,9 +29,9 @@ files:
29
29
  - test/configuration_test.rb
30
30
  - test/infoblox_test.rb
31
31
  - test/test_helper.rb
32
- homepage: https://github.com/sjoeboo/smart_proxy_dns_infoblox
32
+ homepage: https://github.com/theforeman/smart_proxy_dns_infoblox
33
33
  licenses:
34
- - GPLv3
34
+ - GPL-3.0
35
35
  metadata: {}
36
36
  post_install_message:
37
37
  rdoc_options: []
@@ -49,11 +49,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  version: '0'
50
50
  requirements: []
51
51
  rubyforge_project:
52
- rubygems_version: 2.2.2
52
+ rubygems_version: 2.6.12
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: Infoblox DNS provider plugin for Foreman's smart proxy
56
56
  test_files:
57
- - test/configuration_test.rb
58
57
  - test/infoblox_test.rb
59
58
  - test/test_helper.rb
59
+ - test/configuration_test.rb