Sha256: 87c421733bd7b41effef37e27c0971a296d8bcf5676b61964bf6cfd98f9a92b6

Contents?: true

Size: 1.38 KB

Versions: 134

Compression:

Stored size: 1.38 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}"

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

    if last_modified = http_response['last-modified']
      mtime = DateTime.httpdate(last_modified).to_time
      @checksums[:mtime] = "{mtime}#{mtime}"
    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, :mtime ].each do |type|
      @checksum_type = type
      @checksum = @checksums[type]
      return if @checksum
    end
  end
end

Version data entries

134 entries across 134 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/file_serving/http_metadata.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/file_serving/http_metadata.rb
puppet-4.10.12 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.12-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.12-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.12-universal-darwin lib/puppet/file_serving/http_metadata.rb
puppet-4.10.11 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.11-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.11-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.11-universal-darwin lib/puppet/file_serving/http_metadata.rb
puppet-4.10.10 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.10-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.10-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.10-universal-darwin lib/puppet/file_serving/http_metadata.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/file_serving/http_metadata.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/file_serving/http_metadata.rb
puppet-4.10.9 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.9-x86-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.9-x64-mingw32 lib/puppet/file_serving/http_metadata.rb
puppet-4.10.9-universal-darwin lib/puppet/file_serving/http_metadata.rb