diff options
Diffstat (limited to 'lib/puppet/indirector/module_files.rb')
-rw-r--r-- | lib/puppet/indirector/module_files.rb | 43 |
1 files changed, 30 insertions, 13 deletions
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 |