class Coppertone::Mechanism::DomainSpecWithDualCidr

Parent class for mechanisms that use a domain spec, and permit specification of an optional IPv4 CIDR and optional IPv6 CIDR.

Constants

CIDR_REGEXP

Public Class Methods

create(attributes) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 10
def self.create(attributes)
  new(attributes)
end
new(attributes) click to toggle source
Calls superclass method Coppertone::Mechanism::new
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 14
def initialize(attributes)
  super(attributes)
  return if attributes.blank?

  parse_argument(attributes)
rescue Coppertone::MacroStringParsingError
  raise Coppertone::InvalidMechanismError
end

Public Instance Methods

==(other) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 104
def ==(other)
  return false unless other.instance_of? self.class

  domain_spec == other.domain_spec &&
    ip_v4_cidr_length == other.ip_v4_cidr_length &&
    ip_v6_cidr_length == other.ip_v6_cidr_length
end
Also aliased as: eql?
clean_matches(attributes, cidr_matches) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 68
def clean_matches(attributes, cidr_matches)
  raw_ip_v4_cidr_length = cidr_matches[2] unless cidr_matches[2].blank?
  raw_ip_v6_cidr_length = cidr_matches[4] unless cidr_matches[4].blank?
  term = cidr_matches[0]
  domain_spec_end = term.blank? ? -1 : (-1 - term.length)
  macro_string = parse_domain_spec(attributes, domain_spec_end)
  [macro_string, raw_ip_v4_cidr_length, raw_ip_v6_cidr_length]
end
eql?(other)
Alias for: ==
generate_target_name(macro_context, request_context) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 92
def generate_target_name(macro_context, request_context)
  if domain_spec
    target_name_from_domain_spec(macro_context, request_context)
  else
    macro_context.domain
  end
end
handle_invalid_domain(_macro_context, _options) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 100
def handle_invalid_domain(_macro_context, _options)
  raise RecordParsingError
end
hash() click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 113
def hash
  domain_spec.hash ^ ip_v4_cidr_length.hash ^ ip_v6_cidr_length.hash
end
ip_v4_cidr_length() click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 23
def ip_v4_cidr_length
  @ip_v4_cidr_length ||= 32
end
ip_v6_cidr_length() click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 27
def ip_v6_cidr_length
  @ip_v6_cidr_length ||= 128
end
match?(macro_context, request_context) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 31
def match?(macro_context, request_context)
  request_context.register_dns_lookup_term
  target_name = generate_target_name(macro_context, request_context)
  if target_name
    match_target_name(macro_context, request_context, target_name)
  else
    handle_invalid_domain(macro_context, request_context)
  end
end
parse_argument(attributes) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 42
def parse_argument(attributes)
  raise InvalidMechanismError if attributes.blank?

  cidr_matches = CIDR_REGEXP.match(attributes)
  raise InvalidMechanismError unless cidr_matches

  macro_string, raw_ip_v4_cidr_length, raw_ip_v6_cidr_length =
    clean_matches(attributes, cidr_matches)
  process_matches(macro_string, raw_ip_v4_cidr_length,
                  raw_ip_v6_cidr_length)
end
parse_domain_spec(attributes, domain_spec_end) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 54
def parse_domain_spec(attributes, domain_spec_end)
  return nil if attributes.blank?

  cand = attributes[0..domain_spec_end]
  return nil if cand.blank?

  cand = trim_domain_spec(cand)
  # At this point we've ascertained that there is
  # a body to the domain spec
  raise InvalidMechanismError if cand.blank?

  cand
end
parse_v4_cidr_length(raw_length) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 84
def parse_v4_cidr_length(raw_length)
  @ip_v4_cidr_length = CidrParser.parse(raw_length, 32)
end
parse_v6_cidr_length(raw_length) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 88
def parse_v6_cidr_length(raw_length)
  @ip_v6_cidr_length = CidrParser.parse(raw_length, 128)
end
process_matches(macro_string, raw_ip_v4_cidr_length, raw_ip_v6_cidr_length) click to toggle source
# File lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb, line 77
def process_matches(macro_string, raw_ip_v4_cidr_length,
                    raw_ip_v6_cidr_length)
  @domain_spec = Coppertone::DomainSpec.new(macro_string) if macro_string
  parse_v4_cidr_length(raw_ip_v4_cidr_length)
  parse_v6_cidr_length(raw_ip_v6_cidr_length)
end