diff options
| author | Max Martin <max@puppetlabs.com> | 2011-03-17 13:42:46 -0700 |
|---|---|---|
| committer | Max Martin <max@puppetlabs.com> | 2011-03-17 13:42:46 -0700 |
| commit | 462a56060f0fffc7b8577f252000195e9384fb7a (patch) | |
| tree | c3447659483c2e286df255053655b00a46af4070 /lib/puppet/parameter | |
| parent | 17f673dd6fee08309970f8ff721855cf1644b45f (diff) | |
| parent | ec1aa192825f17afbe4dc12be1e0f2d644d74155 (diff) | |
Merge branch 'feature/2.6.next/4884-an-exec-provider-that-executes-unfiltered-bash-code' into 2.6.next
* feature/2.6.next/4884-an-exec-provider-that-executes-unfiltered-bash-code:
(#4884) Revise new exec tests, add a few more
(#4884) Add an shell provider for execs
(#4884) Fix Test::Unit exec tests
(#4884) Break the exec type out to have a posix provider
(#4884) Add consistent path validation and behavior
(#4884) Add expand_path to requiring the spec_helper
(#4884) Autorequire shared behaviors and method to silence warnings
(#4884) Fix whitespace
(#4884) Get rid of open3 require since it wasn't being used
Diffstat (limited to 'lib/puppet/parameter')
| -rw-r--r-- | lib/puppet/parameter/path.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/puppet/parameter/path.rb b/lib/puppet/parameter/path.rb new file mode 100644 index 000000000..44886afd0 --- /dev/null +++ b/lib/puppet/parameter/path.rb @@ -0,0 +1,42 @@ +require 'puppet/parameter' + +class Puppet::Parameter::Path < Puppet::Parameter + def self.accept_arrays(bool = true) + @accept_arrays = !!bool + end + def self.arrays? + @accept_arrays + end + + def validate_path(paths) + if paths.is_a?(Array) and ! self.class.arrays? then + fail "#{name} only accepts a single path, not an array of paths" + end + + # We *always* support Unix path separators, as Win32 does now too. + absolute = "[/#{::Regexp.quote(::File::SEPARATOR)}]" + win32 = Puppet.features.microsoft_windows? + + Array(paths).each do |path| + next if path =~ %r{^#{absolute}} + next if win32 and path =~ %r{^(?:[a-zA-Z]:)?#{absolute}} + fail("#{name} must be a fully qualified path") + end + + paths + end + + # This will be overridden if someone uses the validate option, which is why + # it just delegates to the other, useful, method. + def unsafe_validate(paths) + validate_path(paths) + end + + # Likewise, this might be overridden, but by default... + def unsafe_munge(paths) + if paths.is_a?(Array) and ! self.class.arrays? then + fail "#{name} only accepts a single path, not an array of paths" + end + paths + end +end |
