class Puppet::FileServing::Configuration
Constants
- Mount
Attributes
mounts[R]
Public Class Methods
configuration()
click to toggle source
# File lib/puppet/file_serving/configuration.rb 15 def self.configuration 16 @configuration ||= new 17 end
new()
click to toggle source
# File lib/puppet/file_serving/configuration.rb 35 def initialize 36 @mounts = {} 37 @config_file = nil 38 39 # We don't check to see if the file is modified the first time, 40 # because we always want to parse at first. 41 readconfig(false) 42 end
Public Instance Methods
find_mount(mount_name, environment)
click to toggle source
Find the right mount. Does some shenanigans to support old-style module mounts.
# File lib/puppet/file_serving/configuration.rb 28 def find_mount(mount_name, environment) 29 # Reparse the configuration if necessary. 30 readconfig 31 # This can be nil. 32 mounts[mount_name] 33 end
mounted?(name)
click to toggle source
Is a given mount available?
# File lib/puppet/file_serving/configuration.rb 45 def mounted?(name) 46 @mounts.include?(name) 47 end
split_path(request)
click to toggle source
Split the path into the separate mount point and path.
# File lib/puppet/file_serving/configuration.rb 50 def split_path(request) 51 # Reparse the configuration if necessary. 52 readconfig 53 54 mount_name, path = request.key.split(File::Separator, 2) 55 56 raise(ArgumentError, _("Cannot find file: Invalid mount '%{mount_name}'") % { mount_name: mount_name }) unless mount_name =~ %r{^[-\w]+$} 57 raise(ArgumentError, _("Cannot find file: Invalid relative path '%{path}'") % { path: path }) if path and path.split('/').include?('..') 58 59 mount = find_mount(mount_name, request.environment) 60 return nil unless mount 61 if mount.name == "modules" and mount_name != "modules" 62 # yay backward-compatibility 63 path = "#{mount_name}/#{path}" 64 end 65 66 if path == "" 67 path = nil 68 elsif path 69 # Remove any double slashes that might have occurred 70 path = path.gsub(/\/+/, "/") 71 end 72 73 return mount, path 74 end
umount(name)
click to toggle source
# File lib/puppet/file_serving/configuration.rb 76 def umount(name) 77 @mounts.delete(name) if @mounts.include? name 78 end
Private Instance Methods
mk_default_mounts()
click to toggle source
# File lib/puppet/file_serving/configuration.rb 82 def mk_default_mounts 83 @mounts["modules"] ||= Mount::Modules.new("modules") 84 @mounts["plugins"] ||= Mount::Plugins.new("plugins") 85 @mounts["locales"] ||= Mount::Locales.new("locales") 86 @mounts["pluginfacts"] ||= Mount::PluginFacts.new("pluginfacts") 87 @mounts["scripts"] ||= Mount::Scripts.new("scripts") 88 @mounts["tasks"] ||= Mount::Tasks.new("tasks") 89 end
readconfig(check = true)
click to toggle source
Read the configuration file.
# File lib/puppet/file_serving/configuration.rb 92 def readconfig(check = true) 93 config = Puppet[:fileserverconfig] 94 95 return unless Puppet::FileSystem.exist?(config) 96 97 @parser ||= Puppet::FileServing::Configuration::Parser.new(config) 98 99 return if check and ! @parser.changed? 100 101 # Don't assign the mounts hash until we're sure the parsing succeeded. 102 begin 103 newmounts = @parser.parse 104 @mounts = newmounts 105 rescue => detail 106 Puppet.log_exception(detail, _("Error parsing fileserver configuration: %{detail}; using old configuration") % { detail: detail }) 107 end 108 109 ensure 110 # Make sure we've got our plugins and modules. 111 mk_default_mounts 112 end