Sha256: f16d9f57e5eed13df9f0a329efb119d2fa2a46bec84638573170a73ed22bcfae

Contents?: true

Size: 1.58 KB

Versions: 6

Compression:

Stored size: 1.58 KB

Contents

# 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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
puppet-0.24.9 lib/puppet/parser/functions/generate.rb
puppet-0.25.1 lib/puppet/parser/functions/generate.rb
puppet-0.25.0 lib/puppet/parser/functions/generate.rb
puppet-0.24.6 lib/puppet/parser/functions/generate.rb
puppet-0.24.7 lib/puppet/parser/functions/generate.rb
puppet-0.24.8 lib/puppet/parser/functions/generate.rb