Sha256: 603dea8837dde8e224c2ce261cac4adf0fcc8deba4397073bb9ecadd7fb6b242

Contents?: true

Size: 908 Bytes

Versions: 31

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true

# Read a file and return its contents.
Puppet::Functions.create_function(:'file::read', Puppet::Functions::InternalFunction) do
  # @param filename Absolute path or Puppet file path.
  # @example Read a file from disk
  #   file::read('/tmp/i_dumped_this_here')
  # @example Read a file from the modulepath
  #   file::read('example/files/VERSION')
  dispatch :read do
    scope_param
    required_param 'String', :filename
    return_type 'String'
  end

  def read(scope, filename)
    Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)
    found = Puppet::Parser::Files.find_file(filename, scope.compiler.environment)
    unless found && Puppet::FileSystem.exist?(found)
      raise Puppet::ParseErrorWithIssue.from_issue_and_stack(
        Puppet::Pops::Issues::NO_SUCH_FILE_OR_DIRECTORY, file: filename
      )
    end

    File.read(found)
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
bolt-1.49.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.48.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.47.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.45.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.44.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.43.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.42.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.41.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.40.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.39.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.38.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.37.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.36.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.35.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.34.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.33.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.32.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.31.1 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.31.0 bolt-modules/file/lib/puppet/functions/file/read.rb
bolt-1.30.1 bolt-modules/file/lib/puppet/functions/file/read.rb