From 8a0a20489bd5e1b853d2babc36ae521990dc439d Mon Sep 17 00:00:00 2001 From: Daan van Gorkum Date: Fri, 26 Jan 2024 10:13:03 +0800 Subject: [PATCH 1/2] Make minimum TTL configurable This commit allows to set the `min_ttl` configuration option. The default is kept as the originel 120 seconds. resolves #76 Signed-off-by: Daan van Gorkum --- CHANGELOG.md | 1 + octodns_cloudflare/__init__.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62de732..e282935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Support for auto-ttl without proxied as records can be configured that way, see auto-ttl in README.md for more info * Fix bug in handling of empty strings/content on TXT records +* Make the minumum supported TTL configurable. ## v0.0.3 - 2023-09-20 - All the commits fit to release diff --git a/octodns_cloudflare/__init__.py b/octodns_cloudflare/__init__.py index ed4b580..d9ab96b 100644 --- a/octodns_cloudflare/__init__.py +++ b/octodns_cloudflare/__init__.py @@ -64,7 +64,6 @@ class CloudflareProvider(BaseProvider): ) ) - MIN_TTL = 120 TIMEOUT = 15 def __init__( @@ -79,6 +78,7 @@ def __init__( retry_period=300, zones_per_page=50, records_per_page=100, + min_ttl=120, *args, **kwargs, ): @@ -111,6 +111,7 @@ def __init__( self.retry_period = retry_period self.zones_per_page = zones_per_page self.records_per_page = records_per_page + self.min_ttl = min_ttl self._sess = sess self._zones = None @@ -560,8 +561,8 @@ def _include_change(self, change): # Cloudflare has a minimum TTL, we need to clamp the TTL values so # that we ignore a desired state (new) where we can't support the # TTL - new['ttl'] = max(self.MIN_TTL, new['ttl']) - existing['ttl'] = max(self.MIN_TTL, existing['ttl']) + new['ttl'] = max(self.min_ttl, new['ttl']) + existing['ttl'] = max(self.min_ttl, existing['ttl']) if new == existing: return False @@ -736,7 +737,7 @@ def _gen_data(self, record): # when either is the case we tell Cloudflare with ttl=1 ttl = 1 else: - ttl = max(self.MIN_TTL, record.ttl) + ttl = max(self.min_ttl, record.ttl) # Cloudflare supports ALIAS semantics with a root CNAME if _type == 'ALIAS': From fc2eae43cf291e9c9c69561cc7c1dba61ab2b1a6 Mon Sep 17 00:00:00 2001 From: Daan van Gorkum Date: Fri, 26 Jan 2024 13:40:23 +0800 Subject: [PATCH 2/2] Update README with information about minimum TTL Signed-off-by: Daan van Gorkum --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index a7c4307..2cb491f 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,10 @@ providers: #zones_per_page: 50 # Optional. Default: 100. Number of dns records per page. #records_per_page: 100 + # Optional. Default: 120. Lowest TTL allowed to be set. + # A different limit for (non-)enterprise zone applies. + # See: https://developers.cloudflare.com/dns/manage-dns-records/reference/ttl + #min_ttl: 120 ``` Note: The "proxied" flag of "A", "AAAA" and "CNAME" records can be managed via the YAML provider like so: @@ -110,6 +114,11 @@ CloudflareProvider does not support dynamic records. Required Permissions for API Token are Zone:Read, DNS:Read, and DNS:Edit. +#### TTL + +Cloudflare has a different minimum TTL for enterprise and non-enterprise zones. See the [documentation](https://developers.cloudflare.com/dns/manage-dns-records/reference/ttl) for more information. +In the past the CloudflareProvider had a fixed minimum TTL set to 120 seconds and for backwards compatbility this is the current default. + ### Developement See the [/script/](/script/) directory for some tools to help with the development process. They generally follow the [Script to rule them all](https://github.com/github/scripts-to-rule-them-all) pattern. Most useful is `./script/bootstrap` which will create a venv and install both the runtime and development related requirements. It will also hook up a pre-commit hook that covers most of what's run by CI.