Class: Puppet::Network::AuthConfig

Inherits:
Util::LoadedFile show all
Defined in:
lib/vendor/puppet/network/authconfig.rb

Direct Known Subclasses

RestAuthConfig

Instance Attribute Summary

Attributes inherited from Util::LoadedFile

#file, #statted, #tstamp

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Util::LoadedFile

#changed?, #stamp, #to_s

Constructor Details

#initialize(file = nil, parsenow = true) ⇒ AuthConfig

Returns a new instance of AuthConfig.

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vendor/puppet/network/authconfig.rb', line 42

def initialize(file = nil, parsenow = true)
  @file = file || Puppet[:authconfig]

  raise Puppet::DevError, "No authconfig file defined" unless @file
  return unless self.exists?
  super(@file)
  @rights = Puppet::Network::Rights.new
  @configstamp = @configstatted = nil
  @configtimeout = 60

  read if parsenow
end

Class Method Details

.mainObject



8
9
10
# File 'lib/vendor/puppet/network/authconfig.rb', line 8

def self.main
  @main ||= self.new
end

Instance Method Details

#allowed?(request) ⇒ Boolean

Here we add a little bit of semantics. They can set auth on a whole namespace or on just a single method in the namespace.

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vendor/puppet/network/authconfig.rb', line 21

def allowed?(request)
  name        = request.call.intern
  namespace   = request.handler.intern
  method      = request.method.intern

  read

  if @rights.include?(name)
    return @rights[name].allowed?(request.name, request.ip)
  elsif @rights.include?(namespace)
    return @rights[namespace].allowed?(request.name, request.ip)
  end
  false
end

#exists?Boolean

Does the file exist? Puppetmasterd does not require it, but puppet agent does.

Returns:

  • (Boolean)


38
39
40
# File 'lib/vendor/puppet/network/authconfig.rb', line 38

def exists?
  FileTest.exists?(@file)
end

#readObject

Read the configuration file.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vendor/puppet/network/authconfig.rb', line 56

def read
  return unless FileTest.exists?(@file)

  if @configstamp
    if @configtimeout and @configstatted
      if Time.now - @configstatted > @configtimeout
        @configstatted = Time.now
        tmp = File.stat(@file).ctime

        if tmp == @configstamp
          return
        else
          Puppet.notice "#{tmp} vs #{@configstamp}"
        end
      else
        return
      end
    else
      Puppet.notice "#{@configtimeout} and #{@configstatted}"
    end
  end

  parse

  @configstamp = File.stat(@file).ctime
  @configstatted = Time.now
end