mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-09-20 06:46:19 +08:00
REFACTOR: .target should always be FQDN (#2421)
This commit is contained in:
parent
8b915a4760
commit
f80f94f94b
|
@ -1561,22 +1561,22 @@ func makeTests(t *testing.T) []*TestGroup {
|
|||
testgroup("AZURE_ALIAS_CNAME",
|
||||
requires(providers.CanUseAzureAlias),
|
||||
tc("create dependent CNAME records",
|
||||
cname("foo.cname", "google.com"),
|
||||
cname("quux.cname", "google2.com"),
|
||||
cname("foo.cname", "google.com."),
|
||||
cname("quux.cname", "google2.com."),
|
||||
),
|
||||
tc("ALIAS to CNAME record in same zone",
|
||||
cname("foo.cname", "google.com"),
|
||||
cname("quux.cname", "google2.com"),
|
||||
cname("foo.cname", "google.com."),
|
||||
cname("quux.cname", "google2.com."),
|
||||
azureAlias("bar.cname", "CNAME", "/subscriptions/**subscription-id**/resourceGroups/**resource-group**/providers/Microsoft.Network/dnszones/**current-domain-no-trailing**/CNAME/foo.cname"),
|
||||
),
|
||||
tc("change aliasCNAME",
|
||||
cname("foo.cname", "google.com"),
|
||||
cname("quux.cname", "google2.com"),
|
||||
cname("foo.cname", "google.com."),
|
||||
cname("quux.cname", "google2.com."),
|
||||
azureAlias("bar.cname", "CNAME", "/subscriptions/**subscription-id**/resourceGroups/**resource-group**/providers/Microsoft.Network/dnszones/**current-domain-no-trailing**/CNAME/quux.cname"),
|
||||
),
|
||||
tc("change backCNAME",
|
||||
cname("foo.cname", "google.com"),
|
||||
cname("quux.cname", "google2.com"),
|
||||
cname("foo.cname", "google.com."),
|
||||
cname("quux.cname", "google2.com."),
|
||||
azureAlias("bar.cname", "CNAME", "/subscriptions/**subscription-id**/resourceGroups/**resource-group**/providers/Microsoft.Network/dnszones/**current-domain-no-trailing**/CNAME/foo.cname"),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -566,14 +566,12 @@ func Downcase(recs []*RecordConfig) {
|
|||
r.Name = strings.ToLower(r.Name)
|
||||
r.NameFQDN = strings.ToLower(r.NameFQDN)
|
||||
switch r.Type { // #rtype_variations
|
||||
case "ANAME", "CNAME", "DS", "MX", "NS", "PTR", "NAPTR", "SRV", "TLSA", "AKAMAICDN":
|
||||
// These record types have a target that is case insensitive, so we downcase it.
|
||||
case "AKAMAICDN", "AAAA", "ANAME", "CNAME", "DS", "MX", "NS", "NAPTR", "PTR", "SRV", "TLSA":
|
||||
// Target is case insensitive. Downcase it.
|
||||
r.target = strings.ToLower(r.target)
|
||||
case "LOC":
|
||||
// Do nothing to affect case of letters.
|
||||
case "A", "AAAA", "ALIAS", "CAA", "IMPORT_TRANSFORM", "TXT", "SSHFP", "CF_REDIRECT", "CF_TEMP_REDIRECT", "CF_WORKER_ROUTE":
|
||||
// These record types have a target that is case sensitive, or is an IP address. We leave them alone.
|
||||
// Do nothing.
|
||||
// BUGFIX(tlim): isn't ALIAS in the wrong case statement?
|
||||
case "A", "ALIAS", "CAA", "CF_REDIRECT", "CF_TEMP_REDIRECT", "CF_WORKER_ROUTE", "IMPORT_TRANSFORM", "LOC", "SSHFP", "TXT":
|
||||
// Do nothing. (IP address or case sensitive target)
|
||||
case "SOA":
|
||||
if r.target != "DEFAULT_NOT_SET." {
|
||||
r.target = strings.ToLower(r.target) // .target stores the Ns
|
||||
|
@ -586,3 +584,25 @@ func Downcase(recs []*RecordConfig) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CanonicalizeTargets turns Targets into FQDNs
|
||||
func CanonicalizeTargets(recs []*RecordConfig, origin string) {
|
||||
for _, r := range recs {
|
||||
switch r.Type { // #rtype_variations
|
||||
case "AKAMAICDN", "ANAME", "CNAME", "DS", "MX", "NS", "NAPTR", "PTR", "SRV":
|
||||
// Target is a hostname that might be a shortname. Turn it into a FQDN.
|
||||
r.target = dnsutil.AddOrigin(r.target, origin)
|
||||
case "A", "ALIAS", "CAA", "CF_REDIRECT", "CF_TEMP_REDIRECT", "CF_WORKER_ROUTE", "IMPORT_TRANSFORM", "LOC", "SSHFP", "TLSA", "TXT":
|
||||
// Do nothing.
|
||||
case "SOA":
|
||||
if r.target != "DEFAULT_NOT_SET." {
|
||||
r.target = dnsutil.AddOrigin(r.target, origin) // .target stores the Ns
|
||||
}
|
||||
if r.SoaMbox != "DEFAULT_NOT_SET." {
|
||||
r.SoaMbox = dnsutil.AddOrigin(r.SoaMbox, origin)
|
||||
}
|
||||
default:
|
||||
// TODO: we'd like to panic here, but custom record types complicate things.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ func CorrectZoneRecords(driver models.DNSProvider, dc *models.DomainConfig) ([]*
|
|||
|
||||
// downcase
|
||||
models.Downcase(existingRecords)
|
||||
models.Downcase(dc.Records)
|
||||
models.CanonicalizeTargets(existingRecords, dc.Name)
|
||||
models.CanonicalizeTargets(dc.Records, dc.Name)
|
||||
|
||||
// Copy dc so that any corrections code that wants to
|
||||
// modify the records may. For example, if the provider only
|
||||
|
|
Loading…
Reference in a new issue