From b874751cbb04c9250163e8cb5600418e12414dfa Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 22 Oct 2007 23:18:58 -0500 Subject: Renaming the FileServing TerminusSelector module to IndirectionHooks, because I'm going to add some hooks for transforming returned objects. --- lib/puppet/file_serving/content.rb | 4 +-- lib/puppet/file_serving/indirection_hooks.rb | 44 ++++++++++++++++++++++++++++ lib/puppet/file_serving/metadata.rb | 4 +-- lib/puppet/file_serving/terminus_selector.rb | 44 ---------------------------- 4 files changed, 48 insertions(+), 48 deletions(-) create mode 100644 lib/puppet/file_serving/indirection_hooks.rb delete mode 100644 lib/puppet/file_serving/terminus_selector.rb (limited to 'lib') diff --git a/lib/puppet/file_serving/content.rb b/lib/puppet/file_serving/content.rb index 3cb428e63..063192d15 100644 --- a/lib/puppet/file_serving/content.rb +++ b/lib/puppet/file_serving/content.rb @@ -5,14 +5,14 @@ require 'puppet/indirector' require 'puppet/file_serving' require 'puppet/file_serving/file_base' -require 'puppet/file_serving/terminus_selector' +require 'puppet/file_serving/indirection_hooks' # A class that handles retrieving file contents. # It only reads the file when its content is specifically # asked for. class Puppet::FileServing::Content < Puppet::FileServing::FileBase extend Puppet::Indirector - indirects :file_content, :extend => Puppet::FileServing::TerminusSelector + indirects :file_content, :extend => Puppet::FileServing::IndirectionHooks attr_reader :path diff --git a/lib/puppet/file_serving/indirection_hooks.rb b/lib/puppet/file_serving/indirection_hooks.rb new file mode 100644 index 000000000..141642efe --- /dev/null +++ b/lib/puppet/file_serving/indirection_hooks.rb @@ -0,0 +1,44 @@ +# +# Created by Luke Kanies on 2007-10-18. +# Copyright (c) 2007. All rights reserved. + +require 'uri' +require 'puppet/file_serving' + +# This module is used to pick the appropriate terminus +# in file-serving indirections. This is necessary because +# the terminus varies based on the URI asked for. +module Puppet::FileServing::IndirectionHooks + PROTOCOL_MAP = {"puppet" => :rest, "file" => :file, "puppetmounts" => :file_server} + + # Pick an appropriate terminus based on the protocol. + def select_terminus(full_uri, options = {}) + # Short-circuit to :file if it's a fully-qualified path. + return PROTOCOL_MAP["file"] if full_uri =~ /^#{::File::SEPARATOR}/ + begin + uri = URI.parse(URI.escape(full_uri)) + rescue => detail + raise ArgumentError, "Could not understand URI %s: %s" % [full_uri, detail.to_s] + end + + terminus = PROTOCOL_MAP[uri.scheme] || raise(ArgumentError, "URI protocol '%s' is not supported for file serving" % uri.scheme) + + # This provides a convenient mechanism for people to write configurations work + # well in both a networked and local setting. + if uri.host.nil? and uri.scheme == "puppet" and Puppet.settings[:name] == "puppet" + terminus = :file_server + end + + if terminus == :file_server and uri.path =~ %r{^/([^/]+)\b} + modname = $1 + if modname == "modules" + terminus = :modules + elsif terminus(:modules).find_module(modname, options[:node]) + Puppet.warning "DEPRECATION NOTICE: Found file '%s' in module without using the 'modules' mount; please prefix path with '/modules'" % uri.path + terminus = :modules + end + end + + return terminus + end +end diff --git a/lib/puppet/file_serving/metadata.rb b/lib/puppet/file_serving/metadata.rb index 62ebccca9..410655731 100644 --- a/lib/puppet/file_serving/metadata.rb +++ b/lib/puppet/file_serving/metadata.rb @@ -7,14 +7,14 @@ require 'puppet/indirector' require 'puppet/file_serving' require 'puppet/file_serving/file_base' require 'puppet/util/checksums' -require 'puppet/file_serving/terminus_selector' +require 'puppet/file_serving/indirection_hooks' # A class that handles retrieving file metadata. class Puppet::FileServing::Metadata < Puppet::FileServing::FileBase include Puppet::Util::Checksums extend Puppet::Indirector - indirects :file_metadata, :extend => Puppet::FileServing::TerminusSelector + indirects :file_metadata, :extend => Puppet::FileServing::IndirectionHooks attr_reader :path, :owner, :group, :mode, :checksum_type, :checksum, :ftype, :destination diff --git a/lib/puppet/file_serving/terminus_selector.rb b/lib/puppet/file_serving/terminus_selector.rb deleted file mode 100644 index 06b53ddb1..000000000 --- a/lib/puppet/file_serving/terminus_selector.rb +++ /dev/null @@ -1,44 +0,0 @@ -# -# Created by Luke Kanies on 2007-10-18. -# Copyright (c) 2007. All rights reserved. - -require 'uri' -require 'puppet/file_serving' - -# This module is used to pick the appropriate terminus -# in file-serving indirections. This is necessary because -# the terminus varies based on the URI asked for. -module Puppet::FileServing::TerminusSelector - PROTOCOL_MAP = {"puppet" => :rest, "file" => :file, "puppetmounts" => :file_server} - - # Pick an appropriate terminus based on the protocol. - def select_terminus(full_uri, options = {}) - # Short-circuit to :file if it's a fully-qualified path. - return PROTOCOL_MAP["file"] if full_uri =~ /^#{::File::SEPARATOR}/ - begin - uri = URI.parse(URI.escape(full_uri)) - rescue => detail - raise ArgumentError, "Could not understand URI %s: %s" % [full_uri, detail.to_s] - end - - terminus = PROTOCOL_MAP[uri.scheme] || raise(ArgumentError, "URI protocol '%s' is not supported for file serving" % uri.scheme) - - # This provides a convenient mechanism for people to write configurations work - # well in both a networked and local setting. - if uri.host.nil? and uri.scheme == "puppet" and Puppet.settings[:name] == "puppet" - terminus = :file_server - end - - if terminus == :file_server and uri.path =~ %r{^/([^/]+)\b} - modname = $1 - if modname == "modules" - terminus = :modules - elsif terminus(:modules).find_module(modname, options[:node]) - Puppet.warning "DEPRECATION NOTICE: Found file '%s' in module without using the 'modules' mount; please prefix path with '/modules'" % uri.path - terminus = :modules - end - end - - return terminus - end -end -- cgit