From 4dbe4da18435a355f9276df548007892747b638c Mon Sep 17 00:00:00 2001 From: Zeusina Date: Sun, 15 Mar 2026 19:34:38 +0300 Subject: [PATCH] feat: add cloudflare auto ttl --- .env.example | 6 ++++++ config.go | 7 +++++++ dns.go | 14 ++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/.env.example b/.env.example index a3627e6..188501d 100644 --- a/.env.example +++ b/.env.example @@ -30,6 +30,12 @@ PUBLIC_IPV6= # TTL (in seconds) for all generated DNS records. RECORD_TTL=300 +# Enable Cloudflare automatic TTL handling in OctoDNS-generated records: +# octodns.cloudflare.auto-ttl: true +# true - include provider-specific auto-ttl metadata +# false - do not include provider-specific metadata +CF_AUTO_TTL=true + # ── DNS Git repository ──────────────────────────────────────────────────────── # Absolute path to the pre-cloned DNS OctoDNS repository on the local filesystem. diff --git a/config.go b/config.go index afa1ca9..82c9762 100644 --- a/config.go +++ b/config.go @@ -29,6 +29,7 @@ type Config struct { DebounceDelay time.Duration RecordTTL int + CloudflareAutoTTL bool ExcludeRouters map[string]struct{} } @@ -83,6 +84,12 @@ func LoadConfig() (*Config, error) { return nil, fmt.Errorf("RECORD_TTL: invalid integer %q: %w", ttlStr, err) } + autoTTLStr := envOrDefault("CF_AUTO_TTL", "true") + cfg.CloudflareAutoTTL, err = strconv.ParseBool(autoTTLStr) + if err != nil { + return nil, fmt.Errorf("CF_AUTO_TTL: invalid boolean %q: %w", autoTTLStr, err) + } + cfg.ExcludeRouters = make(map[string]struct{}) if v := os.Getenv("EXCLUDE_ROUTERS"); v != "" { for _, r := range strings.Split(v, ",") { diff --git a/dns.go b/dns.go index e5e6b8b..29fa4e9 100644 --- a/dns.go +++ b/dns.go @@ -74,6 +74,13 @@ func buildRecord(cfg *Config) interface{} { "type": "A", "values": []string{cfg.PublicIP}, } + if cfg.CloudflareAutoTTL { + aRec["octodns"] = map[string]interface{}{ + "cloudflare": map[string]interface{}{ + "auto-ttl": true, + }, + } + } if cfg.PublicIPv6 == "" { return aRec } @@ -82,6 +89,13 @@ func buildRecord(cfg *Config) interface{} { "type": "AAAA", "values": []string{cfg.PublicIPv6}, } + if cfg.CloudflareAutoTTL { + aaaaRec["octodns"] = map[string]interface{}{ + "cloudflare": map[string]interface{}{ + "auto-ttl": true, + }, + } + } return []interface{}{aRec, aaaaRec} }