Class: Puppet::Network::AuthStore::Declaration

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

Overview

A single declaration. Stores the info for a given declaration, provides the methods for determining whether a declaration matches, and handles sorting the declarations appropriately.

Constant Summary

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Constructor Details

#initialize(type, pattern) ⇒ Declaration

Returns a new instance of Declaration.



141
142
143
144
# File 'lib/vendor/puppet/network/authstore.rb', line 141

def initialize(type, pattern)
  self.type = type
  self.pattern = pattern
end

Instance Attribute Details

#lengthObject

The length. Only used for iprange and domain.



122
123
124
# File 'lib/vendor/puppet/network/authstore.rb', line 122

def length
  @length
end

#nameObject

The name: :ip or :domain



114
115
116
# File 'lib/vendor/puppet/network/authstore.rb', line 114

def name
  @name
end

#patternObject

The pattern we’re matching against. Can be an IPAddr instance, or an array of strings, resulting from reversing a hostname or domain name.



119
120
121
# File 'lib/vendor/puppet/network/authstore.rb', line 119

def pattern
  @pattern
end

#typeObject

The type of declaration: either :allow or :deny



111
112
113
# File 'lib/vendor/puppet/network/authstore.rb', line 111

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object

Sort the declarations most specific first.



125
126
127
128
129
130
131
# File 'lib/vendor/puppet/network/authstore.rb', line 125

def <=>(other)
  compare(exact?, other.exact?) ||
  compare(ip?, other.ip?)  ||
  ((length != other.length) &&  (other.length <=> length)) ||
  compare(deny?, other.deny?) ||
  ( ip? ? pattern.to_s <=> other.pattern.to_s : pattern <=> other.pattern)
end

#deny?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/vendor/puppet/network/authstore.rb', line 133

def deny?
  type == :deny
end

#exact?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/vendor/puppet/network/authstore.rb', line 137

def exact?
  @exact == :exact
end

#interpolate(match) ⇒ Object

interpolate a pattern to replace any backreferences by the given match for instance if our pattern is $1.reductivelabs.com and we’re called with a MatchData whose capture 1 is puppet we’ll return a pattern of puppet.reductivelabs.com



192
193
194
195
196
197
198
199
200
# File 'lib/vendor/puppet/network/authstore.rb', line 192

def interpolate(match)
  clone = dup
  if @name == :dynamic
    clone.pattern = clone.pattern.reverse.collect do |p|
      p.gsub(/\$(\d)/) { |m| match[$1.to_i] }
    end.join(".")
  end
  clone
end

#ip?Boolean

Are we an IP type?

Returns:

  • (Boolean)


147
148
149
# File 'lib/vendor/puppet/network/authstore.rb', line 147

def ip?
  name == :ip
end

#match?(name, ip) ⇒ Boolean

Does this declaration match the name/ip combo?

Returns:

  • (Boolean)


152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/vendor/puppet/network/authstore.rb', line 152

def match?(name, ip)
  if ip?
    if pattern.include?(IPAddr.new(ip))
      Puppet.deprecation_warning "Authentication based on IP address is deprecated; please use certname-based rules instead"
      true
    else
      false
    end
  else
    matchname?(name)
  end
end

#resultObject

Mapping a type of statement into a return value.



172
173
174
# File 'lib/vendor/puppet/network/authstore.rb', line 172

def result
  type == :allow
end

#to_sObject



176
177
178
# File 'lib/vendor/puppet/network/authstore.rb', line 176

def to_s
  "#{type}: #{pattern}"
end