Skip to content

Add auto_ttl config parameter. #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ providers:
# A different limit for (non-)enterprise zone applies.
# See: https://developers.cloudflare.com/dns/manage-dns-records/reference/ttl
#min_ttl: 120
# Optional. Default: false. Set auto-ttl to true for all records by default.
#auto_ttl: false
```

Note: The "proxied" flag of "A", "AAAA" and "CNAME" records can be managed via the YAML provider like so:
Expand Down
4 changes: 3 additions & 1 deletion octodns_cloudflare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def __init__(
zones_per_page=50,
records_per_page=100,
min_ttl=120,
auto_ttl=False,
*args,
**kwargs,
):
Expand Down Expand Up @@ -127,6 +128,7 @@ def __init__(
self.zones_per_page = zones_per_page
self.records_per_page = records_per_page
self.min_ttl = min_ttl
self.auto_ttl = auto_ttl
self._sess = sess

self._zones = None
Expand Down Expand Up @@ -862,7 +864,7 @@ def _record_is_just_auto_ttl(self, record):
return (
not self._record_is_proxied(record)
and not self.cdn
and record._octodns.get('cloudflare', {}).get('auto-ttl', False)
and record._octodns.get('cloudflare', {}).get('auto-ttl', record.source != self and record._type != 'URLFWD' and self.auto_ttl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The record.source != self and URLFWD checks are worthy of an explanations/comments I would have expected this to just have the self.auto_ttl bit. Guessing the other clauses may be more general. Might also make sense to pull all of the default value stuff out into its own assignment before the return statement and just use that value here. Line is getting pretty long and multi-leveled.

Copy link
Author

@jmtorres jmtorres Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These performs checks on the record's context as _record_is_just_auto_ttl is used in a few different contexts.

URLFWD records do not utilize ttl. This mirrors other sections which ignore ttl for URLFWD records.

_record_is_just_auto_ttl is used to check the status of the auto-ttl flag on the live record on Cloudflare and the source record from other providers. The record.source != self ensures that we don't default records from Cloudflare to true, as we want the actual value in that case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Those explanations make sense. If you don't mind please move them into comments along with the code changes.

)

def _record_comment(self, record):
Expand Down
Loading