summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/functions/generate.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-09-27 21:30:49 +0200
committerLuke Kanies <luke@madstop.com>2008-09-27 21:30:49 +0200
commitb96bdc6a63f7be6b724c2aa7ad0ea007cba81718 (patch)
tree6d334ea12e1468b34160fa36da29dd7d78ac31ea /lib/puppet/parser/functions/generate.rb
parente20f02af4a93478c5b08b7681caa12cd72b4a3a6 (diff)
parent3749267093923692d6e7bc0c9ce83b43a487b19e (diff)
downloadpuppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.tar.gz
puppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.tar.xz
puppet-b96bdc6a63f7be6b724c2aa7ad0ea007cba81718.zip
Merge branch '0.24.x' of git://github.com/jamtur01/puppet into 0.24.x
Diffstat (limited to 'lib/puppet/parser/functions/generate.rb')
-rw-r--r--lib/puppet/parser/functions/generate.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/generate.rb b/lib/puppet/parser/functions/generate.rb
new file mode 100644
index 000000000..1be9016ed
--- /dev/null
+++ b/lib/puppet/parser/functions/generate.rb
@@ -0,0 +1,35 @@
+# Runs an external command and returns the results
+Puppet::Parser::Functions::newfunction(:generate, :type => :rvalue,
+ :doc => "Calls an external command and returns the results of the
+ command. Any arguments are passed to the external command as
+ arguments. If the generator does not exit with return code of 0,
+ the generator is considered to have failed and a parse error is
+ thrown. Generators can only have file separators, alphanumerics, dashes,
+ and periods in them. This function will attempt to protect you from
+ malicious generator calls (e.g., those with '..' in them), but it can
+ never be entirely safe. No subshell is used to execute
+ generators, so all shell metacharacters are passed directly to
+ the generator.") do |args|
+
+ unless args[0] =~ /^#{File::SEPARATOR}/
+ raise Puppet::ParseError, "Generators must be fully qualified"
+ end
+
+ unless args[0] =~ /^[-#{File::SEPARATOR}\w.]+$/
+ raise Puppet::ParseError,
+ "Generators can only contain alphanumerics, file separators, and dashes"
+ end
+
+ if args[0] =~ /\.\./
+ raise Puppet::ParseError,
+ "Can not use generators with '..' in them."
+ end
+
+ begin
+ output = Puppet::Util.execute(args)
+ rescue Puppet::ExecutionFailure => detail
+ raise Puppet::ParseError, "Failed to execute generator %s: %s" %
+ [args[0], detail]
+ end
+ output
+end