Class: Puppet::Network::Handler::FileBucket
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#addfile(contents, path, client = nil, clientip = nil) ⇒ Object
Accept a file from a client and store it by md5 sum, returning the sum.
-
#getfile(md5, client = nil, clientip = nil) ⇒ Object
Return the contents associated with a given md5 sum.
-
#initialize(hash) ⇒ FileBucket
constructor
A new instance of FileBucket.
- #to_s ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/puppet/network/handler/filebucket.rb', line 19 def name @name end |
#path ⇒ Object (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_s ⇒ Object
46 47 48 |
# File 'lib/puppet/network/handler/filebucket.rb', line 46 def to_s self.name end |