mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-12 10:27:57 +08:00
Do get zones (#635)
* Implement GetZoneRecords for Digitalocean provider * Clean fixme comment from digitalocean provider
This commit is contained in:
parent
05cedab5a7
commit
ca99517ced
2 changed files with 26 additions and 26 deletions
|
@ -919,8 +919,8 @@
|
|||
<td class="info">
|
||||
<i class="fa fa-circle-o text-info" aria-hidden="true"></i>
|
||||
</td>
|
||||
<td class="info">
|
||||
<i class="fa fa-circle-o text-info" aria-hidden="true"></i>
|
||||
<td class="success">
|
||||
<i class="fa fa-check text-success" aria-hidden="true"></i>
|
||||
</td>
|
||||
<td class="info">
|
||||
<i class="fa fa-circle-o text-info" aria-hidden="true"></i>
|
||||
|
|
|
@ -70,7 +70,7 @@ var features = providers.DocumentationNotes{
|
|||
// ";" value with issue/issuewild records:
|
||||
// https://www.digitalocean.com/docs/networking/dns/how-to/create-caa-records/
|
||||
providers.CanUseCAA: providers.Can(),
|
||||
providers.CanGetZones: providers.Unimplemented(),
|
||||
providers.CanGetZones: providers.Can(),
|
||||
}
|
||||
|
||||
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.
|
||||
func (client *DoApi) 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 (api *DoApi) GetZoneRecords(domain string) (models.Records, error) {
|
||||
records, err := getRecords(api, domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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.
|
||||
|
@ -109,20 +120,11 @@ func (api *DoApi) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Corre
|
|||
ctx := context.Background()
|
||||
dc.Punycode()
|
||||
|
||||
records, err := getRecords(api, dc.Name)
|
||||
existingRecords, err := api.GetZoneRecords(dc.Name)
|
||||
if err != nil {
|
||||
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
|
||||
models.PostProcessRecords(existingRecords)
|
||||
|
||||
|
@ -200,9 +202,9 @@ func getRecords(api *DoApi, name string) ([]godo.DomainRecord, error) {
|
|||
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.
|
||||
name := dnsutil.AddOrigin(r.Name, dc.Name)
|
||||
name := dnsutil.AddOrigin(r.Name, domain)
|
||||
|
||||
target := r.Data
|
||||
// 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,
|
||||
// DO returns "@" on read even if fqdn was written.
|
||||
if target == "@" {
|
||||
target = dc.Name
|
||||
target = domain
|
||||
} else if target == "." {
|
||||
target = "" // don't append another dot to null records
|
||||
target = ""
|
||||
}
|
||||
target = dnsutil.AddOrigin(target+".", dc.Name)
|
||||
// FIXME(tlim): The AddOrigin should be a no-op.
|
||||
// Test whether or not it is actually needed.
|
||||
target = target + "."
|
||||
}
|
||||
|
||||
t := &models.RecordConfig{
|
||||
|
@ -230,7 +230,7 @@ func toRc(dc *models.DomainConfig, r *godo.DomainRecord) *models.RecordConfig {
|
|||
CaaTag: r.Tag,
|
||||
CaaFlag: uint8(r.Flags),
|
||||
}
|
||||
t.SetLabelFromFQDN(name, dc.Name)
|
||||
t.SetLabelFromFQDN(name, domain)
|
||||
t.SetTarget(target)
|
||||
switch rtype := r.Type; rtype {
|
||||
case "TXT":
|
||||
|
|
Loading…
Reference in a new issue