bind9mgr 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bind9mgr.rb +4 -1
- data/lib/parser.rb +3 -3
- data/lib/resource_record.rb +34 -6
- data/lib/zone.rb +1 -12
- data/spec/resource_record_spec.rb +18 -0
- metadata +5 -7
data/lib/bind9mgr.rb
CHANGED
@@ -6,10 +6,13 @@ require File.join( File.dirname(__FILE__), 'resource_record' )
|
|
6
6
|
require File.join( File.dirname(__FILE__), 'parser' )
|
7
7
|
|
8
8
|
module Bind9mgr
|
9
|
-
VERSION = '0.3.
|
9
|
+
VERSION = '0.3.3'
|
10
10
|
|
11
11
|
ZONES_BIND_SUBDIR = 'primary'
|
12
12
|
|
13
13
|
KLASSES = %w{IN CH}
|
14
14
|
ALLOWED_TYPES = %w{A CNAME MX TXT PTR NS SRV SOA}
|
15
|
+
|
16
|
+
class ParserError < RuntimeError; end
|
17
|
+
class MalformedResourceRecord < RuntimeError; end
|
15
18
|
end
|
data/lib/parser.rb
CHANGED
@@ -28,7 +28,7 @@ module Bind9mgr
|
|
28
28
|
[:type, :start, Proc.new{ |t| update_last_rr(nil, nil, nil, nil, t) }],
|
29
29
|
[:klass, :soa, Proc.new{ |t| t == 'SOA' ? update_last_rr(nil, nil, nil, t, nil) : false }],
|
30
30
|
[:soa, :start, Proc.new{ |t| rdata = [t] + @tokens.shift(7)
|
31
|
-
raise
|
31
|
+
raise ParserError, "Zone parsing error: parentices expected in SOA record.\n#{@content}" if (rdata[2] != '(') && (@tokens.first != ')')
|
32
32
|
rdata.delete_at(2)
|
33
33
|
@result.options[:support_email] = rdata[1]
|
34
34
|
@result.options[:serial] = rdata[2]
|
@@ -53,7 +53,7 @@ module Bind9mgr
|
|
53
53
|
token = @tokens.shift
|
54
54
|
# puts "state: #{@state}, token: #{token}"
|
55
55
|
possible_edges = @STATE_RULES.select{|arr|arr[0] == @state }
|
56
|
-
raise "no possible_edges. cur_state: #{@state}" if possible_edges.count < 1
|
56
|
+
raise( ParserError, "no possible_edges. cur_state: #{@state}" ) if possible_edges.count < 1
|
57
57
|
|
58
58
|
flag = false
|
59
59
|
while ( possible_edges.count > 0 ) && flag == false
|
@@ -65,7 +65,7 @@ module Bind9mgr
|
|
65
65
|
@state = current_edge[1] if flag
|
66
66
|
end
|
67
67
|
|
68
|
-
raise "no successful rules found. cur_state: #{@state}, token: #{token}" unless flag
|
68
|
+
raise( ParserError, "no successful rules found. cur_state: #{@state}, token: #{token}" ) unless flag
|
69
69
|
cntr += 1
|
70
70
|
end
|
71
71
|
|
data/lib/resource_record.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Bind9mgr
|
2
2
|
class ResourceRecord
|
3
3
|
attr_accessor :owner, :ttl, :klass, :type, :rdata
|
4
|
+
attr_reader :errors
|
4
5
|
|
5
6
|
def initialize owner = nil, ttl = nil, klass = nil, type = nil, rdata = nil
|
6
7
|
@owner = owner
|
@@ -10,13 +11,40 @@ module Bind9mgr
|
|
10
11
|
@rdata = rdata
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
# Validations
|
15
|
+
##
|
16
|
+
|
17
|
+
def valid?
|
18
|
+
@errors = []
|
19
|
+
(@errors << "Base type_and_rdata_shouldnt_be_blank"; return false) unless @type && @rdata
|
20
|
+
(@errors << "Owner invalid") if @owner && ( !@owner.kind_of?(String) || (@owner.length < 1) || (@owner.match(/^\d+$/)) || (@owner == 'localhost') )
|
21
|
+
(@errors << "Class invalid") if !klass.nil? && !KLASSES.include?( klass )
|
22
|
+
(@errors << "Type not_supported") unless ALLOWED_TYPES.include?( type )
|
23
|
+
|
24
|
+
validate_method_name = "validate_#{@type.downcase}"
|
25
|
+
|
26
|
+
self.class.send validate_method_name if self.class.respond_to?(validate_method_name)
|
27
|
+
|
28
|
+
return @errors.size == 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_a
|
32
|
+
@errors << "Base a record validation is under construction"
|
33
|
+
end
|
16
34
|
|
17
|
-
|
18
|
-
|
19
|
-
|
35
|
+
def validate_cname
|
36
|
+
@errors << "Base cname record validation is under construction"
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_mx
|
40
|
+
@errors << "Base mx record validation is under construction"
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Validations
|
45
|
+
|
46
|
+
def gen_rr_string
|
47
|
+
raise MalformedResourceRecord, "Owner:'#{@owner}', ttl:'#{@ttl}', class:'#{klass}', type:'#{type}', rdata:'#{rdata}'" unless self.valid?
|
20
48
|
|
21
49
|
if @type == 'SOA'
|
22
50
|
cont = ''
|
data/lib/zone.rb
CHANGED
@@ -1,16 +1,5 @@
|
|
1
1
|
module Bind9mgr
|
2
2
|
class Zone
|
3
|
-
RRClasses = ['IN', 'CH']
|
4
|
-
RRTypes = [ 'A',
|
5
|
-
'MX',
|
6
|
-
'SRV',
|
7
|
-
'CNAME',
|
8
|
-
'SOA',
|
9
|
-
'NS',
|
10
|
-
'TXT',
|
11
|
-
'PTR'
|
12
|
-
]
|
13
|
-
|
14
3
|
attr_accessor :default_ttl
|
15
4
|
attr_accessor :file, :options
|
16
5
|
attr_reader :records
|
@@ -74,7 +63,7 @@ module Bind9mgr
|
|
74
63
|
begin
|
75
64
|
p.parse File.read( @file )
|
76
65
|
rescue
|
77
|
-
raise
|
66
|
+
raise ParserError, "Parser error. File: #{@file.inspect}.\nError: #{$!.to_s}\n#{$!.backtrace.join("\n")}"
|
78
67
|
end
|
79
68
|
end
|
80
69
|
|
@@ -29,6 +29,24 @@ describe Bind9mgr::ResourceRecord do
|
|
29
29
|
@rr.should respond_to( :gen_rr_string )
|
30
30
|
end
|
31
31
|
|
32
|
+
it "should raise error when wrong record exists on gen_rr_string" do
|
33
|
+
expect { @rr.gen_rr_string }.to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should fill errors array with something on validation" do
|
37
|
+
@rr.should_not be_valid
|
38
|
+
@rr.errors.size.should > 0
|
39
|
+
puts @rr.errors
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not raise error when valid record exists on gen_rr_string" do
|
43
|
+
@rr.owner = '@'
|
44
|
+
@rr.type = 'A'
|
45
|
+
@rr.rdata = '123.123.123.123'
|
46
|
+
|
47
|
+
expect { @rr.gen_rr_string }.not_to raise_error
|
48
|
+
end
|
49
|
+
|
32
50
|
it "shoult have a list of allowed rr types" do
|
33
51
|
Bind9mgr::ALLOWED_TYPES.should be_kind_of(Array)
|
34
52
|
Bind9mgr::ALLOWED_TYPES.count.should > 0
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bind9mgr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-10-05 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: hoe
|
17
|
-
requirement: &
|
16
|
+
requirement: &24264520 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ~>
|
@@ -22,7 +21,7 @@ dependencies:
|
|
22
21
|
version: '2.12'
|
23
22
|
type: :development
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *24264520
|
26
25
|
description: This gem contains some classes to manage bind9 zone files
|
27
26
|
email:
|
28
27
|
- mikhail@mad-box.ru
|
@@ -51,7 +50,6 @@ files:
|
|
51
50
|
- spec/parser_spec.rb
|
52
51
|
- spec/resource_record_spec.rb
|
53
52
|
- .gemtest
|
54
|
-
has_rdoc: true
|
55
53
|
homepage: https://github.com/madbox/bind9mgr
|
56
54
|
licenses: []
|
57
55
|
post_install_message:
|
@@ -74,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
72
|
version: '0'
|
75
73
|
requirements: []
|
76
74
|
rubyforge_project: bind9mgr
|
77
|
-
rubygems_version: 1.
|
75
|
+
rubygems_version: 1.8.10
|
78
76
|
signing_key:
|
79
77
|
specification_version: 3
|
80
78
|
summary: This gem contains some classes to manage bind9 zone files
|