Skip to content

Commit

Permalink
Merge pull request #77 from TheDJVG/76-make-min_ttl-configurable
Browse files Browse the repository at this point in the history
Make minimum TTL configurable
  • Loading branch information
ross authored Jan 26, 2024
2 parents baf0730 + fc2eae4 commit 61eaa26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
9 changes: 5 additions & 4 deletions octodns_cloudflare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class CloudflareProvider(BaseProvider):
)
)

MIN_TTL = 120
TIMEOUT = 15

def __init__(
Expand All @@ -79,6 +78,7 @@ def __init__(
retry_period=300,
zones_per_page=50,
records_per_page=100,
min_ttl=120,
*args,
**kwargs,
):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 61eaa26

Please sign in to comment.