Sha256: 53888b034dcab715aad8dd6263745392d89da5c725775956481c115ca08d6ffe

Contents?: true

Size: 1.15 KB

Versions: 12

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require_relative '../../../puppet/file_serving/content'
require_relative '../../../puppet/indirector/file_content'
require_relative '../../../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

12 entries across 12 versions & 1 rubygems

Version Path
puppet-8.5.1 lib/puppet/indirector/file_content/rest.rb
puppet-8.5.1-x86-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-8.5.1-x64-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-8.5.1-universal-darwin lib/puppet/indirector/file_content/rest.rb
puppet-8.5.0 lib/puppet/indirector/file_content/rest.rb
puppet-8.5.0-x86-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-8.5.0-x64-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-8.5.0-universal-darwin lib/puppet/indirector/file_content/rest.rb
puppet-8.4.0 lib/puppet/indirector/file_content/rest.rb
puppet-8.4.0-x86-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-8.4.0-x64-mingw32 lib/puppet/indirector/file_content/rest.rb
puppet-8.4.0-universal-darwin lib/puppet/indirector/file_content/rest.rb