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}.freeze
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?
104
105
106
107
108
109
110
|
# 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
|
#clean_matches(attributes, cidr_matches) ⇒ Object
68
69
70
71
72
73
74
75
|
# 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
|
#generate_target_name(macro_context, request_context) ⇒ Object
92
93
94
95
96
97
98
|
# 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) ⇒ Object
100
101
102
|
# File 'lib/coppertone/mechanism/domain_spec_with_dual_cidr.rb', line 100
def handle_invalid_domain(_macro_context, _options)
raise RecordParsingError
end
|
#hash ⇒ Object
113
114
115
|
# 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 ⇒ Object
23
24
25
|
# 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 ⇒ Object
27
28
29
|
# 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) ⇒ Boolean
31
32
33
34
35
36
37
38
39
|
# 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) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# 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) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# 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)
raise InvalidMechanismError if cand.blank?
cand
end
|
#parse_v4_cidr_length(raw_length) ⇒ Object
84
85
86
|
# 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) ⇒ Object
88
89
90
|
# 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) ⇒ Object
77
78
79
80
81
82
|
# 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
|