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