Sha256: bd56d273dc964337dd6d85ba80fe9e67524aa06d8fc75d226da38d732def59ba

Contents?: true

Size: 1.31 KB

Versions: 14

Compression:

Stored size: 1.31 KB

Contents

require 'puppet/file_bucket'
require 'puppet/indirector'
require 'puppet/util/checksums'
require 'digest/md5'

class Puppet::FileBucket::File
  # This class handles the abstract notion of a file in a filebucket.
  # There are mechanisms to save and load this file locally and remotely in puppet/indirector/filebucketfile/*
  # There is a compatibility class that emulates pre-indirector filebuckets in Puppet::FileBucket::Dipper
  extend Puppet::Indirector
  require 'puppet/file_bucket/file/indirection_hooks'
  indirects :file_bucket_file, :terminus_class => :file, :extend => Puppet::FileBucket::File::IndirectionHooks

  attr :contents
  attr :bucket_path

  def initialize( contents, options = {} )
    raise ArgumentError if !contents.is_a?(String)
    @contents  = contents

    @bucket_path = options.delete(:bucket_path)
    raise ArgumentError if options != {}
  end

  def checksum_type
    'md5'
  end

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

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

  def to_s
    contents
  end

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

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

  def to_pson
    { "contents" => contents }.to_pson
  end

  def self.from_pson( pson )
    self.new( pson["contents"] )
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
puppet-2.6.16 lib/puppet/file_bucket/file.rb
puppet-2.6.15 lib/puppet/file_bucket/file.rb
puppet-2.6.14 lib/puppet/file_bucket/file.rb
puppet-2.6.13 lib/puppet/file_bucket/file.rb
puppet-2.6.12 lib/puppet/file_bucket/file.rb
puppet-2.6.11 lib/puppet/file_bucket/file.rb
puppet-2.6.10 lib/puppet/file_bucket/file.rb
puppet-2.7.3 lib/puppet/file_bucket/file.rb
puppet-2.7.1 lib/puppet/file_bucket/file.rb
puppet-2.6.9 lib/puppet/file_bucket/file.rb
puppet-2.6.8 lib/puppet/file_bucket/file.rb
puppet-2.6.7 lib/puppet/file_bucket/file.rb
puppet-2.6.6 lib/puppet/file_bucket/file.rb
puppet-2.6.5 lib/puppet/file_bucket/file.rb