summaryrefslogtreecommitdiffstats
path: root/lib/puppet/server
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-08-23 21:23:57 +0000
committerLuke Kanies <luke@madstop.com>2005-08-23 21:23:57 +0000
commit5b20c92ff322ba1886209f788ce6a7df05315cf5 (patch)
tree8b75ab42323ef07de4a5cab6182b4c8eff8eb5da /lib/puppet/server
parentba51e700ace1b34b2dbb06bc61287be184fe46ec (diff)
Have done a significant reorganization of how clients work, also, along with some interesting trouble shooting on components
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@585 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/server')
-rwxr-xr-xlib/puppet/server/filebucket.rb174
-rw-r--r--lib/puppet/server/servlet.rb3
2 files changed, 25 insertions, 152 deletions
diff --git a/lib/puppet/server/filebucket.rb b/lib/puppet/server/filebucket.rb
index f0e717146..fa02d967a 100755
--- a/lib/puppet/server/filebucket.rb
+++ b/lib/puppet/server/filebucket.rb
@@ -15,37 +15,26 @@ require 'facter'
require 'digest/md5'
require 'base64'
-class BucketError < RuntimeError; end
+module Puppet
+class Server
+ class BucketError < RuntimeError; end
+ class FileBucket < Handler
+ DEFAULTPORT = 8139
+
+ @interface = XMLRPC::Service::Interface.new("puppetbucket") { |iface|
+ iface.add_method("string addfile(string, string)")
+ iface.add_method("string getfile(string)")
+ }
-module FileBucket
- DEFAULTPORT = 8139
- # this doesn't work for relative paths
- def FileBucket.mkdir(dir)
- if FileTest.exist?(dir)
- return false
- else
- tmp = dir.sub(/^\//,'')
- path = [File::SEPARATOR]
- tmp.split(File::SEPARATOR).each { |dir|
- path.push dir
- unless FileTest.exist?(File.join(path))
- Dir.mkdir(File.join(path))
- end
- }
- return true
+ # this doesn't work for relative paths
+ def FileBucket.paths(base,md5)
+ return [
+ File.join(base, md5),
+ File.join(base, md5, "contents"),
+ File.join(base, md5, "paths")
+ ]
end
- end
- def FileBucket.paths(base,md5)
- return [
- File.join(base, md5),
- File.join(base, md5, "contents"),
- File.join(base, md5, "paths")
- ]
- end
-
- #---------------------------------------------------------------
- class Bucket
def initialize(hash)
# build our AST
@@ -67,12 +56,11 @@ module FileBucket
end
end
- # XXX this should really be done using Puppet::Type instances...
- FileBucket.mkdir(@bucket)
+ Puppet.recmkdir(@bucket)
end
# accept a file from a client
- def addfile(string,path)
+ def addfile(string,path, request = nil)
#puts "entering addfile"
contents = Base64.decode64(string)
#puts "string is decoded"
@@ -83,7 +71,7 @@ module FileBucket
bpath, bfile, pathpath = FileBucket.paths(@bucket,md5)
# if it's a new directory...
- if FileBucket.mkdir(bpath)
+ if Puppet.recmkdir(bpath)
# ...then just create the file
#puts "creating file"
File.open(bfile, File::WRONLY|File::CREAT) { |of|
@@ -141,7 +129,7 @@ module FileBucket
return md5
end
- def getfile(md5)
+ def getfile(md5, request = nil)
bpath, bfile, bpaths = FileBucket.paths(@bucket,md5)
unless FileTest.exists?(bfile)
@@ -155,123 +143,7 @@ module FileBucket
return Base64.encode64(contents)
end
-
- private
-
- def on_init
- @default_namespace = 'urn:filebucket-server'
- add_method(self, 'addfile', 'string', 'path')
- add_method(self, 'getfile', 'md5')
- end
-
- def cert(filename)
- OpenSSL::X509::Certificate.new(File.open(File.join(@dir, filename)) { |f|
- f.read
- })
- end
-
- def key(filename)
- OpenSSL::PKey::RSA.new(File.open(File.join(@dir, filename)) { |f|
- f.read
- })
- end
-
- end
- #---------------------------------------------------------------
-
- class BucketWebserver < WEBrick::HTTPServer
- def initialize(hash)
- unless hash.include?(:Port)
- hash[:Port] = FileBucket::DEFAULTPORT
- end
- servlet = XMLRPC::WEBrickServlet.new
- @bucket = FileBucket::Bucket.new(hash)
- #puts @bucket
- servlet.add_handler("bucket",@bucket)
- super
-
- self.mount("/RPC2", servlet)
- end
+ #---------------------------------------------------------------
end
-
- class BucketClient < XMLRPC::Client
- @@methods = [ :addfile, :getfile ]
-
- @@methods.each { |method|
- self.send(:define_method,method) { |*args|
- begin
- call("bucket.%s" % method.to_s,*args)
- rescue => detail
- #puts detail
- end
- }
- }
-
- def initialize(hash)
- hash[:Path] ||= "/RPC2"
- hash[:Server] ||= "localhost"
- hash[:Port] ||= FileBucket::DEFAULTPORT
- super(hash[:Server],hash[:Path],hash[:Port])
- end
- end
-
- class Dipper
- def initialize(hash)
- if hash.include?(:Server)
- @bucket = FileBucket::BucketClient.new(
- :Server => hash[:Server]
- )
- elsif hash.include?(:Bucket)
- @bucket = hash[:Bucket]
- elsif hash.include?(:Path)
- @bucket = FileBucket::Bucket.new(
- :Path => hash[:Path]
- )
- end
- end
-
- def backup(file)
- unless FileTest.exists?(file)
- raise(BucketError, "File %s does not exist" % file, caller)
- end
- contents = File.open(file) { |of| of.read }
-
- string = Base64.encode64(contents)
- #puts "string is created"
-
- sum = @bucket.addfile(string,file)
- #puts "file %s is added" % file
- return sum
- end
-
- def restore(file,sum)
- restore = true
- if FileTest.exists?(file)
- contents = File.open(file) { |of| of.read }
-
- cursum = Digest::MD5.hexdigest(contents)
-
- # if the checksum has changed...
- # this might be extra effort
- if cursum == sum
- restore = false
- end
- end
-
- if restore
- #puts "Restoring %s" % file
- newcontents = Base64.decode64(@bucket.getfile(sum))
- newsum = Digest::MD5.hexdigest(newcontents)
- File.open(file,File::WRONLY|File::TRUNC) { |of|
- of.print(newcontents)
- }
- #puts "Done"
- return newsum
- else
- return nil
- end
-
- end
- end
- #---------------------------------------------------------------
+end
end
diff --git a/lib/puppet/server/servlet.rb b/lib/puppet/server/servlet.rb
index 4db9f6c0e..70f47a069 100644
--- a/lib/puppet/server/servlet.rb
+++ b/lib/puppet/server/servlet.rb
@@ -38,6 +38,7 @@ class Server
obj.call(*args)
rescue => detail
Puppet.warning obj.inspect
+ Puppet.warning args.inspect
Puppet.err "Could not call: %s" % detail.to_s
end
}
@@ -49,7 +50,7 @@ class Server
Puppet.info "client cert is %s" % @request.client_cert
end
if @request.server_cert
- Puppet.info "server cert is %s" % @request.server_cert
+ #Puppet.info "server cert is %s" % @request.server_cert
end
#p @request
begin