Class: Puppet::FileServing::HttpMetadata

Inherits:
Metadata show all
Defined in:
lib/puppet/file_serving/http_metadata.rb

Overview

Simplified metadata representation, suitable for the information that is available from HTTP headers.

Constant Summary

Constants inherited from Metadata

Metadata::PARAM_ORDER

Constants included from Indirector

Indirector::BadNameRegexp

Instance Attribute Summary

Attributes inherited from Metadata

#checksum, #checksum_type, #content_uri, #destination, #ftype, #group, #mode, #owner, #path, #source_permissions

Attributes inherited from Base

#links, #path, #relative_path, #source

Instance Method Summary collapse

Methods inherited from Metadata

#collect_stat, from_data_hash, #to_data_hash

Methods included from Indirector

configure_routes, #indirects

Methods included from Util::Checksums

checksum?, checksum_file, checksum_stream, ctime, ctime?, ctime_file, ctime_stream, known_checksum_types, md5, md5?, md5_file, md5_hex_length, md5_stream, md5lite, md5lite?, md5lite_file, md5lite_hex_length, md5lite_stream, mtime, mtime?, mtime_file, mtime_stream, none, none?, none_file, none_stream, sha1, sha1?, sha1_file, sha1_hex_length, sha1_stream, sha1lite, sha1lite?, sha1lite_file, sha1lite_hex_length, sha1lite_stream, sha256, sha256?, sha256_file, sha256_hex_length, sha256_stream, sha256lite, sha256lite?, sha256lite_file, sha256lite_hex_length, sha256lite_stream, sumdata, sumtype

Methods inherited from Base

absolute?, #exist?, #full_path, #stat, #to_data_hash

Methods included from Util::MethodHelper

#requiredopts, #set_options, #symbolize_options

Constructor Details

#initialize(http_response, path = '/dev/null') ⇒ HttpMetadata

Returns a new instance of HttpMetadata.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/file_serving/http_metadata.rb', line 7

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.utc}"
  end

  @ftype = 'file'

  self
end

Instance Method Details

#collectObject

Override of the parent class method. Does not call super! We can only return metadata that was extracted from the HTTP headers during #initialize.



37
38
39
40
41
42
43
44
45
# File 'lib/puppet/file_serving/http_metadata.rb', line 37

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