summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-18 17:51:25 -0500
committerLuke Kanies <luke@madstop.com>2008-07-18 17:51:25 -0500
commitebb219e496682862ac98d382afe014cf1c763f2f (patch)
treed754de01560f8724e2cfad5ff3a53d714e37e9ba /lib
parentd8937acb8c9b108e61330cbac703a17b2eaba9b3 (diff)
downloadpuppet-ebb219e496682862ac98d382afe014cf1c763f2f.tar.gz
puppet-ebb219e496682862ac98d382afe014cf1c763f2f.tar.xz
puppet-ebb219e496682862ac98d382afe014cf1c763f2f.zip
Fixed all of the fileserving termini so they use indirection requests.
This looks like a much larger commit than it is -- it doesn't change any behaviour at all, it just adds some integration tests (which expose the problem) and then switches from an ad-hoc api to a request-based api. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/file_serving/terminus_helper.rb8
-rw-r--r--lib/puppet/indirector/direct_file_server.rb2
-rw-r--r--lib/puppet/indirector/file_server.rb28
-rw-r--r--lib/puppet/indirector/module_files.rb28
4 files changed, 33 insertions, 33 deletions
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/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)