feat: add cloudflare auto ttl
This commit is contained in:
@@ -30,6 +30,12 @@ PUBLIC_IPV6=
|
|||||||
# TTL (in seconds) for all generated DNS records.
|
# TTL (in seconds) for all generated DNS records.
|
||||||
RECORD_TTL=300
|
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 ────────────────────────────────────────────────────────
|
# ── DNS Git repository ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
# Absolute path to the pre-cloned DNS OctoDNS repository on the local filesystem.
|
# Absolute path to the pre-cloned DNS OctoDNS repository on the local filesystem.
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ type Config struct {
|
|||||||
DebounceDelay time.Duration
|
DebounceDelay time.Duration
|
||||||
|
|
||||||
RecordTTL int
|
RecordTTL int
|
||||||
|
CloudflareAutoTTL bool
|
||||||
ExcludeRouters map[string]struct{}
|
ExcludeRouters map[string]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +84,12 @@ func LoadConfig() (*Config, error) {
|
|||||||
return nil, fmt.Errorf("RECORD_TTL: invalid integer %q: %w", ttlStr, err)
|
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{})
|
cfg.ExcludeRouters = make(map[string]struct{})
|
||||||
if v := os.Getenv("EXCLUDE_ROUTERS"); v != "" {
|
if v := os.Getenv("EXCLUDE_ROUTERS"); v != "" {
|
||||||
for _, r := range strings.Split(v, ",") {
|
for _, r := range strings.Split(v, ",") {
|
||||||
|
|||||||
14
dns.go
14
dns.go
@@ -74,6 +74,13 @@ func buildRecord(cfg *Config) interface{} {
|
|||||||
"type": "A",
|
"type": "A",
|
||||||
"values": []string{cfg.PublicIP},
|
"values": []string{cfg.PublicIP},
|
||||||
}
|
}
|
||||||
|
if cfg.CloudflareAutoTTL {
|
||||||
|
aRec["octodns"] = map[string]interface{}{
|
||||||
|
"cloudflare": map[string]interface{}{
|
||||||
|
"auto-ttl": true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
if cfg.PublicIPv6 == "" {
|
if cfg.PublicIPv6 == "" {
|
||||||
return aRec
|
return aRec
|
||||||
}
|
}
|
||||||
@@ -82,6 +89,13 @@ func buildRecord(cfg *Config) interface{} {
|
|||||||
"type": "AAAA",
|
"type": "AAAA",
|
||||||
"values": []string{cfg.PublicIPv6},
|
"values": []string{cfg.PublicIPv6},
|
||||||
}
|
}
|
||||||
|
if cfg.CloudflareAutoTTL {
|
||||||
|
aaaaRec["octodns"] = map[string]interface{}{
|
||||||
|
"cloudflare": map[string]interface{}{
|
||||||
|
"auto-ttl": true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
return []interface{}{aRec, aaaaRec}
|
return []interface{}{aRec, aaaaRec}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user