(#628) Add get-zones to the OVH provider (#666)

Commit 87ad01d added the very useful `get-zones` command, which
requires providers to implement a new method `GetZoneRecords`.
This changes make the OVH provider support this.
This commit is contained in:
Brice Figureau 2020-02-28 17:14:02 +01:00 committed by GitHub
parent 99cef24d8f
commit bdddd466bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 20 deletions

View file

@ -125,6 +125,7 @@
"app-key": "$OVH_APP_KEY",
"app-secret-key": "$OVH_APP_SECRET_KEY",
"consumer-key": "$OVH_CONSUMER_KEY",
"domain": "$OVH_DOMAIN"
"domain": "$OVH_DOMAIN",
"knownFailures": "49"
}
}

View file

@ -27,7 +27,7 @@ var features = providers.DocumentationNotes{
providers.DocCreateDomains: providers.Cannot("New domains require registration"),
providers.DocDualHost: providers.Can(),
providers.DocOfficiallySupported: providers.Cannot(),
providers.CanGetZones: providers.Unimplemented(),
providers.CanGetZones: providers.Can(),
}
func newOVH(m map[string]string, metadata json.RawMessage) (*ovhProvider, error) {
@ -81,34 +81,35 @@ func (e errNoExist) Error() string {
}
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
func (client *ovhProvider) GetZoneRecords(domain string) (models.Records, error) {
return nil, fmt.Errorf("not implemented")
// This enables the get-zones subcommand.
// Implement this by extracting the code from GetDomainCorrections into
// a single function. For most providers this should be relatively easy.
func (c *ovhProvider) GetZoneRecords(domain string) (models.Records, error) {
if !c.zones[domain] {
return nil, errNoExist{domain}
}
records, err := c.fetchRecords(domain)
if err != nil {
return nil, err
}
var actual models.Records
for _, r := range records {
rec := nativeToRecord(r, domain)
if rec != nil {
actual = append(actual, rec)
}
}
return actual, nil
}
func (c *ovhProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
dc.Punycode()
//dc.CombineMXs()
if !c.zones[dc.Name] {
return nil, errNoExist{dc.Name}
}
records, err := c.fetchRecords(dc.Name)
actual, err := c.GetZoneRecords(dc.Name)
if err != nil {
return nil, err
}
var actual []*models.RecordConfig
for _, r := range records {
rec := nativeToRecord(r, dc.Name)
if rec != nil {
actual = append(actual, rec)
}
}
// Normalize
models.PostProcessRecords(actual)