Eliminate models.StringsToNameservers() (#1486)

* Eliminate StringsToNameservers()

* update comments
This commit is contained in:
Tom Limoncelli 2022-04-24 09:08:40 -04:00 committed by GitHub
parent e2536ad406
commit 41d994bab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 17 deletions

View file

@ -330,7 +330,8 @@ func TestDualProviders(t *testing.T) {
run()
// add bogus nameservers
dc.Records = []*models.RecordConfig{}
dc.Nameservers = append(dc.Nameservers, models.StringsToNameservers([]string{"ns1.example.com", "ns2.example.com"})...)
nslist, _ := models.ToNameservers([]string{"ns1.example.com", "ns2.example.com"})
dc.Nameservers = append(dc.Nameservers, nslist...)
nameservers.AddNSRecords(dc)
t.Log("Adding nameservers from another provider")
run()

View file

@ -43,32 +43,23 @@ type DNSProviderConfig struct {
Metadata json.RawMessage `json:"meta,omitempty"`
}
// FIXME(tal): In hindsight, the Nameserver struct is overkill. We
// could have just used []string. Now every provider calls StringsToNameservers
// and ever user calls StringsToNameservers. We should refactor this
// some day. https://github.com/StackExchange/dnscontrol/issues/577
// Nameserver describes a nameserver.
type Nameserver struct {
Name string `json:"name"` // Normalized to a FQDN with NO trailing "."
// NB(tlim): DomainConfig.Nameservers are stored WITH a trailing "." (Sorry!)
}
// FIXME(tal): In hindsight the Nameserver struct is overkill. We
// could have just used string. Currently there are very few places
// that refer to the .Name field directly. All new code should use
// ToNameservers/ToNameserversStripTD and NameserversToStrings to make
// future refactoring easier. See
// https://github.com/StackExchange/dnscontrol/issues/577
func (n *Nameserver) String() string {
return n.Name
}
// StringsToNameservers constructs a list of *Nameserver structs using a list of FQDNs.
// Deprecated. Please use ToNameservers, or maybe ToNameserversStripTD instead.
// See https://github.com/StackExchange/dnscontrol/issues/491
func StringsToNameservers(nss []string) []*Nameserver {
nservers := []*Nameserver{}
for _, ns := range nss {
nservers = append(nservers, &Nameserver{Name: ns})
}
return nservers
}
// ToNameservers turns a list of strings into a list of Nameservers.
// It is an error if any string has a trailing dot. Either remove the
// trailing dot before you call this or (much preferred) use ToNameserversStripTD.