Class: Puppet::Network::AuthStore::Declaration
- Includes:
- Comparable, Util
- Defined in:
- lib/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 collapse
- VALID_TYPES =
[ :allow, :deny, :allow_ip, :deny_ip ]
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Instance Attribute Summary collapse
-
#length ⇒ Object
The length.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pattern ⇒ Object
The pattern we’re matching against.
-
#type ⇒ Object
The type of declaration: either :allow or :deny.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Sort the declarations most specific first.
- #deny? ⇒ Boolean
- #exact? ⇒ Boolean
-
#initialize(type, pattern) ⇒ Declaration
constructor
A new instance of Declaration.
-
#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.
-
#ip? ⇒ Boolean
Are we an IP type?.
-
#match?(name, ip) ⇒ Boolean
Does this declaration match the name/ip combo?.
-
#result ⇒ Object
Mapping a type of statement into a return value.
- #to_s ⇒ Object
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Constructor Details
#initialize(type, pattern) ⇒ Declaration
Returns a new instance of Declaration.
148 149 150 151 |
# File 'lib/puppet/network/authstore.rb', line 148 def initialize(type, pattern) self.type = type self.pattern = pattern end |
Instance Attribute Details
#length ⇒ Object
The length. Only used for iprange and domain.
129 130 131 |
# File 'lib/puppet/network/authstore.rb', line 129 def length @length end |
#name ⇒ Object
Returns the value of attribute name.
121 122 123 |
# File 'lib/puppet/network/authstore.rb', line 121 def name @name end |
#pattern ⇒ Object
The pattern we’re matching against. Can be an IPAddr instance, or an array of strings, resulting from reversing a hostname or domain name.
126 127 128 |
# File 'lib/puppet/network/authstore.rb', line 126 def pattern @pattern end |
#type ⇒ Object
The type of declaration: either :allow or :deny
118 119 120 |
# File 'lib/puppet/network/authstore.rb', line 118 def type @type end |
Instance Method Details
#<=>(other) ⇒ Object
Sort the declarations most specific first.
132 133 134 135 136 137 138 |
# File 'lib/puppet/network/authstore.rb', line 132 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
140 141 142 |
# File 'lib/puppet/network/authstore.rb', line 140 def deny? type == :deny end |
#exact? ⇒ Boolean
144 145 146 |
# File 'lib/puppet/network/authstore.rb', line 144 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
198 199 200 201 202 203 204 205 206 |
# File 'lib/puppet/network/authstore.rb', line 198 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?
154 155 156 |
# File 'lib/puppet/network/authstore.rb', line 154 def ip? name == :ip end |
#match?(name, ip) ⇒ Boolean
Does this declaration match the name/ip combo?
159 160 161 162 163 164 165 |
# File 'lib/puppet/network/authstore.rb', line 159 def match?(name, ip) if ip? pattern.include?(IPAddr.new(ip)) else matchname?(name) end end |
#result ⇒ Object
Mapping a type of statement into a return value.
178 179 180 |
# File 'lib/puppet/network/authstore.rb', line 178 def result [:allow, :allow_ip].include?(type) end |
#to_s ⇒ Object
182 183 184 |
# File 'lib/puppet/network/authstore.rb', line 182 def to_s "#{type}: #{pattern}" end |