feat: add cloudflare auto ttl

This commit is contained in:
2026-03-15 19:34:38 +03:00
parent 27c03fff46
commit 607235d311
3 changed files with 27 additions and 0 deletions

View File

@@ -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.

View File

@@ -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, ",") {

14
dns.go
View File

@@ -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}
}