Allow catalog-only zones without file= in --bind-conf mode
Zones without a file= property (e.g. ddns zones) are included in catalog zone output for secondaries but skipped in domains.conf. Previously --bind-conf required every zone to have file= set.
This commit is contained in:
21
bindconf.go
21
bindconf.go
@@ -23,6 +23,10 @@ func generateBindConf(entries []ZoneEntry) string {
|
||||
b.WriteString("#\n")
|
||||
|
||||
for _, entry := range sorted {
|
||||
if entry.ZoneFile == "" {
|
||||
continue // catalog-only zone, no BIND config needed
|
||||
}
|
||||
|
||||
// Strip trailing dot for BIND zone name
|
||||
zoneName := strings.TrimSuffix(entry.Zone, ".")
|
||||
|
||||
@@ -40,22 +44,9 @@ func generateBindConf(entries []ZoneEntry) string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// validateBindConf checks that every zone entry has a non-empty ZoneFile.
|
||||
func validateBindConf(entries []ZoneEntry) error {
|
||||
for _, entry := range entries {
|
||||
if entry.ZoneFile == "" {
|
||||
return fmt.Errorf("%s:%d: zone %s missing file= property (required for --bind-conf)",
|
||||
entry.ZonesFile, entry.Line, entry.Zone)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeBindConf validates entries and writes the BIND config to path.
|
||||
// writeBindConf writes the BIND config to path.
|
||||
// Zones without a ZoneFile are skipped (catalog-only zones).
|
||||
func writeBindConf(path string, entries []ZoneEntry) error {
|
||||
if err := validateBindConf(entries); err != nil {
|
||||
return err
|
||||
}
|
||||
content := generateBindConf(entries)
|
||||
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
|
||||
return fmt.Errorf("writing bind config %s: %w", path, err)
|
||||
|
||||
Reference in New Issue
Block a user