summaryrefslogtreecommitdiffstats
path: root/lib/puppet/indirector/module_files.rb
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-23 07:28:42 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-23 07:28:42 -0500
commit7def1eaa0e6e559ed70f260bf7b42d8e84d3740b (patch)
tree81c91d425f015a634e5fe45e500ca0dec87bc0f6 /lib/puppet/indirector/module_files.rb
parentb134f0ce465923a6b0b7f2855850e38599f0f176 (diff)
parentde5d91e2036de2934a4eec79d35a714f3ed24b10 (diff)
downloadpuppet-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/module_files.rb')
-rw-r--r--lib/puppet/indirector/module_files.rb61
1 files changed, 48 insertions, 13 deletions
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