Class: Puppet::Network::Handler::FileBucket

Inherits:
Handler
  • Object
show all
Defined in:
lib/vendor/puppet/network/handler/filebucket.rb

Overview

Accept files and store them by md5 sum, returning the md5 sum back to the client. Alternatively, accept an md5 sum and return the associated content.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ FileBucket

Returns a new instance of FileBucket.



23
24
25
26
# File 'lib/vendor/puppet/network/handler/filebucket.rb', line 23

def initialize(hash)
  @path = hash[:Path] || Puppet[:bucketdir]
  @name = "Filebucket[#{@path}]"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/vendor/puppet/network/handler/filebucket.rb', line 21

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'lib/vendor/puppet/network/handler/filebucket.rb', line 21

def path
  @path
end

Instance Method Details

#addfile(contents, path, client = nil, clientip = nil) ⇒ Object

Accept a file from a client and store it by md5 sum, returning the sum.



30
31
32
33
34
# File 'lib/vendor/puppet/network/handler/filebucket.rb', line 30

def addfile(contents, path, client = nil, clientip = nil)
  contents = Base64.decode64(contents) if client
  bucket = Puppet::FileBucket::File.new(contents)
  Puppet::FileBucket::File.indirection.save(bucket)
end

#getfile(md5, client = nil, clientip = nil) ⇒ Object

Return the contents associated with a given md5 sum.



37
38
39
40
41
42
43
44
45
46
# File 'lib/vendor/puppet/network/handler/filebucket.rb', line 37

def getfile(md5, client = nil, clientip = nil)
  bucket = Puppet::FileBucket::File.indirection.find("md5:#{md5}")
  contents = bucket.contents

  if client
    return Base64.encode64(contents)
  else
    return contents
  end
end

#to_sObject



48
49
50
# File 'lib/vendor/puppet/network/handler/filebucket.rb', line 48

def to_s
  self.name
end