puppet 2.7.1 → 2.7.3
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.
- data/CHANGELOG +225 -1
- data/CONTRIBUTING.md +299 -0
- data/README.md +0 -1
- data/conf/redhat/puppet.spec +132 -25
- data/conf/solaris/pkginfo +1 -1
- data/conf/suse/puppet.spec +5 -2
- data/ext/envpuppet +56 -3
- data/ext/vim/README +2 -1
- data/ext/vim/ftplugin/puppet.vim +94 -0
- data/ext/vim/indent/puppet.vim +76 -0
- data/lib/puppet.rb +2 -3
- data/lib/puppet/application/agent.rb +7 -7
- data/lib/puppet/application/apply.rb +20 -8
- data/lib/puppet/application/ca.rb +5 -0
- data/lib/puppet/application/cert.rb +2 -1
- data/lib/puppet/application/certificate.rb +0 -5
- data/lib/puppet/application/device.rb +4 -4
- data/lib/puppet/application/doc.rb +23 -12
- data/lib/puppet/application/face_base.rb +2 -1
- data/lib/puppet/application/inspect.rb +5 -2
- data/lib/puppet/configurer.rb +60 -56
- data/lib/puppet/configurer/fact_handler.rb +6 -1
- data/lib/puppet/defaults.rb +20 -1
- data/lib/puppet/face/ca.rb +233 -0
- data/lib/puppet/face/certificate.rb +15 -11
- data/lib/puppet/face/certificate_request.rb +9 -11
- data/lib/puppet/face/certificate_revocation_list.rb +5 -7
- data/lib/puppet/face/node/clean.rb +154 -0
- data/lib/puppet/face/status.rb +1 -0
- data/lib/puppet/file_serving/configuration/parser.rb +6 -13
- data/lib/puppet/indirector/exec.rb +3 -3
- data/lib/puppet/indirector/face.rb +17 -7
- data/lib/puppet/indirector/report/processor.rb +29 -16
- data/lib/puppet/indirector/rest.rb +42 -7
- data/lib/puppet/indirector/yaml.rb +5 -0
- data/lib/puppet/interface.rb +7 -2
- data/lib/puppet/interface/action.rb +57 -23
- data/lib/puppet/interface/action_manager.rb +10 -5
- data/lib/puppet/interface/face_collection.rb +43 -52
- data/lib/puppet/interface/option.rb +19 -0
- data/lib/puppet/interface/option_builder.rb +13 -0
- data/lib/puppet/interface/option_manager.rb +2 -1
- data/lib/puppet/metatype/manager.rb +7 -20
- data/lib/puppet/module.rb +4 -1
- data/lib/puppet/network/authconfig.rb +3 -1
- data/lib/puppet/network/authstore.rb +14 -5
- data/lib/puppet/network/handler/fileserver.rb +3 -0
- data/lib/puppet/network/http/webrick.rb +1 -1
- data/lib/puppet/network/rest_authconfig.rb +6 -1
- data/lib/puppet/network/rest_authorization.rb +1 -1
- data/lib/puppet/parser/compiler.rb +8 -11
- data/lib/puppet/parser/functions.rb +1 -6
- data/lib/puppet/parser/functions/create_resources.rb +6 -5
- data/lib/puppet/parser/functions/regsubst.rb +26 -0
- data/lib/puppet/parser/functions/shellquote.rb +26 -0
- data/lib/puppet/parser/functions/sprintf.rb +26 -0
- data/lib/puppet/parser/grammar.ra +34 -60
- data/lib/puppet/parser/lexer.rb +5 -5
- data/lib/puppet/parser/parser.rb +913 -1196
- data/lib/puppet/parser/resource.rb +18 -1
- data/lib/puppet/parser/scope.rb +2 -2
- data/lib/puppet/provider/augeas/augeas.rb +42 -17
- data/lib/puppet/provider/mount/parsed.rb +19 -1
- data/lib/puppet/provider/naginator.rb +9 -1
- data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
- data/lib/puppet/provider/network_device.rb +1 -1
- data/lib/puppet/provider/package/aptitude.rb +1 -0
- data/lib/puppet/provider/package/pacman.rb +94 -0
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
- data/lib/puppet/rails/host.rb +7 -0
- data/lib/puppet/reports/store.rb +15 -0
- data/lib/puppet/resource/catalog.rb +15 -6
- data/lib/puppet/ssl/certificate.rb +6 -0
- data/lib/puppet/ssl/inventory.rb +2 -0
- data/lib/puppet/transaction.rb +9 -17
- data/lib/puppet/transaction/report.rb +3 -3
- data/lib/puppet/type.rb +13 -24
- data/lib/puppet/type/file.rb +8 -2
- data/lib/puppet/type/file/source.rb +2 -2
- data/lib/puppet/type/service.rb +20 -24
- data/lib/puppet/type/ssh_authorized_key.rb +12 -0
- data/lib/puppet/type/user.rb +8 -0
- data/lib/puppet/util.rb +0 -1
- data/lib/puppet/util/network_device.rb +3 -3
- data/lib/puppet/util/settings.rb +1 -1
- data/lib/puppet/util/settings/file_setting.rb +1 -0
- data/lib/semver.rb +65 -0
- data/spec/integration/defaults_spec.rb +23 -1
- data/spec/integration/network/rest_authconfig_spec.rb +145 -0
- data/spec/integration/node/facts_spec.rb +1 -1
- data/spec/integration/parser/functions_spec.rb +1 -1
- data/spec/integration/parser/parser_spec.rb +31 -0
- data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
- data/spec/integration/type_spec.rb +11 -0
- data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
- data/spec/lib/puppet/face/huzzah.rb +1 -0
- data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
- data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
- data/spec/unit/application/agent_spec.rb +2 -2
- data/spec/unit/application/apply_spec.rb +74 -56
- data/spec/unit/application/cert_spec.rb +10 -0
- data/spec/unit/application/device_spec.rb +2 -3
- data/spec/unit/application/face_base_spec.rb +1 -0
- data/spec/unit/application/facts_spec.rb +1 -0
- data/spec/unit/application/inspect_spec.rb +5 -0
- data/spec/unit/configurer/fact_handler_spec.rb +45 -37
- data/spec/unit/configurer_spec.rb +405 -327
- data/spec/unit/face/ca_spec.rb +355 -0
- data/spec/unit/face/certificate_spec.rb +16 -4
- data/spec/unit/face/node_spec.rb +261 -1
- data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
- data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
- data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
- data/spec/unit/indirector/exec_spec.rb +4 -4
- data/spec/unit/indirector/face_spec.rb +3 -1
- data/spec/unit/indirector/facts/couch_spec.rb +2 -2
- data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
- data/spec/unit/indirector/node/exec_spec.rb +1 -1
- data/spec/unit/indirector/report/processor_spec.rb +31 -8
- data/spec/unit/indirector/rest_spec.rb +53 -5
- data/spec/unit/indirector/yaml_spec.rb +18 -0
- data/spec/unit/interface/action_spec.rb +112 -8
- data/spec/unit/interface/face_collection_spec.rb +46 -36
- data/spec/unit/interface/option_spec.rb +44 -0
- data/spec/unit/interface_spec.rb +11 -6
- data/spec/unit/module_spec.rb +38 -9
- data/spec/unit/network/authconfig_spec.rb +23 -0
- data/spec/unit/network/authstore_spec.rb +36 -4
- data/spec/unit/network/handler/fileserver_spec.rb +32 -0
- data/spec/unit/network/rest_authconfig_spec.rb +1 -1
- data/spec/unit/node_spec.rb +1 -0
- data/spec/unit/parser/compiler_spec.rb +8 -46
- data/spec/unit/parser/lexer_spec.rb +27 -17
- data/spec/unit/parser/resource_spec.rb +61 -3
- data/spec/unit/parser/scope_spec.rb +5 -1
- data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
- data/spec/unit/provider/cisco_spec.rb +3 -4
- data/spec/unit/provider/interface/cisco_spec.rb +1 -2
- data/spec/unit/provider/mount/parsed_spec.rb +41 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
- data/spec/unit/provider/network_device_spec.rb +1 -2
- data/spec/unit/provider/package/pacman_spec.rb +237 -0
- data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
- data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
- data/spec/unit/rails/host_spec.rb +8 -0
- data/spec/unit/resource/catalog_spec.rb +55 -8
- data/spec/unit/semver_spec.rb +187 -0
- data/spec/unit/ssl/certificate_spec.rb +25 -0
- data/spec/unit/transaction/report_spec.rb +3 -3
- data/spec/unit/transaction_spec.rb +8 -2
- data/spec/unit/type/file_spec.rb +57 -0
- data/spec/unit/type/interface_spec.rb +1 -2
- data/spec/unit/type/schedule_spec.rb +73 -42
- data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
- data/spec/unit/type/user_spec.rb +8 -0
- data/spec/unit/type/vlan_spec.rb +1 -2
- data/spec/unit/type_spec.rb +66 -0
- data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
- data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
- data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
- data/spec/unit/util/network_device/config_spec.rb +3 -4
- data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
- data/spec/unit/util/network_device_spec.rb +2 -2
- data/spec/unit/util/settings/file_setting_spec.rb +4 -0
- data/spec/unit/util/settings_spec.rb +11 -0
- data/test/lib/puppettest/railstesting.rb +0 -34
- metadata +19 -4
@@ -38,6 +38,7 @@ class Puppet::Interface::Action
|
|
38
38
|
def to_s() "#{@face}##{@name}" end
|
39
39
|
|
40
40
|
attr_reader :name
|
41
|
+
attr_reader :face
|
41
42
|
attr_accessor :default
|
42
43
|
def default?
|
43
44
|
!!@default
|
@@ -195,14 +196,12 @@ class Puppet::Interface::Action
|
|
195
196
|
wrapper = <<WRAPPER
|
196
197
|
def #{@name}(#{decl.join(", ")})
|
197
198
|
#{optn}
|
198
|
-
args
|
199
|
-
|
200
|
-
|
201
|
-
action
|
202
|
-
action.validate_args(args)
|
203
|
-
__invoke_decorations(:before, action, args, options)
|
199
|
+
args = #{args}
|
200
|
+
action = get_action(#{name.inspect})
|
201
|
+
args << action.validate_and_clean(args.pop)
|
202
|
+
__invoke_decorations(:before, action, args, args.last)
|
204
203
|
rval = self.__send__(#{internal_name.inspect}, *args)
|
205
|
-
__invoke_decorations(:after, action, args,
|
204
|
+
__invoke_decorations(:after, action, args, args.last)
|
206
205
|
return rval
|
207
206
|
end
|
208
207
|
WRAPPER
|
@@ -227,8 +226,9 @@ WRAPPER
|
|
227
226
|
end
|
228
227
|
end
|
229
228
|
|
229
|
+
@options << option.name
|
230
|
+
|
230
231
|
option.aliases.each do |name|
|
231
|
-
@options << name
|
232
232
|
@options_hash[name] = option
|
233
233
|
end
|
234
234
|
|
@@ -251,27 +251,61 @@ WRAPPER
|
|
251
251
|
option
|
252
252
|
end
|
253
253
|
|
254
|
-
def
|
255
|
-
#
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
254
|
+
def validate_and_clean(original)
|
255
|
+
# The final set of arguments; effectively a hand-rolled shallow copy of
|
256
|
+
# the original, which protects the caller from the surprises they might
|
257
|
+
# get if they passed us a hash and we mutated it...
|
258
|
+
result = {}
|
259
|
+
|
260
|
+
# Check for multiple aliases for the same option, and canonicalize the
|
261
|
+
# name of the argument while we are about it.
|
262
|
+
overlap = Hash.new do |h, k| h[k] = [] end
|
263
|
+
unknown = []
|
264
|
+
original.keys.each do |name|
|
260
265
|
if option = get_option(name) then
|
261
|
-
|
262
|
-
|
263
|
-
|
266
|
+
canonical = option.name
|
267
|
+
if result.has_key? canonical
|
268
|
+
overlap[canonical] << name
|
269
|
+
else
|
270
|
+
result[canonical] = original[name]
|
264
271
|
end
|
272
|
+
elsif Puppet.settings.include? name
|
273
|
+
result[name] = original[name]
|
274
|
+
else
|
275
|
+
unknown << name
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
unless overlap.empty?
|
280
|
+
msg = overlap.map {|k, v| "(#{k}, #{v.sort.join(', ')})" }.join(", ")
|
281
|
+
raise ArgumentError, "Multiple aliases for the same option passed: #{msg}"
|
282
|
+
end
|
283
|
+
|
284
|
+
unless unknown.empty?
|
285
|
+
msg = unknown.sort.join(", ")
|
286
|
+
raise ArgumentError, "Unknown options passed: #{msg}"
|
287
|
+
end
|
288
|
+
|
289
|
+
# Inject default arguments and check for missing mandating options.
|
290
|
+
missing = []
|
291
|
+
options.map {|x| get_option(x) }.each do |option|
|
292
|
+
name = option.name
|
293
|
+
next if result.has_key? name
|
294
|
+
|
295
|
+
if option.has_default?
|
296
|
+
result[name] = option.default
|
297
|
+
elsif option.required?
|
298
|
+
missing << name
|
265
299
|
end
|
266
300
|
end
|
267
301
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
end
|
302
|
+
unless missing.empty?
|
303
|
+
msg = missing.sort.join(', ')
|
304
|
+
raise ArgumentError, "The following options are required: #{msg}"
|
305
|
+
end
|
272
306
|
|
273
|
-
|
274
|
-
|
307
|
+
# All done.
|
308
|
+
return result
|
275
309
|
end
|
276
310
|
|
277
311
|
########################################################################
|
@@ -7,13 +7,14 @@ module Puppet::Interface::ActionManager
|
|
7
7
|
require 'puppet/interface/action_builder'
|
8
8
|
|
9
9
|
@actions ||= {}
|
10
|
-
@default_action ||= nil
|
11
10
|
raise "Action #{name} already defined for #{self}" if action?(name)
|
11
|
+
|
12
12
|
action = Puppet::Interface::ActionBuilder.build(self, name, &block)
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
|
14
|
+
if action.default and current = get_default_action
|
15
|
+
raise "Actions #{current.name} and #{name} cannot both be default"
|
16
16
|
end
|
17
|
+
|
17
18
|
@actions[action.name] = action
|
18
19
|
end
|
19
20
|
|
@@ -61,7 +62,11 @@ module Puppet::Interface::ActionManager
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def get_default_action
|
64
|
-
|
65
|
+
default = actions.map {|x| get_action(x) }.select {|x| x.default }
|
66
|
+
if default.length > 1
|
67
|
+
raise "The actions #{default.map(&:name).join(", ")} cannot all be default"
|
68
|
+
end
|
69
|
+
default.first
|
65
70
|
end
|
66
71
|
|
67
72
|
def action?(name)
|
@@ -1,8 +1,6 @@
|
|
1
1
|
require 'puppet/interface'
|
2
2
|
|
3
3
|
module Puppet::Interface::FaceCollection
|
4
|
-
SEMVER_VERSION = /^(\d+)\.(\d+)\.(\d+)([A-Za-z][0-9A-Za-z-]*|)$/
|
5
|
-
|
6
4
|
@faces = Hash.new { |hash, key| hash[key] = {} }
|
7
5
|
|
8
6
|
def self.faces
|
@@ -17,55 +15,36 @@ module Puppet::Interface::FaceCollection
|
|
17
15
|
@faces.keys.select {|name| @faces[name].length > 0 }
|
18
16
|
end
|
19
17
|
|
20
|
-
def self.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def self.semver_to_array(v)
|
25
|
-
parts = SEMVER_VERSION.match(v).to_a[1..4]
|
26
|
-
parts[0..2] = parts[0..2].map { |e| e.to_i }
|
27
|
-
parts
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.cmp_semver(a, b)
|
31
|
-
a, b = [a, b].map do |x| semver_to_array(x) end
|
32
|
-
|
33
|
-
cmp = a[0..2] <=> b[0..2]
|
34
|
-
if cmp == 0
|
35
|
-
cmp = a[3] <=> b[3]
|
36
|
-
cmp = +1 if a[3].empty? && !b[3].empty?
|
37
|
-
cmp = -1 if b[3].empty? && !a[3].empty?
|
38
|
-
end
|
39
|
-
cmp
|
18
|
+
def self.[](name, version)
|
19
|
+
name = underscorize(name)
|
20
|
+
get_face(name, version) or load_face(name, version)
|
40
21
|
end
|
41
22
|
|
42
|
-
def self.
|
43
|
-
|
44
|
-
return false if desired == :current
|
45
|
-
return false if target == :current
|
46
|
-
|
47
|
-
# REVISIT: Should probably fail if the matcher is not valid.
|
48
|
-
prefix = desired.split('.').map {|x| x =~ /^\d+$/ and x.to_i }
|
49
|
-
have = semver_to_array(target)
|
23
|
+
def self.get_action_for_face(name, action_name, version)
|
24
|
+
name = underscorize(name)
|
50
25
|
|
51
|
-
|
52
|
-
|
26
|
+
# If the version they request specifically doesn't exist, don't search
|
27
|
+
# elsewhere. Usually this will start from :current and all...
|
28
|
+
return nil unless face = self[name, version]
|
29
|
+
unless action = face.get_action(action_name)
|
30
|
+
# ...we need to search for it bound to an o{lder,ther} version. Since
|
31
|
+
# we load all actions when the face is first references, this will be in
|
32
|
+
# memory in the known set of versions of the face.
|
33
|
+
(@faces[name].keys - [ :current ]).sort.reverse.each do |version|
|
34
|
+
break if action = @faces[name][version].get_action(action_name)
|
35
|
+
end
|
53
36
|
end
|
54
|
-
return true
|
55
|
-
end
|
56
37
|
|
57
|
-
|
58
|
-
name = underscorize(name)
|
59
|
-
get_face(name, version) or load_face(name, version)
|
38
|
+
return action
|
60
39
|
end
|
61
40
|
|
62
41
|
# get face from memory, without loading.
|
63
|
-
def self.get_face(name,
|
42
|
+
def self.get_face(name, pattern)
|
64
43
|
return nil unless @faces.has_key? name
|
44
|
+
return @faces[name][:current] if pattern == :current
|
65
45
|
|
66
|
-
|
67
|
-
|
68
|
-
found = @faces[name].keys.select {|v| prefix_match?(desired_version, v) }.sort.last
|
46
|
+
versions = @faces[name].keys - [ :current ]
|
47
|
+
found = SemVer.find_matching(pattern, versions)
|
69
48
|
return @faces[name][found]
|
70
49
|
end
|
71
50
|
|
@@ -77,9 +56,7 @@ module Puppet::Interface::FaceCollection
|
|
77
56
|
#
|
78
57
|
# We use require to avoid executing the code multiple times, like any
|
79
58
|
# other Ruby library that we might want to use. --daniel 2011-04-06
|
80
|
-
|
81
|
-
require "puppet/face/#{name}"
|
82
|
-
|
59
|
+
if safely_require name then
|
83
60
|
# If we wanted :current, we need to index to find that; direct version
|
84
61
|
# requests just work™ as they go. --daniel 2011-04-06
|
85
62
|
if version == :current then
|
@@ -108,21 +85,35 @@ module Puppet::Interface::FaceCollection
|
|
108
85
|
# versions here and return the last item in that set.
|
109
86
|
#
|
110
87
|
# --daniel 2011-04-06
|
111
|
-
latest_ver = @faces[name].keys.sort
|
88
|
+
latest_ver = @faces[name].keys.sort.last
|
112
89
|
@faces[name][:current] = @faces[name][latest_ver]
|
113
90
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
Puppet.err "Failed to load face #{name}:\n#{e}"
|
120
|
-
# ...but we just carry on after complaining.
|
91
|
+
end
|
92
|
+
|
93
|
+
unless version == :current or get_face(name, version)
|
94
|
+
# Try an obsolete version of the face, if needed, to see if that helps?
|
95
|
+
safely_require name, version
|
121
96
|
end
|
122
97
|
|
123
98
|
return get_face(name, version)
|
124
99
|
end
|
125
100
|
|
101
|
+
def self.safely_require(name, version = nil)
|
102
|
+
path = File.join 'puppet' ,'face', version.to_s, name.to_s
|
103
|
+
require path
|
104
|
+
true
|
105
|
+
|
106
|
+
rescue LoadError => e
|
107
|
+
raise unless e.message =~ %r{-- #{path}$}
|
108
|
+
# ...guess we didn't find the file; return a much better problem.
|
109
|
+
nil
|
110
|
+
rescue SyntaxError => e
|
111
|
+
raise unless e.message =~ %r{#{path}\.rb:\d+: }
|
112
|
+
Puppet.err "Failed to load face #{name}:\n#{e}"
|
113
|
+
# ...but we just carry on after complaining.
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
|
126
117
|
def self.register(face)
|
127
118
|
@faces[underscorize(face.name)][face.version] = face
|
128
119
|
end
|
@@ -6,6 +6,7 @@ class Puppet::Interface::Option
|
|
6
6
|
def initialize(parent, *declaration, &block)
|
7
7
|
@parent = parent
|
8
8
|
@optparse = []
|
9
|
+
@default = nil
|
9
10
|
|
10
11
|
# Collect and sort the arguments in the declaration.
|
11
12
|
dups = {}
|
@@ -81,8 +82,26 @@ class Puppet::Interface::Option
|
|
81
82
|
!!@required
|
82
83
|
end
|
83
84
|
|
85
|
+
def has_default?
|
86
|
+
!!@default
|
87
|
+
end
|
88
|
+
|
89
|
+
def default=(proc)
|
90
|
+
required and raise ArgumentError, "#{self} can't be optional and have a default value"
|
91
|
+
proc.is_a? Proc or raise ArgumentError, "default value for #{self} is a #{proc.class.name.inspect}, not a proc"
|
92
|
+
@default = proc
|
93
|
+
end
|
94
|
+
|
95
|
+
def default
|
96
|
+
@default and @default.call
|
97
|
+
end
|
98
|
+
|
84
99
|
attr_reader :parent, :name, :aliases, :optparse
|
85
100
|
attr_accessor :required
|
101
|
+
def required=(value)
|
102
|
+
has_default? and raise ArgumentError, "#{self} can't be optional and have a default value"
|
103
|
+
@required = value
|
104
|
+
end
|
86
105
|
|
87
106
|
attr_accessor :before_action
|
88
107
|
def before_action=(proc)
|
@@ -51,4 +51,17 @@ class Puppet::Interface::OptionBuilder
|
|
51
51
|
def required(value = true)
|
52
52
|
@option.required = value
|
53
53
|
end
|
54
|
+
|
55
|
+
def default_to(&block)
|
56
|
+
block or raise ArgumentError, "#{@option} default_to requires a block"
|
57
|
+
if @option.has_default?
|
58
|
+
raise ArgumentError, "#{@option} already has a default value"
|
59
|
+
end
|
60
|
+
# Ruby 1.8 treats a block without arguments as accepting any number; 1.9
|
61
|
+
# gets this right, so we work around it for now... --daniel 2011-07-20
|
62
|
+
unless block.arity == 0 or (RUBY_VERSION =~ /^1\.8/ and block.arity == -1)
|
63
|
+
raise ArgumentError, "#{@option} default_to block should not take any arguments"
|
64
|
+
end
|
65
|
+
@option.default = block
|
66
|
+
end
|
54
67
|
end
|
@@ -61,10 +61,9 @@ module Manager
|
|
61
61
|
|
62
62
|
# Then create the class.
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
klass = genclass(
|
65
|
+
name,
|
66
66
|
:parent => (parent || Puppet::Type),
|
67
|
-
|
68
67
|
:overwrite => true,
|
69
68
|
:hash => @types,
|
70
69
|
:attributes => options,
|
@@ -87,14 +86,11 @@ module Manager
|
|
87
86
|
|
88
87
|
# Now set up autoload any providers that might exist for this type.
|
89
88
|
|
90
|
-
|
91
|
-
klass,
|
92
|
-
|
93
|
-
"puppet/provider/#{klass.name.to_s}"
|
94
|
-
)
|
89
|
+
klass.providerloader = Puppet::Util::Autoload.new(klass, "puppet/provider/#{klass.name.to_s}")
|
95
90
|
|
96
|
-
# We have to load everything so that we can figure out the default
|
91
|
+
# We have to load everything so that we can figure out the default provider.
|
97
92
|
klass.providerloader.loadall
|
93
|
+
klass.providify unless klass.providers.empty?
|
98
94
|
|
99
95
|
klass
|
100
96
|
end
|
@@ -103,11 +99,7 @@ module Manager
|
|
103
99
|
def rmtype(name)
|
104
100
|
# Then create the class.
|
105
101
|
|
106
|
-
|
107
|
-
name,
|
108
|
-
|
109
|
-
:hash => @types
|
110
|
-
)
|
102
|
+
klass = rmclass(name, :hash => @types)
|
111
103
|
|
112
104
|
singleton_class.send(:remove_method, "new#{name}") if respond_to?("new#{name}")
|
113
105
|
end
|
@@ -132,12 +124,7 @@ module Manager
|
|
132
124
|
# Create a loader for Puppet types.
|
133
125
|
def typeloader
|
134
126
|
unless defined?(@typeloader)
|
135
|
-
|
136
|
-
@typeloader = Puppet::Util::Autoload.new(
|
137
|
-
self,
|
138
|
-
|
139
|
-
"puppet/type", :wrap => false
|
140
|
-
)
|
127
|
+
@typeloader = Puppet::Util::Autoload.new(self, "puppet/type", :wrap => false)
|
141
128
|
end
|
142
129
|
|
143
130
|
@typeloader
|
data/lib/puppet/module.rb
CHANGED
@@ -42,7 +42,10 @@ class Puppet::Module
|
|
42
42
|
def has_metadata?
|
43
43
|
return false unless metadata_file
|
44
44
|
|
45
|
-
FileTest.exist?(metadata_file)
|
45
|
+
return false unless FileTest.exist?(metadata_file)
|
46
|
+
|
47
|
+
metadata = PSON.parse File.read(metadata_file)
|
48
|
+
return metadata.is_a?(Hash) && !metadata.keys.empty?
|
46
49
|
end
|
47
50
|
|
48
51
|
def initialize(name, environment = nil)
|
@@ -102,7 +102,7 @@ module Puppet
|
|
102
102
|
name = $3 if $2 == "path"
|
103
103
|
name.chomp!
|
104
104
|
right = newrights.newright(name, count, @file)
|
105
|
-
when /^\s*(allow|deny|method|environment|auth(?:enticated)?)\s+(
|
105
|
+
when /^\s*(allow|deny|method|environment|auth(?:enticated)?)\s+(.+?)(\s*#.*)?$/
|
106
106
|
parse_right_directive(right, $1, $2, count)
|
107
107
|
else
|
108
108
|
raise ConfigurationError, "Invalid line #{count}: #{line}"
|
@@ -130,6 +130,7 @@ module Puppet
|
|
130
130
|
end
|
131
131
|
|
132
132
|
def parse_right_directive(right, var, value, count)
|
133
|
+
value.strip!
|
133
134
|
case var
|
134
135
|
when "allow"
|
135
136
|
modify_right(right, :allow, value, "allowing %s access", count)
|
@@ -159,6 +160,7 @@ module Puppet
|
|
159
160
|
def modify_right(right, method, value, msg, count)
|
160
161
|
value.split(/\s*,\s*/).each do |val|
|
161
162
|
begin
|
163
|
+
val.strip!
|
162
164
|
right.info msg % val
|
163
165
|
right.send(method, val)
|
164
166
|
rescue AuthStoreError => detail
|
@@ -182,9 +182,11 @@ module Puppet
|
|
182
182
|
# we'll return a pattern of puppet.reductivelabs.com
|
183
183
|
def interpolate(match)
|
184
184
|
clone = dup
|
185
|
-
|
186
|
-
|
187
|
-
|
185
|
+
if @name == :dynamic
|
186
|
+
clone.pattern = clone.pattern.reverse.collect do |p|
|
187
|
+
p.gsub(/\$(\d)/) { |m| match[$1.to_i] }
|
188
|
+
end.join(".")
|
189
|
+
end
|
188
190
|
clone
|
189
191
|
end
|
190
192
|
|
@@ -199,8 +201,13 @@ module Puppet
|
|
199
201
|
|
200
202
|
# Does the name match our pattern?
|
201
203
|
def matchname?(name)
|
202
|
-
|
203
|
-
|
204
|
+
case @name
|
205
|
+
when :domain, :dynamic, :opaque
|
206
|
+
name = munge_name(name)
|
207
|
+
(pattern == name) or (not exact? and pattern.zip(name).all? { |p,n| p == n })
|
208
|
+
when :regex
|
209
|
+
Regexp.new(pattern.slice(1..-2)).match(name)
|
210
|
+
end
|
204
211
|
end
|
205
212
|
|
206
213
|
# Convert the name to a common pattern.
|
@@ -240,6 +247,8 @@ module Puppet
|
|
240
247
|
[:dynamic,:exact,nil,munge_name(value)]
|
241
248
|
when /^\w[-.@\w]*$/ # ? Just like a host name but allow '@'s and ending '.'s
|
242
249
|
[:opaque,:exact,nil,[value]]
|
250
|
+
when /^\/.*\/$/ # a regular expression
|
251
|
+
[:regex,:inexact,nil,value]
|
243
252
|
else
|
244
253
|
raise AuthStoreError, "Invalid pattern #{value}"
|
245
254
|
end
|