cisco_acl_intp 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +64 -3
  4. data/cisco_acl_intp.gemspec +2 -2
  5. data/lib/cisco_acl_intp/ace.rb +9 -286
  6. data/lib/cisco_acl_intp/ace_ip.rb +24 -22
  7. data/lib/cisco_acl_intp/ace_other_qualifiers.rb +23 -6
  8. data/lib/cisco_acl_intp/ace_port.rb +37 -182
  9. data/lib/cisco_acl_intp/ace_port_opr.rb +251 -0
  10. data/lib/cisco_acl_intp/ace_port_opr_base.rb +138 -0
  11. data/lib/cisco_acl_intp/ace_proto.rb +133 -328
  12. data/lib/cisco_acl_intp/ace_proto_base.rb +163 -0
  13. data/lib/cisco_acl_intp/ace_srcdst.rb +30 -40
  14. data/lib/cisco_acl_intp/ace_tcp_flags.rb +9 -3
  15. data/lib/cisco_acl_intp/acl.rb +1 -251
  16. data/lib/cisco_acl_intp/acl_base.rb +1 -1
  17. data/lib/cisco_acl_intp/acl_utils.rb +120 -0
  18. data/lib/cisco_acl_intp/extended_ace.rb +149 -0
  19. data/lib/cisco_acl_intp/mono_function_acl.rb +161 -0
  20. data/lib/cisco_acl_intp/parser.rb +237 -395
  21. data/lib/cisco_acl_intp/parser.ry +85 -243
  22. data/lib/cisco_acl_intp/parser_api.rb +2 -2
  23. data/lib/cisco_acl_intp/single_acl_base.rb +137 -0
  24. data/lib/cisco_acl_intp/standard_ace.rb +105 -0
  25. data/lib/cisco_acl_intp/version.rb +1 -1
  26. data/spec/cisco_acl_intp/ace_ip_spec.rb +63 -0
  27. data/spec/cisco_acl_intp/ace_other_qualifier_spec.rb +52 -1
  28. data/spec/cisco_acl_intp/ace_port_operator_spec.rb +340 -0
  29. data/spec/cisco_acl_intp/ace_port_spec.rb +67 -217
  30. data/spec/cisco_acl_intp/ace_proto_spec.rb +118 -41
  31. data/spec/cisco_acl_intp/ace_spec.rb +38 -547
  32. data/spec/cisco_acl_intp/ace_srcdst_spec.rb +115 -226
  33. data/spec/cisco_acl_intp/ace_tcp_flags_spec.rb +36 -4
  34. data/spec/cisco_acl_intp/acl_base_spec.rb +2 -2
  35. data/spec/cisco_acl_intp/extended_ace_spec.rb +411 -0
  36. data/spec/cisco_acl_intp/extended_acl_spec.rb +265 -0
  37. data/spec/cisco_acl_intp/scanner_spec.rb +13 -12
  38. data/spec/cisco_acl_intp/standard_ace_spec.rb +77 -0
  39. data/spec/cisco_acl_intp/standard_acl_spec.rb +245 -0
  40. data/spec/conf/scanner_spec_data.yml +32 -0
  41. data/spec/spec_helper.rb +2 -2
  42. metadata +20 -4
  43. data/spec/cisco_acl_intp/acl_spec.rb +0 -525
@@ -0,0 +1,161 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'forwardable'
4
+ require 'cisco_acl_intp/single_acl_base'
5
+
6
+ module CiscoAclIntp
7
+ # Features for Extended ACL
8
+ # @todo Does it have to raise error if add_entry called with
9
+ # StandardAce?
10
+ module ExtAcl
11
+ # Generate a Extended ACE by parameters
12
+ # and Add it to ACL
13
+ # @param [Hash] opts Options to create {ExtendedAce}
14
+ def add_entry_by_params(opts)
15
+ ace = ExtendedAce.new opts
16
+ add_entry ace
17
+ end
18
+ end
19
+
20
+ # Features for Standard ACL
21
+ # @todo Does it have to raise error if add_entry called with
22
+ # ExtendedAce?
23
+ module StdAcl
24
+ # Generate a Standard ACE by parameters
25
+ # and Add it to ACL
26
+ # @param [Hash] opts Options to create {StandardAce}
27
+ def add_entry_by_params(opts)
28
+ ace = StandardAce.new opts
29
+ add_entry ace
30
+ end
31
+ end
32
+
33
+ ############################################################
34
+
35
+ # Named ACL container base
36
+ class NamedAcl < SingleAclBase
37
+ # check acl type,Named ACL or not?
38
+ # @return [Boolean]
39
+ def named_acl?
40
+ true
41
+ end
42
+
43
+ # check acl type, Numbered ACL or not?
44
+ # @return [Boolean]
45
+ def numbered_acl?
46
+ false
47
+ end
48
+
49
+ # Generate ACL header string
50
+ # @return [String] ACL header string
51
+ def header_string
52
+ format(
53
+ '%s %s %s',
54
+ tag_header('ip access-list'),
55
+ tag_type(@acl_type),
56
+ tag_name(@name)
57
+ )
58
+ end
59
+
60
+ # Generate ACL line string
61
+ # @param [AceBase] entry ACE object
62
+ def line_string(entry)
63
+ # add indent
64
+ format ' %s', clean_acl_string(entry.to_s)
65
+ end
66
+
67
+ # Generate string for Cisco IOS access list
68
+ # @return [String]
69
+ def to_s
70
+ strings = @list.each_with_object([header_string]) do |entry, strlist|
71
+ strlist.push line_string(entry)
72
+ end
73
+ strings.join("\n")
74
+ end
75
+ end
76
+
77
+ # Numbered ACL container base
78
+ class NumberedAcl < SingleAclBase
79
+ # @return [Integer] Access list number
80
+ attr_reader :number
81
+
82
+ # check acl type,Named ACL or not?
83
+ # @return [Boolean]
84
+ def named_acl?
85
+ false
86
+ end
87
+
88
+ # check acl type, Numbered ACL or not?
89
+ # @return [Boolean]
90
+ def numbered_acl?
91
+ true
92
+ end
93
+
94
+ # Constructor
95
+ # @param [String, Integer] name ACL number
96
+ # @raise [AclArgumentError]
97
+ # @return [NumberedAcl]
98
+ # @todo It ought to do something about assignment operator...
99
+ # (attr_reader)
100
+ def initialize(name)
101
+ super
102
+ case name
103
+ when Fixnum
104
+ set_name_and_number(name.to_s, name)
105
+ when String
106
+ validate_name_by_string(name)
107
+ else
108
+ fail AclArgumentError, 'acl number error'
109
+ end
110
+ end
111
+
112
+ # Generate ACL header string
113
+ # @return [String] ACL header string
114
+ def header_string
115
+ format(
116
+ '%s %s',
117
+ tag_header('access-list'),
118
+ tag_name(@name)
119
+ )
120
+ end
121
+
122
+ # Generate ACL line string
123
+ # @param [AceBase] entry ACE object
124
+ def line_string(entry)
125
+ clean_acl_string(format('%s %s', header_string, entry))
126
+ end
127
+
128
+ # Generate string for Cisco IOS access list
129
+ # @return [String]
130
+ def to_s
131
+ strings = @list.each_with_object([]) do |entry, strlist|
132
+ strlist.push line_string(entry)
133
+ end
134
+ strings.join("\n")
135
+ end
136
+
137
+ private
138
+
139
+ # validate instance variables
140
+ # @param [String] name ACL Name
141
+ def validate_name_by_string(name)
142
+ if name =~ /\A\d+\Z/
143
+ set_name_and_number(name, name.to_i)
144
+ else
145
+ fail AclArgumentError, 'acl number string is not integer'
146
+ end
147
+ end
148
+
149
+ # Set instance variables
150
+ def set_name_and_number(name, number)
151
+ @name = name
152
+ @number = number
153
+ end
154
+ end
155
+ end # module
156
+
157
+ ### Local variables:
158
+ ### mode: Ruby
159
+ ### coding: utf-8-unix
160
+ ### indent-tabs-mode: nil
161
+ ### End: