| Class | Puppet::Network::AuthStore::Declaration |
| In: |
lib/puppet/network/authstore.rb
|
| Parent: | Object |
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.
| length | [RW] | The length. Only used for iprange and domain. |
| name | [RW] | The name: :ip or :domain |
| pattern | [R] | The pattern we‘re matching against. Can be an IPAddr instance, or an array of strings, resulting from reversing a hostname or domain name. |
| type | [R] | The type of declaration: either :allow or :deny |
# File lib/puppet/network/authstore.rb, line 149
149: def initialize(type, pattern)
150: self.type = type
151: self.pattern = pattern
152: end
Sort the declarations specially.
# File lib/puppet/network/authstore.rb, line 108
108: def <=>(other)
109: # Sort first based on whether the matches are exact.
110: if r = compare(exact?, other.exact?)
111: return r
112: end
113:
114: # Then by type
115: if r = compare(self.ip?, other.ip?)
116: return r
117: end
118:
119: # Next sort based on length
120: unless self.length == other.length
121: # Longer names/ips should go first, because they're more
122: # specific.
123: return other.length <=> self.length
124: end
125:
126: # Then sort deny before allow
127: if r = compare(self.deny?, other.deny?)
128: return r
129: end
130:
131: # We've already sorted by name and length, so all that's left
132: # is the pattern
133: if ip?
134: return self.pattern.to_s <=> other.pattern.to_s
135: else
136: return self.pattern <=> other.pattern
137: end
138: end
Are we an IP type?
# File lib/puppet/network/authstore.rb, line 155
155: def ip?
156: self.name == :ip
157: end
Does this declaration match the name/ip combo?
# File lib/puppet/network/authstore.rb, line 160
160: def match?(name, ip)
161: if self.ip?
162: return pattern.include?(IPAddr.new(ip))
163: else
164: return matchname?(name)
165: end
166: end
Set the pattern appropriately. Also sets the name and length.
# File lib/puppet/network/authstore.rb, line 169
169: def pattern=(pattern)
170: parse(pattern)
171: @orig = pattern
172: end
Mapping a type of statement into a return value.
# File lib/puppet/network/authstore.rb, line 175
175: def result
176: case @type
177: when :allow: true
178: else
179: false
180: end
181: end
# File lib/puppet/network/authstore.rb, line 183
183: def to_s
184: "%s: %s" % [self.type, self.pattern]
185: end