OVH: Fixed registrar ns correction (#486)

This commit is contained in:
Patrik Kernstock 2019-05-23 15:25:26 +02:00 committed by Tom Limoncelli
parent f9df8c744a
commit 7ed3adb2f1
2 changed files with 19 additions and 14 deletions

View file

@ -64,7 +64,7 @@ func (c *ovhProvider) GetNameservers(domain string) ([]*models.Nameserver, error
return nil, errors.Errorf("%s not listed in zones for ovh account", domain)
}
ns, err := c.fetchNS(domain)
ns, err := c.fetchRegistrarNS(domain)
if err != nil {
return nil, err
}
@ -177,27 +177,31 @@ func nativeToRecord(r *Record, origin string) *models.RecordConfig {
func (c *ovhProvider) GetRegistrarCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
ns, err := c.fetchRegistrarNS(dc.Name)
// get the actual in-use nameservers
actualNs, err := c.fetchRegistrarNS(dc.Name)
if err != nil {
return nil, err
}
sort.Strings(ns)
found := strings.Join(ns, ",")
desiredNs := []string{}
// get the actual used ones + the configured one through dnscontrol
expectedNs := []string{}
for _, d := range dc.Nameservers {
desiredNs = append(desiredNs, d.Name)
expectedNs = append(expectedNs, d.Name)
}
sort.Strings(desiredNs)
desired := strings.Join(desiredNs, ",")
if found != desired {
sort.Strings(actualNs)
actual := strings.Join(actualNs, ",")
sort.Strings(expectedNs)
expected := strings.Join(expectedNs, ",")
// check if we need to change something
if actual != expected {
return []*models.Correction{
{
Msg: fmt.Sprintf("Change Nameservers from '%s' to '%s'", found, desired),
Msg: fmt.Sprintf("Change Nameservers from '%s' to '%s'", actual, expected),
F: func() error {
err := c.updateNS(dc.Name, desiredNs)
err := c.updateNS(dc.Name, expectedNs)
if err != nil {
return err
}
@ -205,5 +209,6 @@ func (c *ovhProvider) GetRegistrarCorrections(dc *models.DomainConfig) ([]*model
}},
}, nil
}
return nil, nil
}

View file

@ -36,10 +36,10 @@ func (c *ovhProvider) fetchZones() error {
// Zone describes the attributes of a DNS zone.
type Zone struct {
LastUpdate string `json:"lastUpdate,omitempty"`
DNSSecSupported bool `json:"dnssecSupported"`
HasDNSAnycast bool `json:"hasDNSAnycast,omitempty"`
NameServers []string `json:"nameServers"`
DNSSecSupported bool `json:"dnssecSupported"`
LastUpdate string `json:"lastUpdate,omitempty"`
}
// get info about a zone.