forked from octodns/octodns-cloudflare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttl.py
46 lines (37 loc) · 1.12 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
#
#
#
from octodns.processor.base import BaseProcessor, ProcessorException
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:
record = record.copy()
record._octodns['cloudflare'] = {
'proxied': True,
'auto-ttl': True,
}
record.ttl = 1
# Ensure we set to valid TTL.
zone.add_record(record, replace=True, lenient=True)
return zone