Class: Puppet::Network::AuthStore

Inherits:
Object
  • Object
show all
Includes:
Util::Logging
Defined in:
lib/vendor/puppet/network/authstore.rb

Defined Under Namespace

Classes: Declaration

Instance Method Summary collapse

Methods included from Util::Logging

#clear_deprecation_warnings, #deprecation_warning, #send_log

Constructor Details

#initializeAuthStore

Returns a new instance of AuthStore.



67
68
69
70
# File 'lib/vendor/puppet/network/authstore.rb', line 67

def initialize
  @globalallow = nil
  @declarations = []
end

Instance Method Details

#allow(pattern) ⇒ Object

Mark a given pattern as allowed.



15
16
17
18
19
20
21
22
23
24
# File 'lib/vendor/puppet/network/authstore.rb', line 15

def allow(pattern)
  # a simple way to allow anyone at all to connect
  if pattern == "*"
    @globalallow = true
  else
    store(:allow, pattern)
  end

  nil
end

#allowed?(name, ip) ⇒ Boolean

Is a given combination of name and ip address allowed? If either input is non-nil, then both inputs must be provided. If neither input is provided, then the authstore is considered local and defaults to “true”.

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/vendor/puppet/network/authstore.rb', line 29

def allowed?(name, ip)
  if name or ip
    # This is probably unnecessary, and can cause some weirdnesses in
    # cases where we're operating over localhost but don't have a real
    # IP defined.
    raise Puppet::DevError, "Name and IP must be passed to 'allowed?'" unless name and ip
    # else, we're networked and such
  else
    # we're local
    return true
  end

  # yay insecure overrides
  return true if globalallow?

  if decl = declarations.find { |d| d.match?(name, ip) }
    return decl.result
  end

  info "defaulting to no access for #{name}"
  false
end

#deny(pattern) ⇒ Object

Deny a given pattern.



53
54
55
# File 'lib/vendor/puppet/network/authstore.rb', line 53

def deny(pattern)
  store(:deny, pattern)
end

#empty?Boolean

does this auth store has any rules?

Returns:

  • (Boolean)


63
64
65
# File 'lib/vendor/puppet/network/authstore.rb', line 63

def empty?
  @globalallow.nil? && @declarations.size == 0
end

#globalallow?Boolean

Is global allow enabled?

Returns:

  • (Boolean)


58
59
60
# File 'lib/vendor/puppet/network/authstore.rb', line 58

def globalallow?
  @globalallow
end

#interpolate(match) ⇒ Object



76
77
78
# File 'lib/vendor/puppet/network/authstore.rb', line 76

def interpolate(match)
  Thread.current[:declarations] = @declarations.collect { |ace| ace.interpolate(match) }.sort
end

#reset_interpolationObject



80
81
82
# File 'lib/vendor/puppet/network/authstore.rb', line 80

def reset_interpolation
  Thread.current[:declarations] = nil
end

#to_sObject



72
73
74
# File 'lib/vendor/puppet/network/authstore.rb', line 72

def to_s
  "authstore"
end