Sha256: 55362327fa840094aa1b8740389852811cd8eb933d7b9e17c8654ec8d6cdcc81

Contents?: true

Size: 1.92 KB

Versions: 28

Compression:

Stored size: 1.92 KB

Contents

require 'puppet/file_serving/metadata'
require 'puppet/indirector/file_metadata'
require 'puppet/indirector/rest'

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

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

    _, file_metadata = api.get_file_metadata(
      path: Puppet::Util.uri_unescape(url.path),
      environment: request.environment.to_s,
      links: request.options[:links],
      checksum_type: request.options[:checksum_type],
      source_permissions: request.options[:source_permissions]
    )
    file_metadata
  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

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

    _, file_metadatas = api.get_file_metadatas(
      path: Puppet::Util.uri_unescape(url.path),
      environment: request.environment.to_s,
      recurse: request.options[:recurse],
      recurselimit: request.options[:recurselimit],
      ignore: request.options[:ignore],
      links: request.options[:links],
      checksum_type: request.options[:checksum_type],
      source_permissions: request.options[:source_permissions],
    )
    file_metadatas
  rescue Puppet::HTTP::ResponseError => e
    # since it's search, return empty array instead of nil
    return [] if e.response.code == 404

    raise convert_to_http_error(e.response)
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
puppet-7.1.0 lib/puppet/indirector/file_metadata/rest.rb
puppet-7.1.0-x86-mingw32 lib/puppet/indirector/file_metadata/rest.rb
puppet-7.1.0-x64-mingw32 lib/puppet/indirector/file_metadata/rest.rb
puppet-7.1.0-universal-darwin lib/puppet/indirector/file_metadata/rest.rb
puppet-7.0.0 lib/puppet/indirector/file_metadata/rest.rb
puppet-7.0.0-x86-mingw32 lib/puppet/indirector/file_metadata/rest.rb
puppet-7.0.0-x64-mingw32 lib/puppet/indirector/file_metadata/rest.rb
puppet-7.0.0-universal-darwin lib/puppet/indirector/file_metadata/rest.rb