puppet 0.25.0 → 0.25.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (138) hide show
  1. data/CHANGELOG +4772 -19114
  2. data/README +1 -1
  3. data/Rakefile +7 -25
  4. data/{sbin → bin}/puppetca +0 -0
  5. data/{sbin → bin}/puppetd +0 -0
  6. data/{sbin → bin}/puppetmasterd +0 -0
  7. data/{sbin → bin}/puppetqd +0 -0
  8. data/{sbin → bin}/puppetrun +0 -0
  9. data/conf/osx/createpackage.sh +1 -1
  10. data/conf/redhat/client.init +6 -3
  11. data/conf/redhat/puppet.spec +26 -14
  12. data/conf/redhat/server.init +3 -2
  13. data/ext/vim/syntax/puppet.vim +4 -1
  14. data/install.rb +25 -7
  15. data/lib/puppet.rb +1 -1
  16. data/lib/puppet/agent.rb +2 -2
  17. data/lib/puppet/application/puppet.rb +3 -3
  18. data/lib/puppet/application/puppetd.rb +0 -7
  19. data/lib/puppet/application/puppetdoc.rb +1 -0
  20. data/lib/puppet/application/puppetmasterd.rb +2 -2
  21. data/lib/puppet/configurer.rb +6 -1
  22. data/lib/puppet/configurer/fact_handler.rb +2 -2
  23. data/lib/puppet/defaults.rb +2 -2
  24. data/lib/puppet/external/nagios/base.rb +4 -3
  25. data/lib/puppet/external/pson/common.rb +367 -0
  26. data/lib/puppet/external/pson/pure.rb +77 -0
  27. data/lib/puppet/external/pson/pure/generator.rb +429 -0
  28. data/lib/puppet/external/pson/pure/parser.rb +269 -0
  29. data/lib/puppet/external/pson/version.rb +8 -0
  30. data/lib/puppet/feature/pson.rb +6 -0
  31. data/lib/puppet/feature/rails.rb +1 -5
  32. data/lib/puppet/file_serving/configuration.rb +2 -2
  33. data/lib/puppet/indirector/certificate/rest.rb +6 -0
  34. data/lib/puppet/indirector/facts/facter.rb +1 -1
  35. data/lib/puppet/indirector/ldap.rb +1 -1
  36. data/lib/puppet/indirector/queue.rb +3 -3
  37. data/lib/puppet/indirector/rest.rb +1 -1
  38. data/lib/puppet/network/authstore.rb +34 -53
  39. data/lib/puppet/network/formats.rb +59 -9
  40. data/lib/puppet/network/http/mongrel/rest.rb +10 -9
  41. data/lib/puppet/network/http/webrick.rb +8 -1
  42. data/lib/puppet/network/http/webrick/rest.rb +2 -5
  43. data/lib/puppet/network/http_server/webrick.rb +1 -4
  44. data/lib/puppet/parser/ast/leaf.rb +1 -3
  45. data/lib/puppet/parser/collector.rb +14 -8
  46. data/lib/puppet/parser/compiler.rb +7 -0
  47. data/lib/puppet/parser/functions/fqdn_rand.rb +4 -10
  48. data/lib/puppet/parser/functions/regsubst.rb +44 -30
  49. data/lib/puppet/parser/functions/require.rb +18 -3
  50. data/lib/puppet/parser/functions/versioncmp.rb +1 -1
  51. data/lib/puppet/parser/interpreter.rb +1 -1
  52. data/lib/puppet/parser/lexer.rb +29 -31
  53. data/lib/puppet/parser/loaded_code.rb +4 -0
  54. data/lib/puppet/parser/parser_support.rb +5 -2
  55. data/lib/puppet/parser/resource.rb +31 -6
  56. data/lib/puppet/property.rb +3 -2
  57. data/lib/puppet/provider/macauthorization/macauthorization.rb +14 -14
  58. data/lib/puppet/provider/package/dpkg.rb +1 -1
  59. data/lib/puppet/provider/package/portage.rb +15 -5
  60. data/lib/puppet/provider/package/rug.rb +1 -1
  61. data/lib/puppet/provider/package/up2date.rb +1 -1
  62. data/lib/puppet/provider/package/urpmi.rb +1 -1
  63. data/lib/puppet/provider/service/daemontools.rb +7 -10
  64. data/lib/puppet/provider/service/runit.rb +7 -17
  65. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -47
  66. data/lib/puppet/provider/zone/solaris.rb +12 -3
  67. data/lib/puppet/relationship.rb +12 -12
  68. data/lib/puppet/reports/rrdgraph.rb +1 -1
  69. data/lib/puppet/reports/store.rb +2 -2
  70. data/lib/puppet/reports/tagmail.rb +5 -16
  71. data/lib/puppet/resource.rb +15 -20
  72. data/lib/puppet/resource/catalog.rb +40 -29
  73. data/lib/puppet/ssl/certificate_revocation_list.rb +0 -2
  74. data/lib/puppet/ssl/host.rb +2 -3
  75. data/lib/puppet/sslcertificates/ca.rb +0 -5
  76. data/lib/puppet/type/cron.rb +1 -1
  77. data/lib/puppet/type/file/owner.rb +7 -4
  78. data/lib/puppet/type/resources.rb +17 -17
  79. data/lib/puppet/type/yumrepo.rb +10 -3
  80. data/lib/puppet/util.rb +6 -11
  81. data/lib/puppet/util/inifile.rb +8 -0
  82. data/lib/puppet/util/log.rb +2 -2
  83. data/lib/puppet/util/monkey_patches.rb +0 -43
  84. data/lib/puppet/util/{json.rb → pson.rb} +6 -6
  85. data/lib/puppet/util/rdoc.rb +5 -3
  86. data/lib/puppet/util/selinux.rb +12 -6
  87. data/lib/puppet/util/settings.rb +25 -16
  88. data/lib/puppet/util/settings/file_setting.rb +4 -2
  89. data/spec/integration/application/puppet.rb +4 -4
  90. data/spec/integration/defaults.rb +2 -2
  91. data/spec/integration/indirector/catalog/queue.rb +5 -5
  92. data/spec/integration/indirector/certificate/rest.rb +3 -1
  93. data/spec/integration/network/formats.rb +36 -36
  94. data/spec/integration/parser/functions/require.rb +5 -3
  95. data/spec/integration/provider/mailalias/aliases.rb +4 -4
  96. data/spec/integration/resource/catalog.rb +4 -4
  97. data/spec/unit/application/puppet.rb +16 -15
  98. data/spec/unit/application/puppetd.rb +1 -1
  99. data/spec/unit/application/puppetdoc.rb +6 -0
  100. data/spec/unit/application/puppetmasterd.rb +6 -6
  101. data/spec/unit/configurer/fact_handler.rb +3 -3
  102. data/spec/unit/file_serving/configuration.rb +16 -2
  103. data/spec/unit/indirector/certificate/rest.rb +34 -0
  104. data/spec/unit/indirector/queue.rb +15 -15
  105. data/spec/unit/indirector/rest.rb +31 -9
  106. data/spec/unit/network/authstore.rb +105 -26
  107. data/spec/unit/network/formats.rb +124 -39
  108. data/spec/unit/parser/ast/leaf.rb +15 -0
  109. data/spec/unit/parser/collector.rb +20 -9
  110. data/spec/unit/parser/compiler.rb +19 -0
  111. data/spec/unit/parser/functions/fqdn_rand.rb +62 -0
  112. data/spec/unit/parser/functions/regsubst.rb +80 -0
  113. data/spec/unit/parser/functions/require.rb +19 -7
  114. data/spec/unit/parser/interpreter.rb +2 -2
  115. data/spec/unit/parser/lexer.rb +32 -7
  116. data/spec/unit/parser/loaded_code.rb +18 -1
  117. data/spec/unit/parser/parser.rb +10 -2
  118. data/spec/unit/parser/resource.rb +53 -2
  119. data/spec/unit/parser/scope.rb +1 -1
  120. data/spec/unit/property.rb +14 -4
  121. data/spec/unit/provider/package/dpkg.rb +7 -0
  122. data/spec/unit/provider/service/daemontools.rb +19 -2
  123. data/spec/unit/provider/service/redhat.rb +2 -0
  124. data/spec/unit/provider/service/runit.rb +15 -4
  125. data/spec/unit/provider/ssh_authorized_key/parsed.rb +32 -55
  126. data/spec/unit/relationship.rb +21 -46
  127. data/spec/unit/resource.rb +30 -39
  128. data/spec/unit/resource/catalog.rb +66 -51
  129. data/spec/unit/ssl/certificate_revocation_list.rb +0 -12
  130. data/spec/unit/type/cron.rb +33 -0
  131. data/spec/unit/type/file/owner.rb +10 -4
  132. data/spec/unit/util/json.rb +9 -9
  133. data/spec/unit/util/log.rb +36 -0
  134. data/spec/unit/util/settings.rb +6 -0
  135. data/test/data/providers/ssh_authorized_key/parsed/authorized_keys2 +1 -0
  136. data/test/lib/puppettest/support/utils.rb +8 -16
  137. metadata +36 -13
  138. data/lib/puppet/feature/json.rb +0 -2
@@ -0,0 +1,269 @@
1
+ require 'strscan'
2
+
3
+ module PSON
4
+ module Pure
5
+ # This class implements the PSON parser that is used to parse a PSON string
6
+ # into a Ruby data structure.
7
+ class Parser < StringScanner
8
+ STRING = /" ((?:[^\x0-\x1f"\\] |
9
+ # escaped special characters:
10
+ \\["\\\/bfnrt] |
11
+ \\u[0-9a-fA-F]{4} |
12
+ # match all but escaped special characters:
13
+ \\[\x20-\x21\x23-\x2e\x30-\x5b\x5d-\x61\x63-\x65\x67-\x6d\x6f-\x71\x73\x75-\xff])*)
14
+ "/nx
15
+ INTEGER = /(-?0|-?[1-9]\d*)/
16
+ FLOAT = /(-?
17
+ (?:0|[1-9]\d*)
18
+ (?:
19
+ \.\d+(?i:e[+-]?\d+) |
20
+ \.\d+ |
21
+ (?i:e[+-]?\d+)
22
+ )
23
+ )/x
24
+ NAN = /NaN/
25
+ INFINITY = /Infinity/
26
+ MINUS_INFINITY = /-Infinity/
27
+ OBJECT_OPEN = /\{/
28
+ OBJECT_CLOSE = /\}/
29
+ ARRAY_OPEN = /\[/
30
+ ARRAY_CLOSE = /\]/
31
+ PAIR_DELIMITER = /:/
32
+ COLLECTION_DELIMITER = /,/
33
+ TRUE = /true/
34
+ FALSE = /false/
35
+ NULL = /null/
36
+ IGNORE = %r(
37
+ (?:
38
+ //[^\n\r]*[\n\r]| # line comments
39
+ /\* # c-style comments
40
+ (?:
41
+ [^*/]| # normal chars
42
+ /[^*]| # slashes that do not start a nested comment
43
+ \*[^/]| # asterisks that do not end this comment
44
+ /(?=\*/) # single slash before this comment's end
45
+ )*
46
+ \*/ # the End of this comment
47
+ |[ \t\r\n]+ # whitespaces: space, horicontal tab, lf, cr
48
+ )+
49
+ )mx
50
+
51
+ UNPARSED = Object.new
52
+
53
+ # Creates a new PSON::Pure::Parser instance for the string _source_.
54
+ #
55
+ # It will be configured by the _opts_ hash. _opts_ can have the following
56
+ # keys:
57
+ # * *max_nesting*: The maximum depth of nesting allowed in the parsed data
58
+ # structures. Disable depth checking with :max_nesting => false|nil|0,
59
+ # it defaults to 19.
60
+ # * *allow_nan*: If set to true, allow NaN, Infinity and -Infinity in
61
+ # defiance of RFC 4627 to be parsed by the Parser. This option defaults
62
+ # to false.
63
+ # * *create_additions*: If set to false, the Parser doesn't create
64
+ # additions even if a matchin class and create_id was found. This option
65
+ # defaults to true.
66
+ # * *object_class*: Defaults to Hash
67
+ # * *array_class*: Defaults to Array
68
+ def initialize(source, opts = {})
69
+ super
70
+ if !opts.key?(:max_nesting) # defaults to 19
71
+ @max_nesting = 19
72
+ elsif opts[:max_nesting]
73
+ @max_nesting = opts[:max_nesting]
74
+ else
75
+ @max_nesting = 0
76
+ end
77
+ @allow_nan = !!opts[:allow_nan]
78
+ ca = true
79
+ ca = opts[:create_additions] if opts.key?(:create_additions)
80
+ @create_id = ca ? PSON.create_id : nil
81
+ @object_class = opts[:object_class] || Hash
82
+ @array_class = opts[:array_class] || Array
83
+ end
84
+
85
+ alias source string
86
+
87
+ # Parses the current PSON string _source_ and returns the complete data
88
+ # structure as a result.
89
+ def parse
90
+ reset
91
+ obj = nil
92
+ until eos?
93
+ case
94
+ when scan(OBJECT_OPEN)
95
+ obj and raise ParserError, "source '#{peek(20)}' not in PSON!"
96
+ @current_nesting = 1
97
+ obj = parse_object
98
+ when scan(ARRAY_OPEN)
99
+ obj and raise ParserError, "source '#{peek(20)}' not in PSON!"
100
+ @current_nesting = 1
101
+ obj = parse_array
102
+ when skip(IGNORE)
103
+ ;
104
+ else
105
+ raise ParserError, "source '#{peek(20)}' not in PSON!"
106
+ end
107
+ end
108
+ obj or raise ParserError, "source did not contain any PSON!"
109
+ obj
110
+ end
111
+
112
+ private
113
+
114
+ # Unescape characters in strings.
115
+ UNESCAPE_MAP = Hash.new { |h, k| h[k] = k.chr }
116
+ UNESCAPE_MAP.update({
117
+ ?" => '"',
118
+ ?\\ => '\\',
119
+ ?/ => '/',
120
+ ?b => "\b",
121
+ ?f => "\f",
122
+ ?n => "\n",
123
+ ?r => "\r",
124
+ ?t => "\t",
125
+ ?u => nil,
126
+ })
127
+
128
+ def parse_string
129
+ if scan(STRING)
130
+ return '' if self[1].empty?
131
+ string = self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
132
+ if u = UNESCAPE_MAP[$&[1]]
133
+ u
134
+ else # \uXXXX
135
+ bytes = ''
136
+ i = 0
137
+ while c[6 * i] == ?\\ && c[6 * i + 1] == ?u
138
+ bytes << c[6 * i + 2, 2].to_i(16) << c[6 * i + 4, 2].to_i(16)
139
+ i += 1
140
+ end
141
+ PSON::UTF16toUTF8.iconv(bytes)
142
+ end
143
+ end
144
+ if string.respond_to?(:force_encoding)
145
+ string.force_encoding(Encoding::UTF_8)
146
+ end
147
+ string
148
+ else
149
+ UNPARSED
150
+ end
151
+ rescue Iconv::Failure => e
152
+ raise GeneratorError, "Caught #{e.class}: #{e}"
153
+ end
154
+
155
+ def parse_value
156
+ case
157
+ when scan(FLOAT)
158
+ Float(self[1])
159
+ when scan(INTEGER)
160
+ Integer(self[1])
161
+ when scan(TRUE)
162
+ true
163
+ when scan(FALSE)
164
+ false
165
+ when scan(NULL)
166
+ nil
167
+ when (string = parse_string) != UNPARSED
168
+ string
169
+ when scan(ARRAY_OPEN)
170
+ @current_nesting += 1
171
+ ary = parse_array
172
+ @current_nesting -= 1
173
+ ary
174
+ when scan(OBJECT_OPEN)
175
+ @current_nesting += 1
176
+ obj = parse_object
177
+ @current_nesting -= 1
178
+ obj
179
+ when @allow_nan && scan(NAN)
180
+ NaN
181
+ when @allow_nan && scan(INFINITY)
182
+ Infinity
183
+ when @allow_nan && scan(MINUS_INFINITY)
184
+ MinusInfinity
185
+ else
186
+ UNPARSED
187
+ end
188
+ end
189
+
190
+ def parse_array
191
+ raise NestingError, "nesting of #@current_nesting is too deep" if
192
+ @max_nesting.nonzero? && @current_nesting > @max_nesting
193
+ result = @array_class.new
194
+ delim = false
195
+ until eos?
196
+ case
197
+ when (value = parse_value) != UNPARSED
198
+ delim = false
199
+ result << value
200
+ skip(IGNORE)
201
+ if scan(COLLECTION_DELIMITER)
202
+ delim = true
203
+ elsif match?(ARRAY_CLOSE)
204
+ ;
205
+ else
206
+ raise ParserError, "expected ',' or ']' in array at '#{peek(20)}'!"
207
+ end
208
+ when scan(ARRAY_CLOSE)
209
+ if delim
210
+ raise ParserError, "expected next element in array at '#{peek(20)}'!"
211
+ end
212
+ break
213
+ when skip(IGNORE)
214
+ ;
215
+ else
216
+ raise ParserError, "unexpected token in array at '#{peek(20)}'!"
217
+ end
218
+ end
219
+ result
220
+ end
221
+
222
+ def parse_object
223
+ raise NestingError, "nesting of #@current_nesting is too deep" if
224
+ @max_nesting.nonzero? && @current_nesting > @max_nesting
225
+ result = @object_class.new
226
+ delim = false
227
+ until eos?
228
+ case
229
+ when (string = parse_string) != UNPARSED
230
+ skip(IGNORE)
231
+ unless scan(PAIR_DELIMITER)
232
+ raise ParserError, "expected ':' in object at '#{peek(20)}'!"
233
+ end
234
+ skip(IGNORE)
235
+ unless (value = parse_value).equal? UNPARSED
236
+ result[string] = value
237
+ delim = false
238
+ skip(IGNORE)
239
+ if scan(COLLECTION_DELIMITER)
240
+ delim = true
241
+ elsif match?(OBJECT_CLOSE)
242
+ ;
243
+ else
244
+ raise ParserError, "expected ',' or '}' in object at '#{peek(20)}'!"
245
+ end
246
+ else
247
+ raise ParserError, "expected value in object at '#{peek(20)}'!"
248
+ end
249
+ when scan(OBJECT_CLOSE)
250
+ if delim
251
+ raise ParserError, "expected next name, value pair in object at '#{peek(20)}'!"
252
+ end
253
+ if @create_id and klassname = result[@create_id]
254
+ klass = PSON.deep_const_get klassname
255
+ break unless klass and klass.pson_creatable?
256
+ result = klass.pson_create(result)
257
+ end
258
+ break
259
+ when skip(IGNORE)
260
+ ;
261
+ else
262
+ raise ParserError, "unexpected token in object at '#{peek(20)}'!"
263
+ end
264
+ end
265
+ result
266
+ end
267
+ end
268
+ end
269
+ end
@@ -0,0 +1,8 @@
1
+ module PSON
2
+ # PSON version
3
+ VERSION = '1.1.9'
4
+ VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
+ VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
+ VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
7
+ VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
8
+ end
@@ -0,0 +1,6 @@
1
+ Puppet.features.add(:pson) do
2
+ require 'puppet/external/pson/common'
3
+ require 'puppet/external/pson/version'
4
+ require 'puppet/external/pson/pure'
5
+ true
6
+ end
@@ -8,6 +8,7 @@ Puppet.features.rubygems?
8
8
  Puppet.features.add(:rails) do
9
9
  begin
10
10
  require 'active_record'
11
+ require 'active_record/version'
11
12
  rescue LoadError => detail
12
13
  if FileTest.exists?("/usr/share/rails")
13
14
  count = 0
@@ -34,8 +35,3 @@ Puppet.features.add(:rails) do
34
35
  true
35
36
  end
36
37
  end
37
-
38
- # We have JSON available
39
- # This is stupid - Rails breaks json compatibility if we load json before
40
- # rails, therefore we load rails and then json. Dumb, mother-dumb.
41
- Puppet.features.add(:json, :libs => ["json"])
@@ -96,9 +96,9 @@ class Puppet::FileServing::Configuration
96
96
 
97
97
  def mk_default_mounts
98
98
  @mounts["modules"] ||= Mount::Modules.new("modules")
99
- @mounts["modules"].allow('*')
99
+ @mounts["modules"].allow('*') if @mounts["modules"].empty?
100
100
  @mounts["plugins"] ||= Mount::Plugins.new("plugins")
101
- @mounts["plugins"].allow('*')
101
+ @mounts["plugins"].allow('*') if @mounts["plugins"].empty?
102
102
  end
103
103
 
104
104
  # Read the configuration file.
@@ -6,4 +6,10 @@ class Puppet::SSL::Certificate::Rest < Puppet::Indirector::REST
6
6
 
7
7
  use_server_setting(:ca_server)
8
8
  use_port_setting(:ca_port)
9
+
10
+ def find(request)
11
+ return nil unless result = super
12
+ result.name = request.key unless result.name == request.key
13
+ result
14
+ end
9
15
  end
@@ -29,7 +29,7 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code
29
29
  Timeout::timeout(self.timeout) do
30
30
  load file
31
31
  end
32
- rescue => detail
32
+ rescue Exception => detail
33
33
  Puppet.warning "Could not load fact file %s: %s" % [fqfile, detail]
34
34
  end
35
35
  end
@@ -40,7 +40,7 @@ class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus
40
40
  found = true
41
41
  yield entry
42
42
  end
43
- rescue => detail
43
+ rescue Exception => detail
44
44
  if count == 0
45
45
  # Try reconnecting to ldap if we get an exception and we haven't yet retried.
46
46
  count += 1
@@ -24,7 +24,7 @@ class Puppet::Indirector::Queue < Puppet::Indirector::Terminus
24
24
 
25
25
  def initialize(*args)
26
26
  super
27
- raise ArgumentError, "Queueing requires json support" unless Puppet.features.json?
27
+ raise ArgumentError, "Queueing requires pson support" unless Puppet.features.pson?
28
28
  end
29
29
 
30
30
  # Queue has no idiomatic "find"
@@ -37,7 +37,7 @@ class Puppet::Indirector::Queue < Puppet::Indirector::Terminus
37
37
  begin
38
38
  result = nil
39
39
  benchmark :info, "Queued %s for %s" % [indirection.name, request.key] do
40
- result = client.send_message(queue, request.instance.render(:json))
40
+ result = client.send_message(queue, request.instance.render(:pson))
41
41
  end
42
42
  result
43
43
  rescue => detail
@@ -62,7 +62,7 @@ class Puppet::Indirector::Queue < Puppet::Indirector::Terminus
62
62
  def self.intern(message)
63
63
  result = nil
64
64
  benchmark :info, "Loaded queued %s" % [indirection.name] do
65
- result = model.convert_from(:json, message)
65
+ result = model.convert_from(:pson, message)
66
66
  end
67
67
  result
68
68
  end
@@ -51,7 +51,7 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
51
51
  end
52
52
  else
53
53
  # Raise the http error if we didn't get a 'success' of some kind.
54
- message = "Error %s on SERVER: %s" % [response.code, response.message]
54
+ message = "Error %s on SERVER: %s" % [response.code, (response.body||'').empty? ? response.message : response.body]
55
55
  raise Net::HTTPError.new(message, response)
56
56
  end
57
57
  end
@@ -63,6 +63,11 @@ module Puppet
63
63
  @globalallow
64
64
  end
65
65
 
66
+ # does this auth store has any rules?
67
+ def empty?
68
+ @globalallow.nil? && @declarations.size == 0
69
+ end
70
+
66
71
  def initialize
67
72
  @globalallow = nil
68
73
  @declarations = []
@@ -220,8 +225,6 @@ module Puppet
220
225
  # and we're called with a MatchData whose capture 1 is puppet
221
226
  # we'll return a pattern of puppet.reductivelabs.com
222
227
  def interpolate(match)
223
- return self if @name == :ip
224
-
225
228
  clone = dup
226
229
  clone.pattern = clone.pattern.reverse.collect do |p|
227
230
  p.gsub(/\$(\d)/) { |m| match[$1.to_i] }
@@ -279,63 +282,41 @@ module Puppet
279
282
  # Parse our input pattern and figure out what kind of allowal
280
283
  # statement it is. The output of this is used for later matching.
281
284
  def parse(value)
282
- case value
283
- when /^(\d+\.){1,3}\*$/ # an ip address with a '*' at the end
285
+ # Use the IPAddr class to determine if we've got a
286
+ # valid IP address.
287
+ @length = Integer($1) if value =~ /\/(\d+)$/
288
+ begin
289
+ @pattern = IPAddr.new(value)
284
290
  @name = :ip
285
- match = $1
286
- match.sub!(".", '')
287
- ary = value.split(".")
288
-
289
- mask = case ary.index(match)
290
- when 0; 8
291
- when 1; 16
292
- when 2; 24
293
- else
294
- raise AuthStoreError, "Invalid IP pattern %s" % value
295
- end
296
-
297
- @length = mask
298
-
299
- ary.pop
300
- while ary.length < 4
301
- ary.push("0")
302
- end
303
-
304
- begin
305
- @pattern = IPAddr.new(ary.join(".") + "/" + mask.to_s)
306
- rescue ArgumentError => detail
307
- raise AuthStoreError, "Invalid IP address pattern %s" % value
308
- end
309
- when /^([a-zA-Z][-\w]*\.)+[-\w]+$/ # a full hostname
310
- # Change to /^([a-zA-Z][-\w]*\.)+[-\w]+\.?$/ for FQDN support
311
- @name = :domain
312
- @pattern = munge_name(value)
313
- when /^\*(\.([a-zA-Z][-\w]*)){1,}$/ # *.domain.com
314
- @name = :domain
315
- @pattern = munge_name(value)
316
- @pattern.pop # take off the '*'
317
- @length = @pattern.length
318
- when /\$\d+/ # a backreference pattern ala $1.reductivelabs.com or 192.168.0.$1 or $1.$2
319
- @name = :dynamic
320
- @pattern = munge_name(value)
321
- else
322
- # Else, use the IPAddr class to determine if we've got a
323
- # valid IP address.
324
- if value =~ /\/(\d+)$/
325
- @length = Integer($1)
326
- end
327
- begin
328
- @pattern = IPAddr.new(value)
291
+ rescue ArgumentError => detail
292
+ case value
293
+ when /^(\d+\.){1,3}\*$/ # an ip address with a '*' at the end
329
294
  @name = :ip
330
- rescue ArgumentError => detail
331
- # so nothing matched, let's match as an opaque value
332
- # some sanity checks first
333
- unless value =~ /^[a-zA-Z0-9][-a-zA-Z0-9_.@]*$/
334
- raise AuthStoreError, "Invalid pattern %s" % value
295
+ segments = value.split(".")[0..-2]
296
+ @length = 8*segments.length
297
+ begin
298
+ @pattern = IPAddr.new((segments+[0,0,0])[0,4].join(".") + "/" + @length.to_s)
299
+ rescue ArgumentError => detail
300
+ raise AuthStoreError, "Invalid IP address pattern %s" % value
335
301
  end
302
+ when /^([a-zA-Z0-9][-\w]*\.)+[-\w]+$/ # a full hostname
303
+ # Change to /^([a-zA-Z][-\w]*\.)+[-\w]+\.?$/ for FQDN support
304
+ @name = :domain
305
+ @pattern = munge_name(value)
306
+ when /^\*(\.([a-zA-Z][-\w]*)){1,}$/ # *.domain.com
307
+ @name = :domain
308
+ @pattern = munge_name(value)
309
+ @pattern.pop # take off the '*'
310
+ @length = @pattern.length
311
+ when /\$\d+/ # a backreference pattern ala $1.reductivelabs.com or 192.168.0.$1 or $1.$2
312
+ @name = :dynamic
313
+ @pattern = munge_name(value)
314
+ when /^[a-zA-Z0-9][-a-zA-Z0-9_.@]*$/
336
315
  @pattern = [value]
337
316
  @length = nil # force an exact match
338
317
  @name = :opaque
318
+ else
319
+ raise AuthStoreError, "Invalid pattern %s" % value
339
320
  end
340
321
  end
341
322
  end