Class: Puppet::FileBucket::File

Inherits:
Object
  • Object
show all
Extended by:
Indirector
Defined in:
lib/puppet/file_bucket/file.rb

Constant Summary

Constants included from Indirector

Indirector::BadNameRegexp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indirector

configure_routes, indirects

Constructor Details

#initialize(contents, options = {}) ⇒ File

Returns a new instance of File.

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
# File 'lib/puppet/file_bucket/file.rb', line 30

def initialize(contents, options = {})
  raise ArgumentError.new("contents must be a String, got a #{contents.class}") unless contents.is_a?(String)
  @contents = contents

  @bucket_path = options.delete(:bucket_path)
  raise ArgumentError.new("Unknown option(s): #{options.keys.join(', ')}") unless options.empty?
end

Instance Attribute Details

#bucket_pathObject (readonly)



15
16
17
# File 'lib/puppet/file_bucket/file.rb', line 15

def bucket_path
  @bucket_path
end

#contentsObject (readonly)



14
15
16
# File 'lib/puppet/file_bucket/file.rb', line 14

def contents
  @contents
end

Class Method Details

.default_formatObject



21
22
23
24
25
26
27
28
# File 'lib/puppet/file_bucket/file.rb', line 21

def self.default_format
  # This should really be :raw, like is done for Puppet::FileServing::Content
  # but this class hasn't historically supported `from_raw`, so switching
  # would break compatibility between newer 3.x agents talking to older 3.x
  # masters. However, to/from_s has been supported and achieves the desired
  # result without breaking compatibility.
  :s
end

.from_pson(pson) ⇒ Object

This method is deprecated, but cannot be removed for awhile, otherwise older agents sending pson couldn’t backup to filebuckets on newer masters



83
84
85
86
# File 'lib/puppet/file_bucket/file.rb', line 83

def self.from_pson(pson)
  Puppet.deprecation_warning("Deserializing Puppet::FileBucket::File objects from pson is deprecated. Upgrade to a newer version.")
  self.new(pson["contents"])
end

.from_s(contents) ⇒ Object



68
69
70
# File 'lib/puppet/file_bucket/file.rb', line 68

def self.from_s(contents)
  self.new(contents)
end

.supported_formatsObject



17
18
19
# File 'lib/puppet/file_bucket/file.rb', line 17

def self.supported_formats
  [:s, :pson]
end

Instance Method Details

#checksumObject



52
53
54
# File 'lib/puppet/file_bucket/file.rb', line 52

def checksum
  "{#{checksum_type}}#{checksum_data}"
end

#checksum_dataObject



56
57
58
# File 'lib/puppet/file_bucket/file.rb', line 56

def checksum_data
  @checksum_data ||= Digest::MD5.hexdigest(contents)
end

#checksum_typeObject



48
49
50
# File 'lib/puppet/file_bucket/file.rb', line 48

def checksum_type
  'md5'
end

#nameObject



64
65
66
# File 'lib/puppet/file_bucket/file.rb', line 64

def name
  "#{checksum_type}/#{checksum_data}"
end

#sizeNum

Returns The size of the contents.

Returns:

  • (Num)

    The size of the contents



39
40
41
# File 'lib/puppet/file_bucket/file.rb', line 39

def size
  contents.size
end

#streamIO

Returns A stream that reads the contents.

Returns:

  • (IO)

    A stream that reads the contents



44
45
46
# File 'lib/puppet/file_bucket/file.rb', line 44

def stream
  StringIO.new(contents)
end

#to_data_hashObject



77
78
79
# File 'lib/puppet/file_bucket/file.rb', line 77

def to_data_hash
  { "contents" => contents }
end

#to_psonObject



72
73
74
75
# File 'lib/puppet/file_bucket/file.rb', line 72

def to_pson
  Puppet.deprecation_warning("Serializing Puppet::FileBucket::File objects to pson is deprecated.")
  to_data_hash.to_pson
end

#to_sObject



60
61
62
# File 'lib/puppet/file_bucket/file.rb', line 60

def to_s
  contents
end