# class Puppet::Network::AuthStore::Declaration

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.

### Constants

IP

  It should be:

      IP = "#{IPv4}|#{IPv6_full}|(#{IPv6_partial}#{IPv4})".gsub(/_/,'([0-9a-fA-F]{1,4})').gsub(/\(/,'(?:')

  but ruby’s ipaddr lib doesn’t support the hybrid format

IPv4
IPv6_full
IPv6_partial
Octet

  Parse our input pattern and figure out what kind of allowal statement it is. The output of this is used for later matching.

VALID_TYPES

### Attributes

length[RW]

The length. Only used for iprange and domain.

name[RW]
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

### Public Class Methods

new(type, pattern) click to toggle source

    # File lib/puppet/network/authstore.rb, line 149
    def initialize(type, pattern)
      self.type = type
      self.pattern = pattern
    end

### Public Instance Methods

<=>(other) click to toggle source

Sort the declarations most specific first.

    # 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?() click to toggle source

    # File lib/puppet/network/authstore.rb, line 141
    def deny?
      type == :deny
    end

exact?() click to toggle source

    # File lib/puppet/network/authstore.rb, line 145
    def exact?
      @exact == :exact
    end

interpolate(match) click to toggle source

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

    # 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?() click to toggle source

Are we an IP type?

    # File lib/puppet/network/authstore.rb, line 155
    def ip?
      name == :ip
    end

match?(name, ip) click to toggle source

Does this declaration match the name/ip combo?

    # File lib/puppet/network/authstore.rb, line 160
    def match?(name, ip)
      if ip?
        pattern.include?(IPAddr.new(ip))
      else
        matchname?(name)
      end
    end

pattern=(pattern) click to toggle source

Set the pattern appropriately. Also sets the name and length.

    # File lib/puppet/network/authstore.rb, line 169
    def pattern=(pattern)
      if [:allow_ip, :deny_ip].include?(self.type)
        parse_ip(pattern)
      else
        parse(pattern)
      end
      @orig = pattern
    end

result() click to toggle source

Mapping a type of statement into a return value.

    # File lib/puppet/network/authstore.rb, line 179
    def result
      [:allow, :allow_ip].include?(type)
    end

to_s() click to toggle source

    # File lib/puppet/network/authstore.rb, line 183
    def to_s
      "#{type}: #{pattern}"
    end

type=(type) click to toggle source

Set the declaration type. Either :allow or :deny.

    # File lib/puppet/network/authstore.rb, line 188
    def type=(type)
      type = type.intern
      raise ArgumentError, "Invalid declaration type #{type}" unless VALID_TYPES.include?(type)
      @type = type
    end