diff options
author | Rick Bradley <rick@rickbradley.com> | 2007-10-26 12:50:19 -0500 |
---|---|---|
committer | Rick Bradley <rick@rickbradley.com> | 2007-10-26 12:50:19 -0500 |
commit | 6dd0d71b13f6b98b3fd4152421d0124e9786f726 (patch) | |
tree | 3f852c0f0a4b5d1317143de08cefc8177166b005 /lib/puppet/file_serving/indirection_hooks.rb | |
parent | 54fc80d5de7b881adca06c85206fb700f4278a73 (diff) | |
parent | d03f68eaed6d05483128b495ad1faaf89208d66a (diff) | |
download | puppet-6dd0d71b13f6b98b3fd4152421d0124e9786f726.tar.gz puppet-6dd0d71b13f6b98b3fd4152421d0124e9786f726.tar.xz puppet-6dd0d71b13f6b98b3fd4152421d0124e9786f726.zip |
Merge branch 'master' of git://reductivelabs.com/puppet into routing
Diffstat (limited to 'lib/puppet/file_serving/indirection_hooks.rb')
-rw-r--r-- | lib/puppet/file_serving/indirection_hooks.rb | 44 |
1 files changed, 44 insertions, 0 deletions
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 |