diff options
| author | Rick Bradley <rick@rickbradley.com> | 2007-10-23 07:28:42 -0500 |
|---|---|---|
| committer | Rick Bradley <rick@rickbradley.com> | 2007-10-23 07:28:42 -0500 |
| commit | 7def1eaa0e6e559ed70f260bf7b42d8e84d3740b (patch) | |
| tree | 81c91d425f015a634e5fe45e500ca0dec87bc0f6 /lib/puppet/indirector | |
| parent | b134f0ce465923a6b0b7f2855850e38599f0f176 (diff) | |
| parent | de5d91e2036de2934a4eec79d35a714f3ed24b10 (diff) | |
| download | puppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.tar.gz puppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.tar.xz puppet-7def1eaa0e6e559ed70f260bf7b42d8e84d3740b.zip | |
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'lib/puppet/indirector')
| -rw-r--r-- | lib/puppet/indirector/file_content/file.rb (renamed from lib/puppet/indirector/file_content/local.rb) | 13 | ||||
| -rw-r--r-- | lib/puppet/indirector/file_content/file_server.rb (renamed from lib/puppet/indirector/file_content/mounts.rb) | 2 | ||||
| -rw-r--r-- | lib/puppet/indirector/file_metadata/file.rb | 32 | ||||
| -rw-r--r-- | lib/puppet/indirector/file_metadata/file_server.rb (renamed from lib/puppet/indirector/file_metadata/mounts.rb) | 2 | ||||
| -rw-r--r-- | lib/puppet/indirector/file_metadata/local.rb | 24 | ||||
| -rw-r--r-- | lib/puppet/indirector/file_server.rb | 38 | ||||
| -rw-r--r-- | lib/puppet/indirector/indirection.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/indirector/module_files.rb | 61 | ||||
| -rw-r--r-- | lib/puppet/indirector/ssl_rsa.rb | 5 | ||||
| -rw-r--r-- | lib/puppet/indirector/ssl_rsa/file.rb | 33 |
10 files changed, 159 insertions, 53 deletions
diff --git a/lib/puppet/indirector/file_content/local.rb b/lib/puppet/indirector/file_content/file.rb index e429c6c25..4503a7919 100644 --- a/lib/puppet/indirector/file_content/local.rb +++ b/lib/puppet/indirector/file_content/file.rb @@ -3,21 +3,26 @@ # Copyright (c) 2007. All rights reserved. require 'puppet/file_serving/content' +require 'puppet/file_serving/terminus_helper' require 'puppet/util/uri_helper' require 'puppet/indirector/file_content' require 'puppet/indirector/file' -class Puppet::Indirector::FileContent::Local < Puppet::Indirector::File +class Puppet::Indirector::FileContent::File < Puppet::Indirector::File desc "Retrieve file contents from disk." include Puppet::Util::URIHelper + include Puppet::FileServing::TerminusHelper def find(key, options = {}) uri = key2uri(key) - return nil unless FileTest.exists?(uri.path) - data = model.new(uri.path) + model.new(uri.path, :links => options[:links]) + end - return data + def search(key, options = {}) + uri = key2uri(key) + return nil unless FileTest.exists?(uri.path) + path2instances(uri.path, options) end end diff --git a/lib/puppet/indirector/file_content/mounts.rb b/lib/puppet/indirector/file_content/file_server.rb index b11fc628c..2f50fcc23 100644 --- a/lib/puppet/indirector/file_content/mounts.rb +++ b/lib/puppet/indirector/file_content/file_server.rb @@ -6,6 +6,6 @@ require 'puppet/file_serving/content' require 'puppet/indirector/file_content' require 'puppet/indirector/file_server' -class Puppet::Indirector::FileContent::Mounts < Puppet::Indirector::FileServer +class Puppet::Indirector::FileContent::FileServer < Puppet::Indirector::FileServer desc "Retrieve file contents using Puppet's fileserver." end diff --git a/lib/puppet/indirector/file_metadata/file.rb b/lib/puppet/indirector/file_metadata/file.rb new file mode 100644 index 000000000..823c26c36 --- /dev/null +++ b/lib/puppet/indirector/file_metadata/file.rb @@ -0,0 +1,32 @@ +# +# Created by Luke Kanies on 2007-10-16. +# Copyright (c) 2007. All rights reserved. + +require 'puppet/file_serving/metadata' +require 'puppet/file_serving/terminus_helper' +require 'puppet/indirector/file_metadata' +require 'puppet/util/uri_helper' +require 'puppet/indirector/code' + +class Puppet::Indirector::FileMetadata::File < Puppet::Indirector::Code + desc "Retrieve file metadata directly from the local filesystem." + + include Puppet::Util::URIHelper + include Puppet::FileServing::TerminusHelper + + def find(key, options = {}) + uri = key2uri(key) + + return nil unless FileTest.exists?(uri.path) + data = model.new(uri.path, :links => options[:links]) + data.collect_attributes + + return data + end + + def search(key, options = {}) + uri = key2uri(key) + return nil unless FileTest.exists?(uri.path) + path2instances(uri.path, options).each { |instance| instance.collect_attributes } + end +end diff --git a/lib/puppet/indirector/file_metadata/mounts.rb b/lib/puppet/indirector/file_metadata/file_server.rb index b1e3b32fd..0b2e78908 100644 --- a/lib/puppet/indirector/file_metadata/mounts.rb +++ b/lib/puppet/indirector/file_metadata/file_server.rb @@ -6,6 +6,6 @@ require 'puppet/file_serving/metadata' require 'puppet/indirector/file_metadata' require 'puppet/indirector/file_server' -class Puppet::Indirector::FileMetadata::Mounts < Puppet::Indirector::FileServer +class Puppet::Indirector::FileMetadata::FileServer < Puppet::Indirector::FileServer desc "Retrieve file metadata using Puppet's fileserver." end diff --git a/lib/puppet/indirector/file_metadata/local.rb b/lib/puppet/indirector/file_metadata/local.rb deleted file mode 100644 index f40d4ce43..000000000 --- a/lib/puppet/indirector/file_metadata/local.rb +++ /dev/null @@ -1,24 +0,0 @@ -# -# Created by Luke Kanies on 2007-10-16. -# Copyright (c) 2007. All rights reserved. - -require 'puppet/file_serving/metadata' -require 'puppet/indirector/file_metadata' -require 'puppet/util/uri_helper' -require 'puppet/indirector/code' - -class Puppet::Indirector::FileMetadata::Local < Puppet::Indirector::Code - desc "Retrieve file metadata directly from the local filesystem." - - include Puppet::Util::URIHelper - - def find(key) - uri = key2uri(key) - - return nil unless FileTest.exists?(uri.path) - data = model.new(uri.path) - data.get_attributes - - return data - end -end diff --git a/lib/puppet/indirector/file_server.rb b/lib/puppet/indirector/file_server.rb index 1b2e047e8..de88bdc18 100644 --- a/lib/puppet/indirector/file_server.rb +++ b/lib/puppet/indirector/file_server.rb @@ -4,25 +4,36 @@ require 'puppet/util/uri_helper' require 'puppet/file_serving/configuration' +require 'puppet/file_serving/fileset' +require 'puppet/file_serving/terminus_helper' require 'puppet/indirector/terminus' # Look files up using the file server. class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus include Puppet::Util::URIHelper + include Puppet::FileServing::TerminusHelper + + # Is the client authorized to perform this action? + def authorized?(method, key, options = {}) + return false unless [:find, :search].include?(method) - # Find our key using the fileserver. - def find(key, options = {}) uri = key2uri(key) - # First try the modules mount, at least for now. - if instance = indirection.terminus(:modules).find(key, options) - Puppet.warning "DEPRECATION NOTICE: Found file in module without using the 'modules' mount; please fix" - return instance - end + configuration.authorized?(uri.path, :node => options[:node], :ipaddress => options[:ipaddress]) + end - return nil unless path = configuration.file_path(uri.path, :node => options[:node]) and FileTest.exists?(path) + # Find our key using the fileserver. + def find(key, options = {}) + return nil unless path = find_path(key, options) + return model.new(path, :links => options[:links]) + end - return model.new(path) + # Search for files. This returns an array rather than a single + # file. + def search(key, options = {}) + return nil unless path = find_path(key, options) + + path2instances(path, options) end private @@ -31,4 +42,13 @@ class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus def configuration Puppet::FileServing::Configuration.create end + + # Find our path; used by :find and :search. + def find_path(key, options) + uri = key2uri(key) + + return nil unless path = configuration.file_path(uri.path, :node => options[:node]) + + return path + end end diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 81d960fbd..2bf754198 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -112,7 +112,7 @@ class Puppet::Indirector::Indirection # of URI that the indirection can use for routing to the appropriate # terminus. if respond_to?(:select_terminus) - terminus_name = select_terminus(key) + terminus_name = select_terminus(key, *args) else terminus_name = terminus_class end diff --git a/lib/puppet/indirector/module_files.rb b/lib/puppet/indirector/module_files.rb index e0374d7a4..12794e4c7 100644 --- a/lib/puppet/indirector/module_files.rb +++ b/lib/puppet/indirector/module_files.rb @@ -4,30 +4,52 @@ require 'puppet/util/uri_helper' require 'puppet/indirector/terminus' +require 'puppet/file_serving/configuration' +require 'puppet/file_serving/fileset' +require 'puppet/file_serving/terminus_helper' # Look files up in Puppet modules. class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus include Puppet::Util::URIHelper + 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) - # Find our key in a module. - def find(key, options = {}) uri = key2uri(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) + # 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 - # And use the environment to look up the module. - return nil unless mod = find_module(module_name, options[:node]) + configuration.authorized?(path, :node => options[:node], :ipaddress => options[:ipaddress]) + end - path = File.join(mod.files, relative_path) + # Find our key in a module. + def find(key, options = {}) + return nil unless path = find_path(key, options) - return nil unless FileTest.exists?(path) + return model.new(path, :links => options[:links]) + end + + # Try to find our module. + def find_module(module_name, node_name) + Puppet::Module::find(module_name, environment(node_name)) + end - return model.new(path) + # Search for a list of files. + def search(key, options = {}) + return nil unless path = find_path(key, options) + path2instances(path, options) end private + + # Our fileserver configuration, if needed. + def configuration + Puppet::FileServing::Configuration.create + end # Determine the environment to use, if any. def environment(node_name) @@ -40,8 +62,21 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus end end - # Try to find our module. - def find_module(module_name, node_name) - Puppet::Module::find(module_name, environment(node_name)) + # The abstracted method for turning a key into a path; used by both :find and :search. + def find_path(key, options) + uri = key2uri(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]) + + path = File.join(mod.files, relative_path) + + return nil unless FileTest.exists?(path) + + return path end end diff --git a/lib/puppet/indirector/ssl_rsa.rb b/lib/puppet/indirector/ssl_rsa.rb new file mode 100644 index 000000000..162d8200a --- /dev/null +++ b/lib/puppet/indirector/ssl_rsa.rb @@ -0,0 +1,5 @@ +# This is a stub class + +class Puppet::Indirector::SslRsa #:nodoc: +end + diff --git a/lib/puppet/indirector/ssl_rsa/file.rb b/lib/puppet/indirector/ssl_rsa/file.rb new file mode 100644 index 000000000..435aa8f86 --- /dev/null +++ b/lib/puppet/indirector/ssl_rsa/file.rb @@ -0,0 +1,33 @@ +require 'puppet/indirector/file' +require 'puppet/indirector/ssl_rsa' + +class Puppet::Indirector::SslRsa::File < Puppet::Indirector::File + desc "Store SSL keys on disk." + + def initialize + Puppet.settings.use(:ssl) + end + + def path(name) + if name == :ca + File.join Puppet.settings[:cadir], "ca_key.pem" + else + File.join Puppet.settings[:publickeydir], name.to_s + ".pem" + end + end + + def save(key) + File.open(path(key.name), "w") { |f| f.print key.to_pem } + end + + def find(name) + return nil unless FileTest.exists?(path(name)) + OpenSSL::PKey::RSA.new(File.read(path(name))) + end + + def destroy(name) + return nil unless FileTest.exists?(path(name)) + File.unlink(path(name)) and true + end + +end |
