diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/defaults.rb | 5 | ||||
-rw-r--r-- | lib/puppet/file_serving/terminus_helper.rb | 8 | ||||
-rw-r--r-- | lib/puppet/indirector/catalog/compiler.rb | 2 | ||||
-rw-r--r-- | lib/puppet/indirector/direct_file_server.rb | 2 | ||||
-rw-r--r-- | lib/puppet/indirector/file_server.rb | 28 | ||||
-rw-r--r-- | lib/puppet/indirector/module_files.rb | 28 | ||||
-rw-r--r-- | lib/puppet/indirector/node/exec.rb | 7 | ||||
-rw-r--r-- | lib/puppet/network/client/master.rb | 15 | ||||
-rw-r--r-- | lib/puppet/network/handler/master.rb | 14 | ||||
-rw-r--r-- | lib/puppet/network/http.rb | 14 | ||||
-rwxr-xr-x | lib/puppet/provider/service/redhat.rb | 16 | ||||
-rw-r--r-- | lib/puppet/provider/ssh_authorized_key/parsed.rb | 36 | ||||
-rw-r--r-- | lib/puppet/sslcertificates/support.rb | 4 | ||||
-rwxr-xr-x | lib/puppet/type/file/source.rb | 3 | ||||
-rwxr-xr-x | lib/puppet/type/group.rb | 2 | ||||
-rw-r--r-- | lib/puppet/type/ssh_authorized_key.rb | 26 | ||||
-rw-r--r-- | lib/puppet/util.rb | 2 |
17 files changed, 122 insertions, 90 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index fce928ce5..7c57dcd6d 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -427,7 +427,10 @@ module Puppet :ca_server => ["$server", "The server to use for certificate authority requests. It's a separate server because it cannot and does not need to horizontally scale."], - :ca_port => ["$masterport", "The port to use for the certificate authority."] + :ca_port => ["$masterport", "The port to use for the certificate authority."], + :catalog_format => ["yaml", "What format to use to dump the catalog. Only supports + 'marshal' and 'yaml'. Only matters on the client, since it asks the server + for a specific format."] ) self.setdefaults(:filebucket, diff --git a/lib/puppet/file_serving/terminus_helper.rb b/lib/puppet/file_serving/terminus_helper.rb index d465aa493..e5da0e29f 100644 --- a/lib/puppet/file_serving/terminus_helper.rb +++ b/lib/puppet/file_serving/terminus_helper.rb @@ -8,11 +8,11 @@ require 'puppet/file_serving/fileset' # Define some common methods for FileServing termini. module Puppet::FileServing::TerminusHelper # Create model instances for all files in a fileset. - def path2instances(key, path, options = {}) - args = [:links, :ignore, :recurse].inject({}) { |hash, param| hash[param] = options[param] if options[param]; hash } + def path2instances(request, path) + args = [:links, :ignore, :recurse].inject({}) { |hash, param| hash[param] = request.options[param] if request.options[param]; hash } Puppet::FileServing::Fileset.new(path, args).files.collect do |file| - inst = model.new(File.join(key, file), :path => path, :relative_path => file) - inst.links = options[:links] if options[:links] + inst = model.new(File.join(request.key, file), :path => path, :relative_path => file) + inst.links = request.options[:links] if request.options[:links] inst end end diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index 455a92cc7..a6a812817 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -14,7 +14,7 @@ class Puppet::Node::Catalog::Compiler < Puppet::Indirector::Code # Compile a node's catalog. def find(request) - unless node = request.options[:node] || find_node(request.key) + unless node = request.options[:use_node] || find_node(request.key) raise ArgumentError, "Could not find node '%s'; cannot compile" % request.key end diff --git a/lib/puppet/indirector/direct_file_server.rb b/lib/puppet/indirector/direct_file_server.rb index 1711356f9..b3b4886f3 100644 --- a/lib/puppet/indirector/direct_file_server.rb +++ b/lib/puppet/indirector/direct_file_server.rb @@ -22,6 +22,6 @@ class Puppet::Indirector::DirectFileServer < Puppet::Indirector::Terminus def search(request) uri = key2uri(request.key) return nil unless FileTest.exists?(uri.path) - path2instances(request.key, uri.path, request.options) + path2instances(request, uri.path) end end diff --git a/lib/puppet/indirector/file_server.rb b/lib/puppet/indirector/file_server.rb index 2eb323d46..b0df7ff5d 100644 --- a/lib/puppet/indirector/file_server.rb +++ b/lib/puppet/indirector/file_server.rb @@ -14,28 +14,28 @@ class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus include Puppet::FileServing::TerminusHelper # Is the client authorized to perform this action? - def authorized?(method, key, options = {}) - return false unless [:find, :search].include?(method) + def authorized?(request) + return false unless [:find, :search].include?(request.method) - uri = key2uri(key) + uri = key2uri(request.key) - configuration.authorized?(uri.path, :node => options[:node], :ipaddress => options[:ipaddress]) + configuration.authorized?(uri.path, :node => request.node, :ipaddress => request.ip) end # Find our key using the fileserver. - def find(key, options = {}) - return nil unless path = find_path(key, options) - result = model.new(key, :path => path) - result.links = options[:links] if options[:links] + def find(request) + return nil unless path = find_path(request) + result = model.new(request.key, :path => path) + result.links = request.options[:links] if request.options[:links] return result end # Search for files. This returns an array rather than a single # file. - def search(key, options = {}) - return nil unless path = find_path(key, options) + def search(request) + return nil unless path = find_path(request) - path2instances(key, path, options) + path2instances(request, path) end private @@ -46,10 +46,10 @@ class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus end # Find our path; used by :find and :search. - def find_path(key, options) - uri = key2uri(key) + def find_path(request) + uri = key2uri(request.key) - return nil unless path = configuration.file_path(uri.path, :node => options[:node]) + return nil unless path = configuration.file_path(uri.path, :node => request.node) return path end diff --git a/lib/puppet/indirector/module_files.rb b/lib/puppet/indirector/module_files.rb index 84286d8a5..cf5c29cab 100644 --- a/lib/puppet/indirector/module_files.rb +++ b/lib/puppet/indirector/module_files.rb @@ -14,24 +14,24 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus include Puppet::FileServing::TerminusHelper # Is the client allowed access to this key with this method? - def authorized?(method, key, options = {}) - return false unless [:find, :search].include?(method) + def authorized?(request) + return false unless [:find, :search].include?(request.method) - uri = key2uri(key) + uri = key2uri(request.key) # Make sure our file path starts with /modules, so that we authorize # against the 'modules' mount. path = uri.path =~ /^\/modules/ ? uri.path : "/modules" + uri.path - configuration.authorized?(path, :node => options[:node], :ipaddress => options[:ipaddress]) + configuration.authorized?(path, :node => request.node, :ipaddress => request.ip) end # Find our key in a module. - def find(key, options = {}) - return nil unless path = find_path(key, options) + def find(request) + return nil unless path = find_path(request) - result = model.new(key, :path => path) - result.links = options[:links] if options[:links] + result = model.new(request.key, :path => path) + result.links = request.options[:links] if request.options[:links] return result end @@ -41,9 +41,9 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus end # Search for a list of files. - def search(key, options = {}) - return nil unless path = find_path(key, options) - path2instances(key, path, options) + def search(request) + return nil unless path = find_path(request) + path2instances(request, path) end private @@ -63,15 +63,15 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus end # The abstracted method for turning a key into a path; used by both :find and :search. - def find_path(key, options) - uri = key2uri(key) + def find_path(request) + uri = key2uri(request.key) # Strip off /modules if it's there -- that's how requests get routed to this terminus. # Also, strip off the leading slash if present. module_name, relative_path = uri.path.sub(/^\/modules\b/, '').sub(%r{^/}, '').split(File::Separator, 2) # And use the environment to look up the module. - return nil unless mod = find_module(module_name, options[:node]) + return nil unless mod = find_module(module_name, request.node) path = File.join(mod.files, relative_path) diff --git a/lib/puppet/indirector/node/exec.rb b/lib/puppet/indirector/node/exec.rb index 029a35c4f..52cbc370c 100644 --- a/lib/puppet/indirector/node/exec.rb +++ b/lib/puppet/indirector/node/exec.rb @@ -30,13 +30,6 @@ class Puppet::Node::Exec < Puppet::Indirector::Exec def create_node(name, result) node = Puppet::Node.new(name) set = false - if current = result[:parameters] - result[:parameters] = current.inject({}) do |strings, ary| - param, value = ary - strings[param] = value.to_s - strings - end - end [:parameters, :classes, :environment].each do |param| if value = result[param] node.send(param.to_s + "=", value) diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb index 26eff52a0..d401cd393 100644 --- a/lib/puppet/network/client/master.rb +++ b/lib/puppet/network/client/master.rb @@ -142,15 +142,20 @@ class Puppet::Network::Client::Master < Puppet::Network::Client # If we can't retrieve the catalog, just return, which will either # fail, or use the in-memory catalog. - unless yaml_objects = get_actual_config(facts) + unless marshalled_objects = get_actual_config(facts) use_cached_config(true) return end begin - objects = YAML.load(yaml_objects) + case Puppet[:catalog_format] + when "marshal": objects = Marshal.load(marshalled_objects) + when "yaml": objects = YAML.load(marshalled_objects) + else + raise "Invalid catalog format '%s'" % Puppet[:catalog_format] + end rescue => detail - msg = "Configuration could not be translated from yaml" + msg = "Configuration could not be translated from %s" % Puppet[:catalog_format] msg += "; using cached catalog" if use_cached_config(true) Puppet.warning msg return @@ -174,7 +179,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client end if ! @catalog.from_cache - self.cache(yaml_objects) + self.cache(marshalled_objects) end # Keep the state database up to date. @@ -441,7 +446,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client benchmark(:debug, "Retrieved catalog") do # error handling for this is done in the network client begin - textobjects = @driver.getconfig(textfacts, "yaml") + textobjects = @driver.getconfig(textfacts, Puppet[:catalog_format]) begin textobjects = CGI.unescape(textobjects) rescue => detail diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index a050b089b..9682c460e 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -64,7 +64,14 @@ class Puppet::Network::Handler catalog = Puppet::Node::Catalog.find(client) - return translate(catalog.extract) + case format + when "yaml": + return CGI.escape(catalog.extract.to_yaml(:UseBlock => true)) + when "marshal": + return CGI.escape(Marshal.dump(catalog.extract)) + else + raise "Invalid markup format '%s'" % format + end end # @@ -90,11 +97,6 @@ class Puppet::Network::Handler # Translate our configuration appropriately for sending back to a client. def translate(config) - if local? - config - else - CGI.escape(config.to_yaml(:UseBlock => true)) - end end end end diff --git a/lib/puppet/network/http.rb b/lib/puppet/network/http.rb index 062c67c71..c219859b6 100644 --- a/lib/puppet/network/http.rb +++ b/lib/puppet/network/http.rb @@ -1,13 +1,15 @@ class Puppet::Network::HTTP def self.server_class_by_type(kind) - return Puppet::Network::HTTP::WEBrick if kind.to_sym == :webrick - if kind.to_sym == :mongrel + case kind.to_sym + when :webrick: + require 'puppet/network/http/webrick' + return Puppet::Network::HTTP::WEBrick + when :mongrel: raise ArgumentError, "Mongrel is not installed on this platform" unless Puppet.features.mongrel? + require 'puppet/network/http/mongrel' return Puppet::Network::HTTP::Mongrel + else + raise ArgumentError, "Unknown HTTP server name [#{kind}]" end - raise ArgumentError, "Unknown HTTP server name [#{kind}]" end end - -require 'puppet/network/http/webrick' -require 'puppet/network/http/mongrel' diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb index e2d6ac947..3fad8bcfe 100755 --- a/lib/puppet/provider/service/redhat.rb +++ b/lib/puppet/provider/service/redhat.rb @@ -50,10 +50,22 @@ Puppet::Type.type(:service).provide :redhat, :parent => :init do end def restart - if @resource[:hasrestart] == true + if @resource[:hasrestart] == :true service(@resource[:name], "restart") else - return false + super + end + end + + def status + if @resource[:hasstatus] == :true + begin + service(@resource[:name], "status") + rescue + return :stopped + end + else + super end end diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb index 351ebcd1b..3bd22c06b 100644 --- a/lib/puppet/provider/ssh_authorized_key/parsed.rb +++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb @@ -29,5 +29,41 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed, record[:options] = record[:options].join(',') end } + + def prefetch + # This was done in the type class but path expansion was failing for + # not yet existing users, the only workaround I found was to move that + # in the provider. + if user = @resource.should(:user) + target = File.expand_path("~%s/.ssh/authorized_keys" % user) + @property_hash[:target] = target + @resource[:target] = target + end + + super + end + + def flush + # As path expansion had to be moved in the provider, we cannot generate new file + # resources and thus have to chown and chmod here. It smells hackish. + + # Create target's parent directory if nonexistant + if target = @property_hash[:target] + dir = File.dirname(@property_hash[:target]) + if not File.exist? dir + Puppet.debug("Creating directory %s which did not exist" % dir) + Dir.mkdir(dir, 0700) + end + end + + # Generate the file + super + + # Ensure correct permissions + if target and user = @property_hash[:user] + File.chown(Puppet::Util.uid(user), nil, dir) + File.chown(Puppet::Util.uid(user), nil, @property_hash[:target]) + end + end end diff --git a/lib/puppet/sslcertificates/support.rb b/lib/puppet/sslcertificates/support.rb index 95f15f0a8..d95944adc 100644 --- a/lib/puppet/sslcertificates/support.rb +++ b/lib/puppet/sslcertificates/support.rb @@ -128,6 +128,10 @@ module Puppet::SSLCertificates::Support def rename_files_with_uppercase(file) dir = File.dirname(file) short = File.basename(file) + + # If the dir isn't present, we clearly don't have the file. + #return nil unless FileTest.directory?(dir) + raise ArgumentError, "Tried to fix SSL files to a file containing uppercase" unless short.downcase == short real_file = Dir.entries(dir).reject { |f| f =~ /^\./ }.find do |other| other.downcase == short diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index f2704abb6..2514d3d1e 100755 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -101,8 +101,7 @@ module Puppet begin desc = server.describe(path, @resource[:links]) rescue Puppet::Network::XMLRPCClientError => detail - self.err "Could not describe %s: %s" % [path, detail] - return nil + fail detail, "Could not describe %s: %s" % [path, detail] end return nil if desc == "" diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb index 36a4d49fa..2a5ac30da 100755 --- a/lib/puppet/type/group.rb +++ b/lib/puppet/type/group.rb @@ -110,7 +110,7 @@ module Puppet isnamevar end - newparam(:allowdupe) do + newparam(:allowdupe, :boolean => true) do desc "Whether to allow duplicate GIDs. This option does not work on FreeBSD (contract to the ``pw`` man page)." diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb index 3a12e95ad..1db4a0ac3 100644 --- a/lib/puppet/type/ssh_authorized_key.rb +++ b/lib/puppet/type/ssh_authorized_key.rb @@ -27,11 +27,6 @@ module Puppet newproperty(:user) do desc "The user account in which the SSH key should be installed." - - def value=(value) - @resource[:target] = File.expand_path("~%s/.ssh/authorized_keys" % value) - super - end end newproperty(:target) do @@ -45,25 +40,6 @@ module Puppet defaultto do :absent end end - def generate - atype = Puppet::Type.type(:file) - target = self.should(:target) - dir = File.dirname(target) - user = should(:user) ? should(:user) : "root" - - rels = [] - - unless catalog.resource(:file, dir) - rels << atype.create(:name => dir, :ensure => :directory, :mode => 0700, :owner => user) - end - - unless catalog.resource(:file, target) - rels << atype.create(:name => target, :ensure => :present, :mode => 0600, :owner => user) - end - - rels - end - autorequire(:user) do if should(:user) should(:user) @@ -71,7 +47,7 @@ module Puppet end validate do - unless should(:target) + unless should(:target) or should(:user) raise Puppet::Error, "Attribute 'user' or 'target' is mandatory" end end diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index 560afe10b..94c96db0c 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -313,7 +313,7 @@ module Util $VERBOSE = oldverb if child_pid # Parent process executes this - child_status = Process.waitpid2(child_pid)[1] + child_status = (Process.waitpid2(child_pid)[1]).to_i >> 8 else # Child process executes this Process.setsid |