summaryrefslogtreecommitdiffstats
path: root/lib/puppet/network/client
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-03-15 14:16:09 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commite5a78009f6bd593e7e3957f0dadb470e623396dd (patch)
treef1d386962e4a7ef5b4e20347653e570dccd141bf /lib/puppet/network/client
parentf838389da0530201849958444dbbe60977935ad0 (diff)
Feature #3347 REST-ified FileBucket
FileBucket Files have been reimplemented as an indirector terminus so that they can be transmitted over REST. The old Network::Client.dipper has been replaced with a compatibility later in FileBucket::Dipper that uses the indirector to access filebucket termini. Slightly revised patch: * No longer allows nil contents in FileBucket outside of initialization * Uses File.exist? instead of the deprecated File.exists? * Tweaks JSON serialization and de-serialization to include "path" Deferred issues: * Feature #3371 "FileBucket should not keep files in memory". * Feature #3372 "Replace FileBucket Dipper with more idiomatic calls"
Diffstat (limited to 'lib/puppet/network/client')
-rw-r--r--lib/puppet/network/client/dipper.rb85
1 files changed, 0 insertions, 85 deletions
diff --git a/lib/puppet/network/client/dipper.rb b/lib/puppet/network/client/dipper.rb
deleted file mode 100644
index 0e2dc1425..000000000
--- a/lib/puppet/network/client/dipper.rb
+++ /dev/null
@@ -1,85 +0,0 @@
-# The client class for filebuckets.
-class Puppet::Network::Client::Dipper < Puppet::Network::Client
- @handler = Puppet::Network::Handler.handler(:filebucket)
- @drivername = :Bucket
-
- attr_accessor :name
-
- # Create our bucket client
- def initialize(hash = {})
- if hash.include?(:Path)
- bucket = self.class.handler.new(:Path => hash[:Path])
- hash.delete(:Path)
- hash[:Bucket] = bucket
- end
-
- super(hash)
- end
-
- # Back up a file to our bucket
- def backup(file)
- unless FileTest.exists?(file)
- raise(ArgumentError, "File %s does not exist" % file)
- end
- contents = ::File.read(file)
- unless local?
- contents = Base64.encode64(contents)
- end
- begin
- return @driver.addfile(contents,file)
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- raise Puppet::Error, "Could not back up %s: %s" % [file, detail]
- end
- end
-
- # Retrieve a file by sum.
- def getfile(sum)
- if newcontents = @driver.getfile(sum)
- unless local?
- newcontents = Base64.decode64(newcontents)
- end
- return newcontents
- end
- return nil
- end
-
- # Restore the file
- def restore(file,sum)
- restore = true
- if FileTest.exists?(file)
- cursum = Digest::MD5.hexdigest(::File.read(file))
-
- # if the checksum has changed...
- # this might be extra effort
- if cursum == sum
- restore = false
- end
- end
-
- if restore
- if newcontents = getfile(sum)
- tmp = ""
- newsum = Digest::MD5.hexdigest(newcontents)
- changed = nil
- if FileTest.exists?(file) and ! FileTest.writable?(file)
- changed = ::File.stat(file).mode
- ::File.chmod(changed | 0200, file)
- end
- ::File.open(file, ::File::WRONLY|::File::TRUNC|::File::CREAT) { |of|
- of.print(newcontents)
- }
- if changed
- ::File.chmod(changed, file)
- end
- else
- Puppet.err "Could not find file with checksum %s" % sum
- return nil
- end
- return newsum
- else
- return nil
- end
- end
-end
-