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

Inherits:
Util::LoadedFile show all
Defined in:
lib/vendor/puppet/file_serving/configuration/parser.rb

Constant Summary collapse

Mount =
Puppet::FileServing::Mount
MODULES =
'modules'

Instance Attribute Summary

Attributes inherited from Util::LoadedFile

#file, #statted, #tstamp

Instance Method Summary collapse

Methods inherited from Util::LoadedFile

#changed?, #initialize, #stamp, #to_s

Constructor Details

This class inherits a constructor from Puppet::Util::LoadedFile

Instance Method Details

#parseObject

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

def parse
  raise("File server configuration #{self.file} does not exist") unless FileTest.exists?(self.file)
  raise("Cannot read file server configuration #{self.file}") unless FileTest.readable?(self.file)

  @mounts = {}
  @count = 0

  File.open(self.file) { |f|
    mount = nil
    f.each_line { |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"
          allow(mount, value)
        when "deny"
          deny(mount, value)
        else
          raise ArgumentError.new("Invalid argument '#{var}'", @count, file)
        end
      else
        raise ArgumentError.new("Invalid line '#{line.chomp}'", @count, file)
      end
    }
  }

  validate

  @mounts
end