Class: Coppertone::Mechanism::DomainSpecWithDualCidr
Overview
Parent class for mechanisms that use a domain spec, and permit specification of an optional IPv4 CIDR and optional IPv6 CIDR.
Direct Known Subclasses
A, MX
Constant Summary
collapse
- CIDR_REGEXP =
%r{(/(\d*))?(//(\d*))?\z}
Instance Attribute Summary
#domain_spec
#arguments
Class Method Summary
collapse
Instance Method Summary
collapse
#context_dependent?, dns_lookup_term?, #includes_ptr?, #target_domain, #target_name_from_domain_spec, #trim_domain_spec
build, class_builder, #context_dependent?, dns_lookup_term?, #dns_lookup_term?, #includes_ptr?, register, #to_s
Constructor Details
Returns a new instance of DomainSpecWithDualCidr.
Class Method Details
.create(attributes) ⇒ Object
10
11
12
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 10
def self.create(attributes)
new(attributes)
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
98
99
100
101
102
103
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 98
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
|
#clean_matches(attributes, cidr_matches) ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 62
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
|
#generate_target_name(macro_context, request_context) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 86
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) ⇒ Object
94
95
96
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 94
def handle_invalid_domain(_macro_context, _options)
raise RecordParsingError
end
|
#hash ⇒ Object
106
107
108
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 106
def hash
domain_spec.hash ^ ip_v4_cidr_length.hash ^ ip_v6_cidr_length.hash
end
|
#ip_v4_cidr_length ⇒ Object
22
23
24
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 22
def ip_v4_cidr_length
@ip_v4_cidr_length ||= 32
end
|
#ip_v6_cidr_length ⇒ Object
26
27
28
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 26
def ip_v6_cidr_length
@ip_v6_cidr_length ||= 128
end
|
#match?(macro_context, request_context) ⇒ Boolean
30
31
32
33
34
35
36
37
38
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 30
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) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 41
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) ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 51
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)
raise InvalidMechanismError if cand.blank?
cand
end
|
#parse_v4_cidr_length(raw_length) ⇒ Object
78
79
80
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 78
def parse_v4_cidr_length(raw_length)
@ip_v4_cidr_length = CidrParser.parse(raw_length, 32)
end
|
#parse_v6_cidr_length(raw_length) ⇒ Object
82
83
84
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 82
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) ⇒ Object
71
72
73
74
75
76
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 71
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
|