1
require 'puppet/util/cacher'
3
require 'puppet/file_serving/mount'
5
class Puppet::FileServing::Mount::File < Puppet::FileServing::Mount
7
include Puppet::Util::Cacher
9
cached_attr(:localmap) do
10
{ "h" => Facter.value("hostname"),
11
"H" => [Facter.value("hostname"),
12
Facter.value("domain")].join("."),
13
"d" => Facter.value("domain")
18
def complete_path(relative_path, node)
19
full_path = path(node)
21
raise ArgumentError.new("Mounts without paths are not usable") unless full_path
23
# If there's no relative path name, then we're serving the mount itself.
24
return full_path unless relative_path
26
file = ::File.join(full_path, relative_path)
28
return nil unless FileTest.exist?(file)
33
# Return an instance of the appropriate class.
34
def find(short_file, request)
35
complete_path(short_file, request.node)
38
# Return the path as appropriate, expanding as necessary.
41
return expand(@path, node)
49
# FIXME: For now, just don't validate paths with replacement
52
# Mark that we're expandable.
55
unless FileTest.directory?(path)
56
raise ArgumentError, "%s does not exist or is not a directory" % path
58
unless FileTest.readable?(path)
59
raise ArgumentError, "%s is not readable" % path
66
def search(path, request)
67
return nil unless path = complete_path(path, request.node)
71
# Verify our configuration is valid. This should really check to
72
# make sure at least someone will be allowed, but, eh.
74
raise ArgumentError.new("Mounts without paths are not usable") if @path.nil?
79
# Create a map for a specific node.
82
"h" => node.sub(/\..*$/, ""),
84
"d" => node.sub(/[^.]+\./, "") # domain name
88
# Replace % patterns as appropriate.
89
def expand(path, node = nil)
90
# This map should probably be moved into a method.
96
Puppet.notice "No client; expanding '%s' with local host" %
98
# Else, use the local information
102
path.gsub(/%(.)/) do |v|
112
# Do we have any patterns in our path, yo?
114
if defined? @expandable
121
# Cache this manufactured map, since if it's used it's likely