Class: Puppet::FileServing::Configuration::Parser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/file_serving/configuration/parser.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

Mount =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Puppet::FileServing::Mount
MODULES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'modules'

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Parser

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Parser.


59
60
61
# File 'lib/puppet/file_serving/configuration/parser.rb', line 59

def initialize(filename)
  @file = Puppet::Util::WatchedFile.new(filename)
end

Instance Method Details

#changed?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

63
64
65
# File 'lib/puppet/file_serving/configuration/parser.rb', line 63

def changed?
  @file.changed?
end

#parseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parse our configuration file.


9
10
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
# File 'lib/puppet/file_serving/configuration/parser.rb', line 9

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($1)
      when /^\s*(\w+)\s+(.+?)(\s*#.*)?$/
        var = $1
        value = $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.new(_("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.new(_("Invalid entry at %{error_location}: '%{file_text}'") %
                                    { file_text: line.chomp, error_location: error_location_str })
      end
    end
  end

  validate

  @mounts
end