1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

get-zones: generate R53_ALIAS right (#721)

* get-zones: generate R53_ALIAS right
* R53_ALIAS.md: Examples should use ' not "
* Handle TTLs
This commit is contained in:
Tom Limoncelli
2020-04-20 11:48:34 -04:00
committed by GitHub
parent 02e6a49bb8
commit 22b9afee3b
3 changed files with 98 additions and 9 deletions

View File

@ -235,7 +235,7 @@ func GetZone(args GetZoneArgs) error {
}
default:
return fmt.Errorf("format %q unknown", args.OutputFile)
return fmt.Errorf("format %q unknown", args.OutputFormat)
}
}
return nil
@ -245,9 +245,11 @@ func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) str
target := rec.GetTargetCombined()
ttl := uint32(0)
ttlop := ""
if rec.TTL != defaultTTL && rec.TTL != 0 {
ttlop = fmt.Sprintf(", TTL(%d)", rec.TTL)
ttl = rec.TTL
ttlop = fmt.Sprintf(", TTL(%d)", ttl)
}
switch rec.Type { // #rtype_variations
@ -277,6 +279,8 @@ func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) str
return fmt.Sprintf("NAMESERVER('%s')", target)
}
target = "'" + target + "'"
case "R53_ALIAS":
return makeR53alias(rec, ttl)
default:
target = "'" + target + "'"
}
@ -295,3 +299,18 @@ func makeCaa(rec *models.RecordConfig, ttlop string) string {
// TODO(tlim): Generate a CAA_BUILDER() instead?
}
func makeR53alias(rec *models.RecordConfig, ttl uint32) string {
items := []string{
"'" + rec.Name + "'",
"'" + rec.R53Alias["type"] + "'",
"'" + rec.GetTargetField() + "'",
}
if z, ok := rec.R53Alias["zone_id"]; ok {
items = append(items, "R53_ZONE('"+z+"')")
}
if ttl != 0 {
items = append(items, fmt.Sprintf("TTL(%d)", ttl))
}
return rec.Type + "(" + strings.Join(items, ", ") + ")"
}