Class: Puppet::FileServing::HttpMetadata Private
- Defined in:
- lib/puppet/file_serving/http_metadata.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Simplified metadata representation, suitable for the information that is available from HTTP headers.
Constant Summary
Constants inherited from Metadata
Constants included from Indirector
Constants included from Util::Checksums
Util::Checksums::KNOWN_CHECKSUMS
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
-
#collect ⇒ Object
private
Override of the parent class method.
-
#initialize(http_response, path = '/dev/null') ⇒ HttpMetadata
constructor
private
A new instance of HttpMetadata.
Methods inherited from Metadata
#collect_stat, from_data_hash, #to_data_hash
Methods included from Indirector
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, sha224, sha224?, sha224_file, sha224_hex_length, sha224_stream, sha256, sha256?, sha256_file, sha256_hex_length, sha256_stream, sha256lite, sha256lite?, sha256lite_file, sha256lite_hex_length, sha256lite_stream, sha384, sha384?, sha384_file, sha384_hex_length, sha384_stream, sha512, sha512?, sha512_file, sha512_hex_length, sha512_stream, sumdata, sumtype, valid_checksum?
Methods inherited from Base
absolute?, #exist?, #full_path, #stat, #to_data_hash
Constructor Details
#initialize(http_response, path = '/dev/null') ⇒ HttpMetadata
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HttpMetadata.
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/puppet/file_serving/http_metadata.rb', line 8 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}" # RFC-1864, deprecated in HTTP/1.1 due to partial responses checksum = http_response['content-md5'] if checksum # convert base64 digest to hex checksum = checksum.unpack("m").first.unpack("H*").first @checksums[:md5] = "{md5}#{checksum}" end { md5: 'X-Checksum-Md5', sha1: 'X-Checksum-Sha1', sha256: 'X-Checksum-Sha256' }.each_pair do |checksum_type, header| checksum = http_response[header] if checksum @checksums[checksum_type] = "{#{checksum_type}}#{checksum}" end 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 |
Instance Method Details
#collect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override of the parent class method. Does not call super! We can only return metadata that was extracted from the HTTP headers during #initialize.
52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/file_serving/http_metadata.rb', line 52 def collect # Prefer the checksum_type from the indirector request options # but fall back to the alternative otherwise [ @checksum_type, :sha256, :sha1, :md5, :mtime ].each do |type| @checksum_type = type @checksum = @checksums[type] break if @checksum end end |