diff options
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/file_serving/fileset.rb | 4 | ||||
-rw-r--r-- | lib/puppet/file_serving/terminus_helper.rb | 15 | ||||
-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 |
6 files changed, 83 insertions, 21 deletions
diff --git a/lib/puppet/file_serving/fileset.rb b/lib/puppet/file_serving/fileset.rb index 7f7b9fc2d..fe54350b1 100644 --- a/lib/puppet/file_serving/fileset.rb +++ b/lib/puppet/file_serving/fileset.rb @@ -11,11 +11,11 @@ class Puppet::FileServing::Fileset attr_reader :path, :ignore, :links attr_accessor :recurse - # Find our collection of files. This is different from the + # Return a list of all files in our fileset. This is different from the # normal definition of find in that we support specific levels # of recursion, which means we need to know when we're going another # level deep, which Find doesn't do. - def find + def files files = perform_recursion # Now strip off the leading path, so each file becomes relative, and remove diff --git a/lib/puppet/file_serving/terminus_helper.rb b/lib/puppet/file_serving/terminus_helper.rb new file mode 100644 index 000000000..9542cbf84 --- /dev/null +++ b/lib/puppet/file_serving/terminus_helper.rb @@ -0,0 +1,15 @@ +# +# Created by Luke Kanies on 2007-10-22. +# Copyright (c) 2007. All rights reserved. + +require 'puppet/file_serving' +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(path, options = {}) + args = [:links, :ignore, :recurse].inject({}) { |hash, param| hash[param] = options[param] if options[param]; hash } + Puppet::FileServing::Fileset.new(path, args).files.collect { |file| model.new(file) } + end +end 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 |