Do get zones (#635)

* Implement GetZoneRecords for Digitalocean provider
* Clean fixme comment from digitalocean provider
This commit is contained in:
Juho Teperi 2020-02-19 20:11:49 +02:00 committed by GitHub
parent 05cedab5a7
commit ca99517ced
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 26 deletions

View file

@ -919,8 +919,8 @@
<td class="info"> <td class="info">
<i class="fa fa-circle-o text-info" aria-hidden="true"></i> <i class="fa fa-circle-o text-info" aria-hidden="true"></i>
</td> </td>
<td class="info"> <td class="success">
<i class="fa fa-circle-o text-info" aria-hidden="true"></i> <i class="fa fa-check text-success" aria-hidden="true"></i>
</td> </td>
<td class="info"> <td class="info">
<i class="fa fa-circle-o text-info" aria-hidden="true"></i> <i class="fa fa-circle-o text-info" aria-hidden="true"></i>

View file

@ -70,7 +70,7 @@ var features = providers.DocumentationNotes{
// ";" value with issue/issuewild records: // ";" value with issue/issuewild records:
// https://www.digitalocean.com/docs/networking/dns/how-to/create-caa-records/ // https://www.digitalocean.com/docs/networking/dns/how-to/create-caa-records/
providers.CanUseCAA: providers.Can(), providers.CanUseCAA: providers.Can(),
providers.CanGetZones: providers.Unimplemented(), providers.CanGetZones: providers.Can(),
} }
func init() { func init() {
@ -97,11 +97,22 @@ func (api *DoApi) GetNameservers(domain string) ([]*models.Nameserver, error) {
} }
// 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 *DoApi) GetZoneRecords(domain string) (models.Records, error) { func (api *DoApi) GetZoneRecords(domain string) (models.Records, error) {
return nil, fmt.Errorf("not implemented") records, err := getRecords(api, domain)
// This enables the get-zones subcommand. if err != nil {
// Implement this by extracting the code from GetDomainCorrections into return nil, err
// a single function. For most providers this should be relatively easy. }
var existingRecords []*models.RecordConfig
for i := range records {
r := toRc(domain, &records[i])
if r.Type == "SOA" {
continue
}
existingRecords = append(existingRecords, r)
}
return existingRecords, nil
} }
// GetDomainCorrections returns a list of corretions for the domain. // GetDomainCorrections returns a list of corretions for the domain.
@ -109,20 +120,11 @@ func (api *DoApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Corre
ctx := context.Background() ctx := context.Background()
dc.Punycode() dc.Punycode()
records, err := getRecords(api, dc.Name) existingRecords, err := api.GetZoneRecords(dc.Name)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var existingRecords []*models.RecordConfig
for i := range records {
r := toRc(dc, &records[i])
if r.Type == "SOA" {
continue
}
existingRecords = append(existingRecords, r)
}
// Normalize // Normalize
models.PostProcessRecords(existingRecords) models.PostProcessRecords(existingRecords)
@ -200,9 +202,9 @@ func getRecords(api *DoApi, name string) ([]godo.DomainRecord, error) {
return records, nil return records, nil
} }
func toRc(dc *models.DomainConfig, r *godo.DomainRecord) *models.RecordConfig { func toRc(domain string, r *godo.DomainRecord) *models.RecordConfig {
// This handles "@" etc. // This handles "@" etc.
name := dnsutil.AddOrigin(r.Name, dc.Name) name := dnsutil.AddOrigin(r.Name, domain)
target := r.Data target := r.Data
// Make target FQDN (#rtype_variations) // Make target FQDN (#rtype_variations)
@ -210,13 +212,11 @@ func toRc(dc *models.DomainConfig, r *godo.DomainRecord) *models.RecordConfig {
// If target is the domainname, e.g. cname foo.example.com -> example.com, // If target is the domainname, e.g. cname foo.example.com -> example.com,
// DO returns "@" on read even if fqdn was written. // DO returns "@" on read even if fqdn was written.
if target == "@" { if target == "@" {
target = dc.Name target = domain
} else if target == "." { } else if target == "." {
target = "" // don't append another dot to null records target = ""
} }
target = dnsutil.AddOrigin(target+".", dc.Name) target = target + "."
// FIXME(tlim): The AddOrigin should be a no-op.
// Test whether or not it is actually needed.
} }
t := &models.RecordConfig{ t := &models.RecordConfig{
@ -230,7 +230,7 @@ func toRc(dc *models.DomainConfig, r *godo.DomainRecord) *models.RecordConfig {
CaaTag: r.Tag, CaaTag: r.Tag,
CaaFlag: uint8(r.Flags), CaaFlag: uint8(r.Flags),
} }
t.SetLabelFromFQDN(name, dc.Name) t.SetLabelFromFQDN(name, domain)
t.SetTarget(target) t.SetTarget(target)
switch rtype := r.Type; rtype { switch rtype := r.Type; rtype {
case "TXT": case "TXT":