bind9mgr 0.2.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,10 @@
1
- === 1.0.0 / 2011-09-09
1
+ === 0.0.0 / 2011-09-09
2
2
 
3
3
  * 1 major enhancement
4
4
 
5
5
  * Birthday!
6
6
 
7
+ === 0.2.6 / 2011-09-14
8
+
9
+ * don't fail if there is missing zone db files
10
+ * specs update
data/README.txt CHANGED
@@ -1,12 +1,28 @@
1
1
  = bind9mgr
2
2
 
3
+ https://github.com/madbox/bind9mgr
4
+ https://rubygems.org/gems/bind9mgr
5
+
3
6
  == DESCRIPTION:
4
7
 
5
8
  This gem contains some classes to manage bind9 zone files
6
9
 
7
10
  == FEATURES/PROBLEMS:
8
11
 
9
- Please look into specs
12
+ Features:
13
+ * zone db file parseing
14
+ * named.conf simple parser
15
+ * OO data organization
16
+ * Simple verifications
17
+ * add zone intaeface
18
+ * delete zone interface
19
+ * automatic zone options management (origin, default NS, default A, "www" CNAME etc)
20
+
21
+ Please look into specs for more detailed info.
22
+
23
+ TODO: more configuration features
24
+ TODO: more conventions(feedback welcomed!)
25
+ TODO: xml mappings for restful APIs
10
26
 
11
27
  == SYNOPSIS:
12
28
 
@@ -20,6 +36,9 @@ Please look into specs
20
36
  bc.zones # => [ existing zones ... Bind9mgr::Zone ]
21
37
  bc.zones.first.records # => [ records ... Bind9mgr::ResourceRecord ]
22
38
 
39
+ bc.add_zone('y_a_zone.org') # adds zone entry with default params
40
+ bc.write_all # rewrites named.conf.local and zone db files (in /etc/bind/zones_db.)
41
+ bc.del_zone!('y_a_zone.org') # immidiately removes db file and zone entry in named.conf.local
23
42
 
24
43
  == REQUIREMENTS:
25
44
 
data/lib/bind9mgr.rb CHANGED
@@ -6,9 +6,9 @@ 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.2.4'
9
+ VERSION = '0.2.6'
10
10
 
11
- ZONES_BIND_SUBDIR = 'zones_db'
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}
data/lib/named_conf.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Bind9mgr
2
2
  # You can specify bind_location. If you do so then .add_zone method
3
3
  # will generate zones with right filenames.
4
+ # If .file
4
5
  class NamedConf
5
6
  # BIND_PATH = '/etc/bind'
6
7
  # BIND_DB_PATH = BIND_PATH + '/master'
@@ -13,15 +14,26 @@ module Bind9mgr
13
14
  @bind_location = File.dirname(file) if file.length > 1
14
15
  load
15
16
  end
16
-
17
+
18
+ def file= str
19
+ raise ArgumentError, "String expected" unless str.kind_of? String
20
+ @file = str
21
+ end
22
+
23
+ # Tries to load data from named conf. Raises exception if file missing.
24
+ def load!
25
+ init_zones
26
+ parse File.read( @file ) if file.length > 0
27
+ end
28
+
29
+ # Tries to load data from named conf. Do nothing if file missing.
17
30
  def load
18
31
  init_zones
19
- parse File.read( File.join( @file )) if File.exists? file
32
+ parse File.read( @file ) if File.exists?(@file)
20
33
  end
21
34
 
22
35
  def load_with_zones
23
- init_zones
24
- parse File.read( File.join( @file )) if File.exists? file
36
+ load
25
37
  zones.each{ |z| z.load}
26
38
  end
27
39
 
data/lib/zone.rb CHANGED
@@ -49,42 +49,18 @@ module Bind9mgr
49
49
 
50
50
  def load
51
51
  raise ArgumentError, "file not specified" unless @file
52
+
53
+
54
+ # TODO what should we do if there is no db file?
55
+ # raise ArgumentError, "File: #{file} not found." unless File.exists?( @file )
56
+ # just emulate parsing of empty file
57
+ return 0 unless File.exists?( @file )
52
58
 
53
59
  p = Parser.new
54
60
  p.result = self
55
- raise ArgumentError, "File: #{file} not found." unless File.exists?( @file )
56
61
  p.parse File.read( @file )
57
62
  end
58
63
 
59
- # def parse content
60
- # clear_records
61
- # content.gsub!(/^\s+\n/, '')
62
-
63
- # # find and remove SOA record with its comments
64
- # soa = /([^\s]*?)\s+?(\d+?)?\s*?(#{RRClasses.join('|')})\s*?(SOA)\s+(.*?\).*?)\n/m
65
- # arr = content.match(soa).to_a
66
- # arr.shift
67
- # @records['SOA'].push arr
68
- # content.sub! soa, ''
69
-
70
- # # remove comments and blank lines
71
- # content.gsub!(/;.*$/, '')
72
- # content.gsub!(/^\s+\n/, '')
73
-
74
- # # other @Records
75
- # rr = /^([^\s]+)\s+?(\d+?)?\s*?(#{RRClasses.join('|')})?\s*?(#{RRTypes.join('|')})\s+(.*?)$/
76
- # content.lines.each do |l|
77
- # if md = l.match(/\$TTL\s+(\d+)/)
78
- # ( @default_ttl = md[1].to_i ) if md[1].to_i > 0
79
- # elsif md = l.match(rr)
80
- # tmp_a = md.to_a
81
- # tmp_a.shift
82
- # @records[tmp_a[3]].push tmp_a
83
- # end
84
- # end
85
- # @records
86
- # end
87
-
88
64
  def gen_db_content
89
65
  initialized?
90
66
  raise ArgumentError, "default_ttl not secified" unless @default_ttl
@@ -23,6 +23,18 @@ zone "cloud.ru" {
23
23
  file "testdomain.com.db";
24
24
  };
25
25
 
26
+ zone "1.168.192.in-addr.arpa" {
27
+ type master;
28
+ file "testdomain.com.db";
29
+ };
30
+ }
31
+
32
+ @test_wrong_conf_content = %q{// test file
33
+ zone "cloud.ru" {
34
+ type master;
35
+ file "there_is_no_such_file.com.db";
36
+ };
37
+
26
38
  zone "1.168.192.in-addr.arpa" {
27
39
  type master;
28
40
  file "testdomain.com.db";
@@ -49,6 +61,7 @@ alias1 IN CNAME ns
49
61
  File.stub(:exists?).with("testfile.conf").and_return(true)
50
62
  File.stub(:exists?).with("testdomain.com.db").and_return(true)
51
63
 
64
+ File.stub(:read).with(anything()).and_raise(Errno::ENOENT.new("File.read stubbed. You trying to read unexpected file."))
52
65
  File.stub(:read).with("testfile.conf").and_return(@test_conf_content)
53
66
  File.stub(:read).with("testdomain.com.db").and_return(@test_db_content)
54
67
 
@@ -117,6 +130,14 @@ alias1 IN CNAME ns
117
130
  @nc.zones.should be_empty()
118
131
  end
119
132
 
133
+ it "should raise error if you try to assign non-String object to file" do
134
+ expect{ @nc.file = nil }.to raise_error(ArgumentError)
135
+ expect{ @nc.file = 1 }.to raise_error(ArgumentError)
136
+ expect{ @nc.file = '' }.not_to raise_error(ArgumentError)
137
+ expect{ @nc.file = 'qwe' }.not_to raise_error(ArgumentError)
138
+ end
139
+
140
+
120
141
  it "should have an empty array of zones on instantiation without conf file" do
121
142
  nc = Bind9mgr::NamedConf.new
122
143
  nc.zones.should be_empty()
@@ -144,4 +165,24 @@ alias1 IN CNAME ns
144
165
  pending "should automatically generate file name for zone db if not supplied"
145
166
  pending "should automatically make dir for zone db files"
146
167
  pending "should have methods to edit SOA values"
168
+
169
+ it "'load!' should raise error if named conf file is missing" do
170
+ @nc.file = "missing.file"
171
+ expect{ @nc.load! }.to raise_error
172
+ end
173
+
174
+ it "'load' should not raise error if named conf file is missing" do
175
+ @nc.file = "missing.file"
176
+ expect{ @nc.load }.not_to raise_error
177
+ end
178
+
179
+ it "should not fail to load configuration when there is no zone db file" do
180
+ # named conf file with not existing zone db file
181
+ File.stub(:exists?).with("testwrongfile.conf").and_return(true)
182
+ File.stub(:read).with("testwrongfile.conf").and_return(@test_wrong_conf_content)
183
+ @nc.file = "testwrongfile.conf"
184
+
185
+ expect{ @nc.load }.not_to raise_error
186
+ expect{ @nc.load_with_zones }.not_to raise_error
187
+ end
147
188
  end
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.2.4
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-12 00:00:00.000000000 +04:00
12
+ date: 2011-09-15 00:00:00.000000000 +04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hoe
17
- requirement: &9505680 !ruby/object:Gem::Requirement
17
+ requirement: &21035760 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '2.12'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *9505680
25
+ version_requirements: *21035760
26
26
  description: This gem contains some classes to manage bind9 zone files
27
27
  email:
28
28
  - mikhail@mad-box.ru
@@ -52,7 +52,7 @@ files:
52
52
  - spec/resource_record_spec.rb
53
53
  - .gemtest
54
54
  has_rdoc: true
55
- homepage:
55
+ homepage: https://github.com/madbox/bind9mgr
56
56
  licenses: []
57
57
  post_install_message:
58
58
  rdoc_options: