Sha256: ef19856de99f887d8fab670da093b242b3335037f81651ecdc4da9d9504f1d84

Contents?: true

Size: 1.45 KB

Versions: 28

Compression:

Stored size: 1.45 KB

Contents

require 'puppet/file_serving/metadata'

# Simplified metadata representation, suitable for the information
# that is available from HTTP headers.
class Puppet::FileServing::HttpMetadata < Puppet::FileServing::Metadata

  def initialize(http_response, path = '/dev/null')
    super(path)

    # ignore options that do not apply to HTTP metadata
    @owner = @group = @mode = nil

    # hash available checksums for eventual collection
    @checksums = {}
    # use a default mtime in case there is no usable HTTP header
    @checksums[:mtime] = "{mtime}#{Time.now}"

    checksum = http_response['content-md5']
    if checksum
      # convert base64 digest to hex
      checksum = checksum.unpack("m0").first.unpack("H*").first
      @checksums[:md5] = "{md5}#{checksum}"
    end

    last_modified = http_response['last-modified']
    if last_modified
      mtime = DateTime.httpdate(last_modified).to_time
      @checksums[:mtime] = "{mtime}#{mtime.utc}"
    end

    @ftype = 'file'

    self
  end

  # Override of the parent class method. Does not call super!
  # We can only return metadata that was extracted from the
  # HTTP headers during #initialize.
  def collect
    # Prefer the checksum_type from the indirector request options
    # but fall back to the alternative otherwise
    [ @checksum_type, :md5, :sha256, :sha384, :sha512, :sha224, :mtime ].each do |type|
      @checksum_type = type
      @checksum = @checksums[type]
      return if @checksum
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
puppet-6.10.1 lib/puppet/file_serving/http_metadata.rb
puppet-6.10.1-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.10.1-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.10.1-universal-darwin lib/puppet/file_serving/http_metadata.rb
puppet-6.10.0 lib/puppet/file_serving/http_metadata.rb
puppet-6.10.0-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.10.0-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.10.0-universal-darwin lib/puppet/file_serving/http_metadata.rb
puppet-6.9.0 lib/puppet/file_serving/http_metadata.rb
puppet-6.9.0-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.9.0-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.9.0-universal-darwin lib/puppet/file_serving/http_metadata.rb
puppet-6.8.1 lib/puppet/file_serving/http_metadata.rb
puppet-6.8.1-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.8.1-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.8.1-universal-darwin lib/puppet/file_serving/http_metadata.rb
puppet-6.8.0 lib/puppet/file_serving/http_metadata.rb
puppet-6.8.0-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.8.0-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-6.8.0-universal-darwin lib/puppet/file_serving/http_metadata.rb