Sha256: a036d8cb2b76125af19fdc403ba321d61609c18c34e068d81d7f923c1aad8ec1

Contents?: true

Size: 1.54 KB

Versions: 26

Compression:

Stored size: 1.54 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 Puppet::Util.absolute_path?(args[0])

      if Puppet.features.microsoft_windows?
        valid = args[0] =~ /^[a-z]:(?:[\/\\][\w.-]+)+$/i
      else
        valid = args[0] =~ /^[-\/\w.]+$/
      end

      unless valid
        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

26 entries across 26 versions & 3 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/parser/functions/generate.rb
puppet-parse-0.1.3 lib/vendor/puppet/parser/functions/generate.rb
puppet-parse-0.1.2 lib/vendor/puppet/parser/functions/generate.rb
puppet-parse-0.1.1 lib/vendor/puppet/parser/functions/generate.rb
puppet-2.7.26 lib/puppet/parser/functions/generate.rb
puppet-2.7.25 lib/puppet/parser/functions/generate.rb
puppet-2.7.24 lib/puppet/parser/functions/generate.rb
puppet-2.7.23 lib/puppet/parser/functions/generate.rb
puppet-2.7.22 lib/puppet/parser/functions/generate.rb
puppet-parse-0.1.0 lib/vendor/puppet/parser/functions/generate.rb
puppet-parse-0.0.6 lib/vendor/puppet/parser/functions/generate.rb
puppet-2.7.21 lib/puppet/parser/functions/generate.rb
puppet-parse-0.0.5 lib/vendor/puppet/parser/functions/generate.rb
puppet-parse-0.0.4 lib/vendor/puppet/parser/functions/generate.rb
puppet-parse-0.0.2 lib/vendor/puppet/parser/functions/generate.rb
puppet-2.7.20 lib/puppet/parser/functions/generate.rb
puppet-2.7.20.rc1 lib/puppet/parser/functions/generate.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/parser/functions/generate.rb
puppet-2.7.19 lib/puppet/parser/functions/generate.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/parser/functions/generate.rb