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