3
require 'puppet/file_serving'
4
require 'puppet/file_serving/mount'
5
require 'puppet/file_serving/mount/file'
6
require 'puppet/file_serving/mount/modules'
7
require 'puppet/file_serving/mount/plugins'
9
class Puppet::FileServing::Configuration
10
require 'puppet/file_serving/configuration/parser'
14
def self.configuration
16
@configuration ||= new
20
Mount = Puppet::FileServing::Mount
22
private_class_method :new
27
# Find the right mount. Does some shenanigans to support old-style module
29
def find_mount(mount_name, environment)
30
# Reparse the configuration if necessary.
33
if mount = mounts[mount_name]
37
if environment.module(mount_name)
38
Puppet::Util::Warnings.notice_once "DEPRECATION NOTICE: Files found in modules without specifying 'modules' in file path will be deprecated in the next major release. Please fix module '#{mount_name}' when no 0.24.x clients are present"
39
return mounts["modules"]
50
# We don't check to see if the file is modified the first time,
51
# because we always want to parse at first.
55
# Is a given mount available?
57
@mounts.include?(name)
60
# Split the path into the separate mount point and path.
61
def split_path(request)
62
# Reparse the configuration if necessary.
65
mount_name, path = request.key.split(File::Separator, 2)
67
raise(ArgumentError, "Cannot find file: Invalid path '#{mount_name}'") unless mount_name =~ %r{^[-\w]+$}
69
return nil unless mount = find_mount(mount_name, request.environment)
70
if mount.name == "modules" and mount_name != "modules"
71
# yay backward-compatibility
72
path = "#{mount_name}/#{path}"
78
# Remove any double slashes that might have occurred
79
path = path.gsub(/\/+/, "/")
86
@mounts.delete(name) if @mounts.include? name
92
@mounts["modules"] ||= Mount::Modules.new("modules")
93
@mounts["modules"].allow('*') if @mounts["modules"].empty?
94
@mounts["plugins"] ||= Mount::Plugins.new("plugins")
95
@mounts["plugins"].allow('*') if @mounts["plugins"].empty?
98
# Read the configuration file.
99
def readconfig(check = true)
100
config = Puppet[:fileserverconfig]
102
return unless FileTest.exists?(config)
104
@parser ||= Puppet::FileServing::Configuration::Parser.new(config)
106
return if check and ! @parser.changed?
108
# Don't assign the mounts hash until we're sure the parsing succeeded.
110
newmounts = @parser.parse
113
puts detail.backtrace if Puppet[:trace]
114
Puppet.err "Error parsing fileserver configuration: #{detail}; using old configuration"
118
# Make sure we've got our plugins and modules.