Class: Coppertone::Mechanism::MX

Inherits:
DomainSpecWithDualCidr show all
Defined in:
lib/coppertone/mechanism/mx.rb

Overview

Implements the MX mechanism.

Constant Summary

Constants inherited from DomainSpecWithDualCidr

DomainSpecWithDualCidr::CIDR_REGEXP

Instance Attribute Summary

Attributes inherited from DomainSpecMechanism

#domain_spec

Attributes inherited from Coppertone::Mechanism

#arguments

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DomainSpecWithDualCidr

#==, #clean_matches, create, #generate_target_name, #handle_invalid_domain, #hash, #initialize, #ip_v4_cidr_length, #ip_v6_cidr_length, #match?, #parse_argument, #parse_domain_spec, #parse_v4_cidr_length, #parse_v6_cidr_length, #process_matches

Methods inherited from DomainSpecMechanism

#==, #context_dependent?, dns_lookup_term?, #hash, #includes_ptr?, #target_domain, #target_name_from_domain_spec, #trim_domain_spec

Methods inherited from Coppertone::Mechanism

build, class_builder, #context_dependent?, dns_lookup_term?, #dns_lookup_term?, #includes_ptr?, #initialize, register, #to_s

Constructor Details

This class inherits a constructor from Coppertone::Mechanism::DomainSpecWithDualCidr

Class Method Details

.labelObject



39
40
41
# File 'lib/coppertone/mechanism/mx.rb', line 39

def self.label
  'mx'
end

Instance Method Details

#check_a_record_limit(request_context, count) ⇒ Object



32
33
34
35
36
37
# File 'lib/coppertone/mechanism/mx.rb', line 32

def check_a_record_limit(request_context, count)
  limit = request_context.dns_lookups_per_mx_mechanism_limit
  return unless limit && count > limit

  raise Coppertone::MXLimitExceededError
end

#ip_checker(macro_context, request_context) ⇒ Object



20
21
22
23
# File 'lib/coppertone/mechanism/mx.rb', line 20

def ip_checker(macro_context, request_context)
  Coppertone::Utils::IPInDomainChecker.new(macro_context,
                                           request_context)
end

#look_up_mx_exchanges(request_context, target_name) ⇒ Object



25
26
27
28
29
30
# File 'lib/coppertone/mechanism/mx.rb', line 25

def look_up_mx_exchanges(request_context, target_name)
  dns_client = request_context.dns_client
  dns_client.fetch_mx_records(target_name).map do |mx|
    mx[:exchange]
  end
end

#match_target_name(macro_context, request_context, target_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/coppertone/mechanism/mx.rb', line 7

def match_target_name(macro_context, request_context, target_name)
  mx_exchange_names = look_up_mx_exchanges(request_context, target_name)

  count = 0
  checker = ip_checker(macro_context, request_context)
  matched_record = mx_exchange_names.find do |mx|
    count += 1
    check_a_record_limit(request_context, count)
    checker.check(mx, ip_v4_cidr_length, ip_v6_cidr_length)
  end
  !matched_record.nil?
end