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

(#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
2 changed files with 22 additions and 20 deletions

View File

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