class Puppet::FileBucket::File

Attributes

bucket_path[R]

Public Instance Methods

checksum() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 58
def checksum
  "{#{checksum_type}}#{checksum_data}"
end
checksum_data() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 62
def checksum_data
  @checksum_data ||= @contents.checksum_data(@checksum_type)
end
checksum_type() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 54
def checksum_type
  @checksum_type.to_s
end
contents() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 70
def contents
  to_s
end
name() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 74
def name
  "#{checksum_type}/#{checksum_data}"
end
size() click to toggle source

@return [Num] The size of the contents

# File lib/puppet/file_bucket/file.rb, line 45
def size
  @contents.size()
end
stream(&block) click to toggle source

@return [IO] A stream that reads the contents

# File lib/puppet/file_bucket/file.rb, line 50
def stream(&block)
  @contents.stream(&block)
end
to_data_hash() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 82
def to_data_hash
  # Note that this serializes the entire data to a string and places it in a hash.
  { "contents" => contents.to_s }
end
to_pson() click to toggle source
# 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
to_s() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 66
def to_s
  @contents.to_s
end

Public Class Methods

default_format() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 20
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_data_hash(data) click to toggle source
# File lib/puppet/file_bucket/file.rb, line 87
def self.from_data_hash(data)
  self.new(data["contents"])
end
from_pson(pson) click to toggle source

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

# 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) click to toggle source
# File lib/puppet/file_bucket/file.rb, line 78
def self.from_s(contents)
  self.new(contents)
end
new(contents, options = {}) click to toggle source
# 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
supported_formats() click to toggle source
# File lib/puppet/file_bucket/file.rb, line 16
def self.supported_formats
  [:s, :pson]
end