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

Inherits:
Handler
  • Object
show all
Defined in:
lib/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.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/puppet/network/handler/filebucket.rb', line 19

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



19
20
21
# File 'lib/puppet/network/handler/filebucket.rb', line 19

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.



28
29
30
31
32
# File 'lib/puppet/network/handler/filebucket.rb', line 28

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

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

Return the contents associated with a given md5 sum.



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

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

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

#to_sObject



46
47
48
# File 'lib/puppet/network/handler/filebucket.rb', line 46

def to_s
  self.name
end