Sha256: f36540bf590bf20b4bb0d4d2365e655b3c7b3bdbd8559e7c980a146b9a58a952

Contents?: true

Size: 1.07 KB

Versions: 28

Compression:

Stored size: 1.07 KB

Contents

require 'puppet/file_serving/content'
require 'puppet/indirector/file_content'
require 'puppet/indirector/rest'

class Puppet::Indirector::FileContent::Rest < Puppet::Indirector::REST
  desc "Retrieve file contents via a REST HTTP interface."

  def find(request)
    content = StringIO.new
    content.binmode

    url = URI.parse(Puppet::Util.uri_encode(request.uri))
    session = Puppet.lookup(:http_session)
    api = session.route_to(:fileserver, url: url)

    api.get_file_content(
      path: Puppet::Util.uri_unescape(url.path),
      environment: request.environment.to_s,
    ) do |data|
      content << data
    end

    Puppet::FileServing::Content.from_binary(content.string)
  rescue Puppet::HTTP::ResponseError => e
    if e.response.code == 404
      return nil unless request.options[:fail_on_404]

      _, body = parse_response(e.response)
      msg = _("Find %{uri} resulted in 404 with the message: %{body}") % { uri: elide(e.response.url.path, 100), body: body }
      raise Puppet::Error, msg
    else
      raise convert_to_http_error(e.response)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
puppet-7.6.1 lib/puppet/indirector/file_content/rest.rb
puppet-7.6.1-x86-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.6.1-x64-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.6.1-universal-darwin lib/puppet/indirector/file_content/rest.rb
puppet-7.5.0 lib/puppet/indirector/file_content/rest.rb
puppet-7.5.0-x86-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.5.0-x64-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.5.0-universal-darwin lib/puppet/indirector/file_content/rest.rb
puppet-7.4.1 lib/puppet/indirector/file_content/rest.rb
puppet-7.4.1-x86-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.4.1-x64-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.4.1-universal-darwin lib/puppet/indirector/file_content/rest.rb
puppet-7.4.0 lib/puppet/indirector/file_content/rest.rb
puppet-7.4.0-x86-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.4.0-x64-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.4.0-universal-darwin lib/puppet/indirector/file_content/rest.rb
puppet-7.3.0 lib/puppet/indirector/file_content/rest.rb
puppet-7.3.0-x86-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.3.0-x64-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-7.3.0-universal-darwin lib/puppet/indirector/file_content/rest.rb