class Puppet::FileServing::Configuration::Parser

Constants

MODULES
Mount

Public Class Methods

new(filename) click to toggle source
   # File lib/puppet/file_serving/configuration/parser.rb
60 def initialize(filename)
61   @file = Puppet::Util::WatchedFile.new(filename)
62 end

Public Instance Methods

changed?() click to toggle source
   # File lib/puppet/file_serving/configuration/parser.rb
64 def changed?
65   @file.changed?
66 end
parse() click to toggle source

Parse our configuration file.

   # File lib/puppet/file_serving/configuration/parser.rb
10 def parse
11   raise(_("File server configuration %{config_file} does not exist") % { config_file: @file }) unless Puppet::FileSystem.exist?(@file)
12   raise(_("Cannot read file server configuration %{config_file}") % { config_file: @file }) unless FileTest.readable?(@file)
13 
14   @mounts = {}
15   @count = 0
16 
17   File.open(@file) do |f|
18     mount = nil
19     f.each_line do |line|
20       # Have the count increment at the top, in case we throw exceptions.
21       @count += 1
22 
23       case line
24       when /^\s*#/; next # skip comments
25       when /^\s*$/; next # skip blank lines
26       when /\[([-\w]+)\]/
27         mount = newmount($1)
28       when /^\s*(\w+)\s+(.+?)(\s*#.*)?$/
29         var = $1
30         value = $2
31         value.strip!
32         raise(ArgumentError, _("Fileserver configuration file does not use '=' as a separator")) if value =~ /^=/
33         case var
34         when "path"
35           path(mount, value)
36         when "allow", "deny"
37           # ignore `allow *`, otherwise report error
38           if var != 'allow' || value != '*'
39             error_location_str = Puppet::Util::Errors.error_location(@file.filename, @count)
40             Puppet.err("Entry '#{line.chomp}' is unsupported and will be ignored at #{error_location_str}")
41           end
42         else
43           error_location_str = Puppet::Util::Errors.error_location(@file.filename, @count)
44           raise ArgumentError.new(_("Invalid argument '%{var}' at %{error_location}") %
45                                       { var: var, error_location: error_location_str })
46         end
47       else
48         error_location_str = Puppet::Util::Errors.error_location(@file.filename, @count)
49         raise ArgumentError.new(_("Invalid entry at %{error_location}: '%{file_text}'") %
50                                     { file_text: line.chomp, error_location: error_location_str })
51       end
52     end
53   end
54 
55   validate
56 
57   @mounts
58 end

Private Instance Methods

newmount(name) click to toggle source

Create a new mount.

   # File lib/puppet/file_serving/configuration/parser.rb
71 def newmount(name)
72   if @mounts.include?(name)
73     error_location_str = Puppet::Util::Errors.error_location(@file, @count)
74     raise ArgumentError.new(_("%{mount} is already mounted at %{name} at %{error_location}") %
75                                 { mount: @mounts[name], name: name, error_location: error_location_str })
76   end
77   case name
78   when "modules"
79     mount = Mount::Modules.new(name)
80   when "plugins"
81     mount = Mount::Plugins.new(name)
82   when "scripts"
83     mount = Mount::Scripts.new(name)
84   when "tasks"
85     mount = Mount::Tasks.new(name)
86   when "locales"
87     mount = Mount::Locales.new(name)
88   else
89     mount = Mount::File.new(name)
90   end
91   @mounts[name] = mount
92   mount
93 end
path(mount, value) click to toggle source

Set the path for a mount.

    # File lib/puppet/file_serving/configuration/parser.rb
 96 def path(mount, value)
 97   if mount.respond_to?(:path=)
 98     begin
 99       mount.path = value
100     rescue ArgumentError => detail
101       Puppet.log_exception(detail, _("Removing mount \"%{mount}\": %{detail}") % { mount: mount.name, detail: detail })
102       @mounts.delete(mount.name)
103     end
104   else
105     Puppet.warning _("The '%{mount}' module can not have a path. Ignoring attempt to set it") % { mount: mount.name }
106   end
107 end
validate() click to toggle source

Make sure all of our mounts are valid. We have to do this after the fact because details are added over time as the file is parsed.

    # File lib/puppet/file_serving/configuration/parser.rb
111 def validate
112   @mounts.each { |name, mount| mount.validate }
113 end