Class: Puppet::FileBucket::File
Defined Under Namespace
Classes: FileContents, StringContents
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.
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/puppet/file_bucket/file.rb', line 29
def initialize(contents, options = {})
case contents
when String
@contents = StringContents.new(contents)
when Pathname
@contents = FileContents.new(contents)
else
raise ArgumentError.new("contents must be a String or Pathname, got a #{contents.class}")
end
@bucket_path = options.delete(:bucket_path)
@checksum_type = Puppet[:digest_algorithm].to_sym
raise ArgumentError.new("Unknown option(s): #{options.keys.join(', ')}") unless options.empty?
end
|
Instance Attribute Details
#bucket_path ⇒ Object
14
15
16
|
# File 'lib/puppet/file_bucket/file.rb', line 14
def bucket_path
@bucket_path
end
|
Class Method Details
20
21
22
23
24
25
26
27
|
# File 'lib/puppet/file_bucket/file.rb', line 20
def self.default_format
:s
end
|
.from_data_hash(data) ⇒ Object
87
88
89
|
# File 'lib/puppet/file_bucket/file.rb', line 87
def self.from_data_hash(data)
self.new(data["contents"])
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
98
99
100
101
|
# File 'lib/puppet/file_bucket/file.rb', line 98
def self.from_pson(pson)
Puppet.deprecation_warning("Deserializing Puppet::FileBucket::File objects from pson is deprecated. Upgrade to a newer version.")
self.from_data_hash(pson)
end
|
.from_s(contents) ⇒ Object
78
79
80
|
# File 'lib/puppet/file_bucket/file.rb', line 78
def self.from_s(contents)
self.new(contents)
end
|
16
17
18
|
# File 'lib/puppet/file_bucket/file.rb', line 16
def self.supported_formats
[:s, :pson]
end
|
Instance Method Details
58
59
60
|
# File 'lib/puppet/file_bucket/file.rb', line 58
def checksum
"{#{checksum_type}}#{checksum_data}"
end
|
#checksum_data ⇒ Object
62
63
64
|
# File 'lib/puppet/file_bucket/file.rb', line 62
def checksum_data
@checksum_data ||= @contents.checksum_data(@checksum_type)
end
|
#checksum_type ⇒ Object
54
55
56
|
# File 'lib/puppet/file_bucket/file.rb', line 54
def checksum_type
@checksum_type.to_s
end
|
70
71
72
|
# File 'lib/puppet/file_bucket/file.rb', line 70
def contents
to_s
end
|
74
75
76
|
# File 'lib/puppet/file_bucket/file.rb', line 74
def name
"#{checksum_type}/#{checksum_data}"
end
|
#size ⇒ Num
Returns The size of the contents.
45
46
47
|
# File 'lib/puppet/file_bucket/file.rb', line 45
def size
@contents.size()
end
|
#stream(&block) ⇒ IO
Returns A stream that reads the contents.
50
51
52
|
# File 'lib/puppet/file_bucket/file.rb', line 50
def stream(&block)
@contents.stream(&block)
end
|
#to_data_hash ⇒ Object
82
83
84
85
|
# File 'lib/puppet/file_bucket/file.rb', line 82
def to_data_hash
{ "contents" => contents.to_s }
end
|
91
92
93
94
|
# File 'lib/puppet/file_bucket/file.rb', line 91
def to_pson
Puppet.deprecation_warning("Serializing Puppet::FileBucket::File objects to pson is deprecated.")
to_data_hash.to_pson
end
|
66
67
68
|
# File 'lib/puppet/file_bucket/file.rb', line 66
def to_s
@contents.to_s
end
|