junos-config 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = junos-config
2
2
 
3
- Description goes here.
3
+ Parser for Junos (Juniper network gear OS) config files.
4
4
 
5
5
  == Contributing to junos-config
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{junos-config}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["John Wulff"]
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
29
29
  "lib/junos-config.rb",
30
30
  "lib/junos-config/config.rb",
31
31
  "lib/junos-config/interface.rb",
32
+ "lib/junos-config/security/policy.rb",
33
+ "lib/junos-config/security/zone.rb",
32
34
  "spec/junos-config_spec.rb",
33
35
  "spec/sample_configs/sample_1",
34
36
  "spec/spec_helper.rb"
@@ -1,2 +1,4 @@
1
+ require 'junos-config/security/policy'
2
+ require 'junos-config/security/zone'
1
3
  require 'junos-config/interface'
2
4
  require 'junos-config/config'
@@ -1,20 +1,36 @@
1
1
  module JunosConfig
2
2
  class Config
3
- attr_reader :config,
4
- :interfaces
3
+ attr_reader :raw,
4
+ :interfaces,
5
+ :security_zones,
6
+ :security_policies
5
7
 
6
- def initialize(config)
7
- @config = config
8
- config.scan(/^(\w+)\ \{$(.*?)^\}$/m).each do |section|
8
+ def initialize(raw)
9
+ @raw = raw
10
+ raw.scan(/^(\w+)\ \{$(.*?)^\}$/m).each do |section|
9
11
  method = "parse_#{section[0]}"
10
12
  send method, section[1] if respond_to?(method)
11
13
  end
12
14
  end
13
15
 
14
- def parse_interfaces(raw)
15
- @interfaces = raw.scan(/^(\ {4}\S+\ \{$.*?^\ {4}\})$/m).collect do |section|
16
- Interface.new section[0]
16
+ def parse_interfaces(raw_section)
17
+ @interfaces = raw_section.scan(/^(\ {4}\S+\ \{$.*?^\ {4}\})$/m).collect do |x|
18
+ Interface.new self, x[0]
17
19
  end
18
20
  end
21
+
22
+ def parse_security(raw_section)
23
+ @security_zones = raw_section.scan(/^(\ {8}security\-zone\ \S+ \{$.*?^\ {8}\})$/m).collect do |x|
24
+ Security::Zone.new self, x[0]
25
+ end
26
+ @security_policies = raw_section.scan(/^\ {8}from\-zone\ (\S+) to\-zone (\S+) \{$(.*?)^\ {8}\}$/m).collect do |x|
27
+ from_zone = security_zones.find{ |zone| zone.name == x[0] }
28
+ to_zone = security_zones.find{ |zone| zone.name == x[1] }
29
+ x[2].scan(/(\ {12}policy \S+ \{$.*?^\ {12}\}$)/m).collect do |y|
30
+ Security::Policy.new self, y[0], from_zone, to_zone
31
+ end
32
+ end
33
+ @security_policies.flatten!
34
+ end
19
35
  end
20
36
  end
@@ -1,11 +1,13 @@
1
1
  module JunosConfig
2
2
  class Interface
3
- attr_accessor :config,
3
+ attr_accessor :raw,
4
+ :config,
4
5
  :name
5
6
 
6
- def initialize(config)
7
+ def initialize(config, raw)
7
8
  @config = config
8
- @name = config.match(/^\ {4}(\S+)\ \{$/)[1]
9
+ @raw = raw
10
+ @name = raw.match(/^\ {4}(\S+)\ \{$/)[1]
9
11
  end
10
12
  end
11
13
  end
@@ -0,0 +1,19 @@
1
+ module JunosConfig
2
+ module Security
3
+ class Policy
4
+ attr_accessor :raw,
5
+ :config,
6
+ :name,
7
+ :from_zone,
8
+ :to_zone
9
+
10
+ def initialize(config, raw, from_zone, to_zone)
11
+ @config = config
12
+ @raw = raw
13
+ @from_zone = from_zone
14
+ @to_zone = to_zone
15
+ @name = raw.match(/^\ {12}policy (\S+)\ \{$/)[1]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module JunosConfig
2
+ module Security
3
+ class Zone
4
+ attr_accessor :raw,
5
+ :config,
6
+ :name
7
+
8
+ def initialize(config, raw)
9
+ @config = config
10
+ @raw = raw
11
+ @name = raw.match(/^\ {8}security\-zone\ (\S+) \{$/)[1]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -8,6 +8,7 @@ describe JunosConfig do
8
8
  before :each do
9
9
  @config = JunosConfig::Config.new SAMPLE_1
10
10
  end
11
+
11
12
  it 'should have 9 interfaces' do
12
13
  @config.interfaces.size.should == 9
13
14
  end
@@ -38,6 +39,53 @@ describe JunosConfig do
38
39
  describe 'interface 8' do
39
40
  it 'should be named st0' do @config.interfaces[8].name.should == 'st0' end
40
41
  end
42
+
43
+ it 'should have 3 security zones' do
44
+ @config.security_zones.size.should == 3
45
+ end
46
+ describe 'security zone 0' do
47
+ it 'should be named trust' do @config.security_zones[0].name.should == 'trust' end
48
+ end
49
+ describe 'security zone 1' do
50
+ it 'should be named untrust' do @config.security_zones[1].name.should == 'untrust' end
51
+ end
52
+ describe 'security zone 2' do
53
+ it 'should be named vpn' do @config.security_zones[2].name.should == 'vpn' end
54
+ end
55
+
56
+ it 'should have 6 security policies' do
57
+ @config.security_policies.size.should == 6
58
+ end
59
+ describe 'security policy 0' do
60
+ it 'should be named trust-to-untrust' do @config.security_policies[0].name.should == 'trust-to-untrust' end
61
+ it 'should be from zone security zone 0 (trust)' do @config.security_policies[0].from_zone.should == @config.security_zones[0] end
62
+ it 'should be to zone security zone 1 (untrust)' do @config.security_policies[0].to_zone.should == @config.security_zones[1] end
63
+ end
64
+ describe 'security policy 1' do
65
+ it 'should be named FromVPN' do @config.security_policies[1].name.should == 'FromVPN' end
66
+ it 'should be from zone security zone 2 (vpn)' do @config.security_policies[1].from_zone.should == @config.security_zones[2] end
67
+ it 'should be to zone security zone 0 (trust)' do @config.security_policies[1].to_zone.should == @config.security_zones[0] end
68
+ end
69
+ describe 'security policy 2' do
70
+ it 'should be named ToVpn' do @config.security_policies[2].name.should == 'ToVpn' end
71
+ it 'should be from zone security zone 0 (trust)' do @config.security_policies[2].from_zone.should == @config.security_zones[0] end
72
+ it 'should be to zone security zone 2 (vpn)' do @config.security_policies[2].to_zone.should == @config.security_zones[2] end
73
+ end
74
+ describe 'security policy 3' do
75
+ it 'should be named vpn-to-vpn' do @config.security_policies[3].name.should == 'vpn-to-vpn' end
76
+ it 'should be from zone security zone 2 (vpn)' do @config.security_policies[3].from_zone.should == @config.security_zones[2] end
77
+ it 'should be to zone security zone 2 (vpn)' do @config.security_policies[3].to_zone.should == @config.security_zones[2] end
78
+ end
79
+ describe 'security policy 4' do
80
+ it 'should be named voip' do @config.security_policies[4].name.should == 'voip' end
81
+ it 'should be from zone security zone 1 (untrust)' do @config.security_policies[4].from_zone.should == @config.security_zones[1] end
82
+ it 'should be to zone security zone 0 (trust)' do @config.security_policies[4].to_zone.should == @config.security_zones[0] end
83
+ end
84
+ describe 'security policy 5' do
85
+ it 'should be named test-rails' do @config.security_policies[5].name.should == 'test-rails' end
86
+ it 'should be from zone security zone 1 (untrust)' do @config.security_policies[5].from_zone.should == @config.security_zones[1] end
87
+ it 'should be to zone security zone 0 (trust)' do @config.security_policies[5].to_zone.should == @config.security_zones[0] end
88
+ end
41
89
  end
42
90
  end
43
91
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junos-config
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - John Wulff
@@ -102,6 +102,8 @@ files:
102
102
  - lib/junos-config.rb
103
103
  - lib/junos-config/config.rb
104
104
  - lib/junos-config/interface.rb
105
+ - lib/junos-config/security/policy.rb
106
+ - lib/junos-config/security/zone.rb
105
107
  - spec/junos-config_spec.rb
106
108
  - spec/sample_configs/sample_1
107
109
  - spec/spec_helper.rb