summaryrefslogtreecommitdiffstats
path: root/lib/puppet/server
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-28 04:08:38 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-04-28 04:08:38 +0000
commitbcfc469e4aa36ab8b98af57b1314e26d5d7a0a18 (patch)
tree0671fccd17cfa5764a5b7e7707d5424cf09420e4 /lib/puppet/server
parent9539dbb5c8b54805a6c26f84f15abd6fdb5532b2 (diff)
downloadpuppet-bcfc469e4aa36ab8b98af57b1314e26d5d7a0a18.tar.gz
puppet-bcfc469e4aa36ab8b98af57b1314e26d5d7a0a18.tar.xz
puppet-bcfc469e4aa36ab8b98af57b1314e26d5d7a0a18.zip
Adding in all of the patches necessary to make a prototype rails interface to puppet nodes work. The biggest change is that there is now a separate NetworkClient class for every Client subclass, because otherwise you get namespace collisions. Most everything other change is a relatively minor patch.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1145 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/server')
-rw-r--r--lib/puppet/server/authconfig.rb6
-rwxr-xr-xlib/puppet/server/pelement.rb42
-rw-r--r--lib/puppet/server/servlet.rb32
3 files changed, 55 insertions, 25 deletions
diff --git a/lib/puppet/server/authconfig.rb b/lib/puppet/server/authconfig.rb
index 05901a207..bc5d713e0 100644
--- a/lib/puppet/server/authconfig.rb
+++ b/lib/puppet/server/authconfig.rb
@@ -51,8 +51,12 @@ class AuthConfig < Puppet::ParsedFile
def initialize(file = nil, parsenow = true)
@file ||= Puppet[:authconfig]
+
+ unless @file
+ raise Puppet::DevError, "No authconfig file defined"
+ end
return unless self.exists?
- super(file)
+ super(@file)
@rights = Rights.new
@configstamp = @configtimeout = @configstatted = nil
diff --git a/lib/puppet/server/pelement.rb b/lib/puppet/server/pelement.rb
index b7fe35f7c..3001cd9a1 100755
--- a/lib/puppet/server/pelement.rb
+++ b/lib/puppet/server/pelement.rb
@@ -19,8 +19,7 @@ class Server::PElement < Server::Handler
begin
case format
when "yaml":
- tmp = YAML::load(CGI.unescape(bucket))
- bucket = tmp
+ bucket = YAML::load(Base64.decode64(bucket))
else
raise Puppet::Error, "Unsupported format '%s'" % format
end
@@ -50,6 +49,7 @@ class Server::PElement < Server::Handler
# Describe a given object. This returns the 'is' values for every state
# available on the object type.
def describe(type, name, retrieve = nil, ignore = [], format = "yaml", client = nil, clientip = nil)
+ Puppet.info "Describing %s[%s]" % [type, name]
@local = true unless client
typeklass = nil
unless typeklass = Puppet.type(type)
@@ -59,6 +59,7 @@ class Server::PElement < Server::Handler
obj = nil
retrieve ||= :all
+ ignore ||= []
if obj = typeklass[name]
obj[:check] = retrieve
@@ -71,6 +72,12 @@ class Server::PElement < Server::Handler
end
end
+ unless obj
+ raise XMLRPC::FaultException.new(
+ 1, "Could not create %s[%s]" % [type, name]
+ )
+ end
+
trans = obj.to_trans
# Now get rid of any attributes they specifically don't want
@@ -87,20 +94,18 @@ class Server::PElement < Server::Handler
end
end
- if @local
- return trans
- else
- str = nil
+ unless @local
case format
when "yaml":
- str = CGI.escape(YAML::dump(trans))
+ trans = Base64.encode64(YAML::dump(trans))
else
raise XMLRPC::FaultException.new(
1, "Unavailable config format %s" % format
)
end
- return CGI.escape(str)
end
+
+ return trans
end
# Create a new fileserving module.
@@ -113,13 +118,15 @@ class Server::PElement < Server::Handler
end
# List all of the elements of a given type.
- def list(type, ignore = [], base = nil, client = nil, clientip = nil)
+ def list(type, ignore = [], base = nil, format = "yaml", client = nil, clientip = nil)
@local = true unless client
typeklass = nil
unless typeklass = Puppet.type(type)
raise Puppet::Error, "Puppet type %s is unsupported" % type
end
+ # They can pass in false
+ ignore ||= []
ignore = [ignore] unless ignore.is_a? Array
bucket = TransBucket.new
bucket.type = typeklass.name
@@ -131,20 +138,25 @@ class Server::PElement < Server::Handler
bucket << object
end
- if @local
- return bucket
- else
- str = nil
+ unless @local
case format
when "yaml":
- str = YAML.dump(bucket)
+ begin
+ bucket = Base64.encode64(YAML::dump(bucket))
+ rescue => detail
+ Puppet.err detail
+ raise XMLRPC::FaultException.new(
+ 1, detail.to_s
+ )
+ end
else
raise XMLRPC::FaultException.new(
1, "Unavailable config format %s" % format
)
end
- return CGI.escape(str)
end
+
+ return bucket
end
private
diff --git a/lib/puppet/server/servlet.rb b/lib/puppet/server/servlet.rb
index dd34fcd03..2ea599c1a 100644
--- a/lib/puppet/server/servlet.rb
+++ b/lib/puppet/server/servlet.rb
@@ -38,25 +38,45 @@ class Server
def authorize(request, method)
namespace = method.sub(/\..+/, '')
client = request.peeraddr[2]
+ if defined? @client and @client
+ client = @client
+ end
ip = request.peeraddr[3]
if request.client_cert
+ begin
if @puppetserver.authconfig.exists?
- return @puppetserver.authconfig.allowed?(method, client, ip)
+ allowed = @puppetserver.authconfig.allowed?(method, client, ip)
+
+ if allowed
+ Puppet.info "Allowing %s(%s) trusted access to %s" %
+ [client, ip, method]
+ return true
+ else
+ Puppet.info "Denying %s(%s) trusted access to %s" %
+ [client, ip, method]
+ return false
+ end
else
+ Puppet.info "No #{@puppetserver.authconfig.file}"
# This is pretty hackish, but...
# This means we can't actually test this method at this point.
# The next release of Puppet will almost definitely require
# this file to exist or will default to denying all access.
if Puppet.name == "puppetmasterd" or defined? Test::Unit::TestCase
- Servlet.log "Allowing %s(%s) trusted access to %s" %
+ Puppet.info "Allowing %s(%s) trusted access to %s" %
[client, ip, method]
return true
else
- Servlet.log "Denying %s(%s) trusted access to %s on %s" %
+ Puppet.info "Denying %s(%s) trusted access to %s on %s" %
[client, ip, method, Puppet.name]
return false
end
end
+ rescue => detail
+ puts detail
+ puts detail.backtrace
+ raise
+ end
else
if method =~ /^puppetca\./
Puppet.notice "Allowing %s(%s) untrusted access to CA methods" %
@@ -106,10 +126,8 @@ class Server
@clientip = nil
self.set_service_hook { |obj, *args|
- #raise "crap!"
if @client and @clientip
args.push(@client, @clientip)
- #obj.call(args, @request)
end
begin
obj.call(*args)
@@ -173,10 +191,6 @@ class Server
end
end
end
- #if request.server_cert
- # Puppet.info "server cert is %s" % @request.server_cert
- #end
- #p @request
begin
super
rescue => detail