summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-18 23:39:12 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-18 23:39:12 +0000
commite952029322eab81580e9c05f5310d78068d2f9bf (patch)
tree7130e03d66682bb99be96f82bdc49a51945ac567 /lib
parent66546610ceb5f14d7dce1da9286def4b1497bd60 (diff)
downloadpuppet-e952029322eab81580e9c05f5310d78068d2f9bf.tar.gz
puppet-e952029322eab81580e9c05f5310d78068d2f9bf.tar.xz
puppet-e952029322eab81580e9c05f5310d78068d2f9bf.zip
Adding #541. There is now a "generate" function.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2299 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index cef694b85..b02ea4308 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -252,6 +252,41 @@ module Functions
vals.join(", ")
end
end
+
+ 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
end
end