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

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

#get_posix_field, #gid, groups_of, #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

#lengthObject

The length. Only used for iprange and domain.



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

def length
  @length
end

#nameObject

Returns the value of attribute name.



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

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.



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

def pattern
  @pattern
end

#typeObject

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

Returns:

  • (Boolean)


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

def deny?
  type == :deny
end

#exact?Boolean

Returns:

  • (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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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

#resultObject

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_sObject



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

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