2
require 'puppet/file_serving'
5
# This module is used to pick the appropriate terminus
6
# in file-serving indirections. This is necessary because
7
# the terminus varies based on the URI asked for.
8
module Puppet::FileServing::IndirectionHooks
9
PROTOCOL_MAP = {"puppet" => :rest, "file" => :file}
11
# Pick an appropriate terminus based on the protocol.
12
def select_terminus(request)
13
# We rely on the request's parsing of the URI.
15
# Short-circuit to :file if it's a fully-qualified path or specifies a 'file' protocol.
16
return PROTOCOL_MAP["file"] if Puppet::Util.absolute_path?(request.key)
17
return PROTOCOL_MAP["file"] if request.protocol == "file"
19
# We're heading over the wire the protocol is 'puppet' and we've got a server name or we're not named 'apply' or 'puppet'
20
if request.protocol == "puppet" and (request.server or !["puppet","apply"].include?(Puppet.settings[:name]))
21
return PROTOCOL_MAP["puppet"]
24
if request.protocol and PROTOCOL_MAP[request.protocol].nil?
25
raise(ArgumentError, "URI protocol '#{request.protocol}' is not currently supported for file serving")
28
# If we're still here, we're using the file_server or modules.