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
59 def initialize(filename)
60   @file = Puppet::Util::WatchedFile.new(filename)
61 end

Public Instance Methods

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

Parse our configuration file.

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

Private Instance Methods

newmount(name) click to toggle source

Create a new mount.

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

Set the path for a mount.

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