Sha256: 41d2ffe25e9b1b8edfe8f606ed31e8a3c0b2eaf5bade5beaf3d30170926d0efc

Contents?: true

Size: 1.41 KB

Versions: 37

Compression:

Stored size: 1.41 KB

Contents

# Runs an external command and returns the results
Puppet::Parser::Functions::newfunction(:generate, :type => :rvalue,
    :doc => "Calls an external command on the Puppet master 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|

      raise Puppet::ParseError, "Generators must be fully qualified" unless args[0] =~ /^#{File::SEPARATOR}/

      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
        Dir.chdir(File.dirname(args[0])) { Puppet::Util.execute(args) }
      rescue Puppet::ExecutionFailure => detail
        raise Puppet::ParseError, "Failed to execute generator #{args[0]}: #{detail}"
      end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
puppet-2.6.18 lib/puppet/parser/functions/generate.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
puppet-2.6.17 lib/puppet/parser/functions/generate.rb
supply_drop-0.10.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
supply_drop-0.10.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
puppet-2.6.16 lib/puppet/parser/functions/generate.rb
puppet-2.6.15 lib/puppet/parser/functions/generate.rb
supply_drop-0.9.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
supply_drop-0.8.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
supply_drop-0.8.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
puppet-2.7.11 lib/puppet/parser/functions/generate.rb
puppet-2.6.14 lib/puppet/parser/functions/generate.rb
supply_drop-0.7.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
supply_drop-0.6.1 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
supply_drop-0.6.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/parser/functions/generate.rb
puppet-2.6.13 lib/puppet/parser/functions/generate.rb
puppet-2.7.9 lib/puppet/parser/functions/generate.rb
puppet-2.7.8 lib/puppet/parser/functions/generate.rb
puppet-2.7.6 lib/puppet/parser/functions/generate.rb