-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathttl.py
49 lines (38 loc) · 1.21 KB
/
ttl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#
#
#
from octodns.processor.base import BaseProcessor
from octodns_cloudflare import _PROXIABLE_RECORD_TYPES
class TtlToProxy(BaseProcessor):
'''
Ensure Cloudflare's proxy status is setup depending on the TTL set for the record. This
can be helpful for `octodns_bind.ZoneFileSource` or the like.
Example usage:
processors:
ttl-to-proxy:
class: octodns_cloudflare.processor.ttl.TtlToProxy
ttl: 0
zones:
exxampled.com.:
sources:
- config
processors:
- ttl-to-proxy
targets:
- cloudflare
'''
def __init__(self, name, ttl=0):
super().__init__(name)
self.ttl = ttl
def process_source_zone(self, zone, *args, **kwargs):
for record in zone.records:
if record.ttl == self.ttl:
attr = {'auto-ttl': True}
if record._type in _PROXIABLE_RECORD_TYPES:
attr['proxied'] = True
record = record.copy()
record._octodns['cloudflare'] = attr
record.ttl = 1
# Ensure we set to valid TTL.
zone.add_record(record, replace=True, lenient=True)
return zone