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

Inherits:
Object
  • Object
show all
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, Util::RFC_3986_URI_REGEX

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Instance Attribute Summary collapse

Instance Method Summary collapse

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::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from Util::POSIX

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

Constructor Details

#initialize(type, pattern) ⇒ Declaration


149
150
151
152
# File 'lib/puppet/network/authstore.rb', line 149

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

Instance Attribute Details

#lengthObject

The length. Only used for iprange and domain.


130
131
132
# File 'lib/puppet/network/authstore.rb', line 130

def length
  @length
end

#nameObject

Returns the value of attribute name


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

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.


127
128
129
# File 'lib/puppet/network/authstore.rb', line 127

def pattern
  @pattern
end

#typeObject

The type of declaration: either :allow or :deny


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

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object

Sort the declarations most specific first.


133
134
135
136
137
138
139
# File 'lib/puppet/network/authstore.rb', line 133

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


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

def deny?
  type == :deny
end

#exact?Boolean


145
146
147
# File 'lib/puppet/network/authstore.rb', line 145

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


199
200
201
202
203
204
205
206
207
# File 'lib/puppet/network/authstore.rb', line 199

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?


155
156
157
# File 'lib/puppet/network/authstore.rb', line 155

def ip?
  name == :ip
end

#match?(name, ip) ⇒ Boolean

Does this declaration match the name/ip combo?


160
161
162
163
164
165
166
# File 'lib/puppet/network/authstore.rb', line 160

def match?(name, ip)
  if ip?
    pattern.include?(IPAddr.new(ip))
  else
    matchname?(name)
  end
end

#resultObject

Mapping a type of statement into a return value.


179
180
181
# File 'lib/puppet/network/authstore.rb', line 179

def result
  [:allow, :allow_ip].include?(type)
end

#to_sObject


183
184
185
# File 'lib/puppet/network/authstore.rb', line 183

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