diff options
author | Luke Kanies <luke@madstop.com> | 2007-10-22 19:28:22 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-10-22 19:28:22 -0500 |
commit | 688fcdf11a685dfda297beff50de8d4c751494d9 (patch) | |
tree | f2d737a2382de16a43e3d37f09dab2c76ad57d91 /lib/puppet/indirector | |
parent | 393a3e8743f503543ad34a874e9296d684b0d49b (diff) | |
download | puppet-688fcdf11a685dfda297beff50de8d4c751494d9.tar.gz puppet-688fcdf11a685dfda297beff50de8d4c751494d9.tar.xz puppet-688fcdf11a685dfda297beff50de8d4c751494d9.zip |
Adding searchability to the fileserving termini, using the
new Fileset class.
The tests aren't the cleanest, in that there is still
a good bit of duplication in them, but it's what we got.
Diffstat (limited to 'lib/puppet/indirector')
-rw-r--r-- | lib/puppet/indirector/file_content/local.rb | 11 | ||||
-rw-r--r-- | lib/puppet/indirector/file_metadata/local.rb | 8 | ||||
-rw-r--r-- | lib/puppet/indirector/file_server.rb | 23 | ||||
-rw-r--r-- | lib/puppet/indirector/module_files.rb | 43 |
4 files changed, 66 insertions, 19 deletions
diff --git a/lib/puppet/indirector/file_content/local.rb b/lib/puppet/indirector/file_content/local.rb index e429c6c25..c2262c82d 100644 --- a/lib/puppet/indirector/file_content/local.rb +++ b/lib/puppet/indirector/file_content/local.rb @@ -3,6 +3,7 @@ # 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' @@ -11,13 +12,17 @@ class Puppet::Indirector::FileContent::Local < 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) + 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_metadata/local.rb b/lib/puppet/indirector/file_metadata/local.rb index f40d4ce43..86e1172f9 100644 --- a/lib/puppet/indirector/file_metadata/local.rb +++ b/lib/puppet/indirector/file_metadata/local.rb @@ -3,6 +3,7 @@ # 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' @@ -11,6 +12,7 @@ class Puppet::Indirector::FileMetadata::Local < Puppet::Indirector::Code desc "Retrieve file metadata directly from the local filesystem." include Puppet::Util::URIHelper + include Puppet::FileServing::TerminusHelper def find(key) uri = key2uri(key) @@ -21,4 +23,10 @@ class Puppet::Indirector::FileMetadata::Local < Puppet::Indirector::Code return data end + + def search(key, options = {}) + uri = key2uri(key) + return nil unless FileTest.exists?(uri.path) + path2instances(uri.path, options).each { |instance| instance.get_attributes } + end end diff --git a/lib/puppet/indirector/file_server.rb b/lib/puppet/indirector/file_server.rb index 51e53d8c9..46b0c40f2 100644 --- a/lib/puppet/indirector/file_server.rb +++ b/lib/puppet/indirector/file_server.rb @@ -4,11 +4,14 @@ 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 = {}) @@ -21,11 +24,16 @@ class Puppet::Indirector::FileServer < Puppet::Indirector::Terminus # Find our key using the fileserver. def find(key, options = {}) - uri = key2uri(key) + return nil unless path = find_path(key, options) + return model.new(path) + end - return nil unless path = configuration.file_path(uri.path, :node => options[:node]) and FileTest.exists?(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) - return model.new(path) + path2instances(path, options) end private @@ -34,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/module_files.rb b/lib/puppet/indirector/module_files.rb index 739d7b7b5..815da2efe 100644 --- a/lib/puppet/indirector/module_files.rb +++ b/lib/puppet/indirector/module_files.rb @@ -5,10 +5,13 @@ 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 = {}) @@ -16,7 +19,8 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus uri = key2uri(key) - # Make sure our file path starts with /modules + # 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]) @@ -24,18 +28,7 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus # 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) - - # 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 nil unless path = find_path(key, options) return model.new(path) end @@ -45,6 +38,12 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus Puppet::Module::find(module_name, environment(node_name)) end + # 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. @@ -62,4 +61,22 @@ class Puppet::Indirector::ModuleFiles < Puppet::Indirector::Terminus nil end 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) + + # 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 |