A right.
Overriding Object#methods sucks for debugging. If we’re in here in the future, it would be nice to rename #methods
Overriding Object#methods sucks for debugging. If we’re in here in the future, it would be nice to rename #methods
Overriding Object#methods sucks for debugging. If we’re in here in the future, it would be nice to rename #methods
# File lib/puppet/network/rights.rb, line 120 def initialize(name, line, file) @methods = [] @environment = [] @authentication = true # defaults to authenticated @name = name @line = line || 0 @file = file @methods = ALL case name when /^\// @key = Regexp.new("^" + Regexp.escape(name)) when /^~/ # this is a regex @name = name.gsub(/^~\s+/,'') @key = Regexp.new(@name) else raise ArgumentError, "Unknown right type '#{name}'" end super() end
# File lib/puppet/network/rights.rb, line 214 def ==(name) self.name == name.gsub(/^~\s+/,'') end
does this right is allowed for this triplet? if this right is too restrictive (ie we don’t match this access method) then return :dunno so that upper layers have a chance to try another right tailored to the given method
# File lib/puppet/network/rights.rb, line 155 def allowed?(name, ip, args = {}) if not @methods.include?(args[:method]) return :dunno elsif @environment.size > 0 and not @environment.include?(args[:environment]) return :dunno elsif (@authentication and not args[:authenticated]) return :dunno end begin # make sure any capture are replaced if needed interpolate(args[:match]) if args[:match] res = super(name,ip) ensure reset_interpolation end res end
# File lib/puppet/network/rights.rb, line 209 def match?(key) # otherwise match with the regex self.key.match(key) end
# File lib/puppet/network/rights.rb, line 197 def restrict_authenticated(authentication) case authentication when "yes", "on", "true", true authentication = true when "no", "off", "false", false, "all" ,"any", :all, :any authentication = false else raise ArgumentError, "'#{name}' incorrect authenticated value: #{authentication}" end @authentication = authentication end
# File lib/puppet/network/rights.rb, line 190 def restrict_environment(env) env = Puppet::Node::Environment.new(env) raise ArgumentError, "'#{env}' is already in the '#{name}' ACL" if @environment.include?(env) @environment << env end
restrict this right to some method only
# File lib/puppet/network/rights.rb, line 175 def restrict_method(m) m = m.intern if m.is_a?(String) raise ArgumentError, "'#{m}' is not an allowed value for method directive" unless ALL.include?(m) # if we were allowing all methods, then starts from scratch if @methods === ALL @methods = [] end raise ArgumentError, "'#{m}' is already in the '#{name}' ACL" if @methods.include?(m) @methods << m end
# File lib/puppet/network/rights.rb, line 142 def to_s "access[#{@name}]" end
There’s no real check to do at this point
# File lib/puppet/network/rights.rb, line 147 def valid? true end