ClouDNS: Get zone records implemented (#681)

* ClouDNS: #628 get-zones implemented

* ClouDNS: #491 convert to models.ToNameservers
This commit is contained in:
Tom Limoncelli 2020-03-05 16:21:42 -05:00 committed by GitHub
parent 947cc043df
commit 394b6e605f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,7 +49,7 @@ var features = providers.DocumentationNotes{
providers.CanUseCAA: providers.Can(), providers.CanUseCAA: providers.Can(),
providers.CanUseTLSA: providers.Can(), providers.CanUseTLSA: providers.Can(),
providers.CanUsePTR: providers.Unimplemented(), providers.CanUsePTR: providers.Unimplemented(),
providers.CanGetZones: providers.Unimplemented(), providers.CanGetZones: providers.Can(),
} }
func init() { func init() {
@ -61,7 +61,7 @@ func (c *api) GetNameservers(domain string) ([]*models.Nameserver, error) {
if len(c.nameserversNames) == 0 { if len(c.nameserversNames) == 0 {
c.fetchAvailableNameservers() c.fetchAvailableNameservers()
} }
return models.StringsToNameservers(c.nameserversNames), nil return models.ToNameservers(c.nameserversNames)
} }
// GetDomainCorrections returns the corrections for a domain. // GetDomainCorrections returns the corrections for a domain.
@ -83,15 +83,10 @@ func (c *api) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correctio
return nil, fmt.Errorf("'%s' not a zone in ClouDNS account", dc.Name) return nil, fmt.Errorf("'%s' not a zone in ClouDNS account", dc.Name)
} }
records, err := c.getRecords(domainID) existingRecords, err := c.GetZoneRecords(dc.Name)
if err != nil { if err != nil {
return nil, err return nil, err
} }
existingRecords := make([]*models.RecordConfig, len(records), len(records)+len(c.nameserversNames))
for i := range records {
existingRecords[i] = toRc(dc, &records[i])
}
// Normalize // Normalize
models.PostProcessRecords(existingRecords) models.PostProcessRecords(existingRecords)
@ -152,11 +147,16 @@ func (c *api) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correctio
} }
// 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 *api) GetZoneRecords(domain string) (models.Records, error) { func (c *api) GetZoneRecords(domain string) (models.Records, error) {
return nil, fmt.Errorf("not implemented") records, err := c.getRecords(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. }
existingRecords := make([]*models.RecordConfig, len(records))
for i := range records {
existingRecords[i] = toRc(domain, &records[i])
}
return existingRecords, nil
} }
// EnsureDomainExists returns an error if domain doesn't exist. // EnsureDomainExists returns an error if domain doesn't exist.
@ -171,7 +171,7 @@ func (c *api) EnsureDomainExists(domain string) error {
return c.createDomain(domain) return c.createDomain(domain)
} }
func toRc(dc *models.DomainConfig, r *domainRecord) *models.RecordConfig { func toRc(domain string, r *domainRecord) *models.RecordConfig {
ttl, _ := strconv.ParseUint(r.TTL, 10, 32) ttl, _ := strconv.ParseUint(r.TTL, 10, 32)
priority, _ := strconv.ParseUint(r.Priority, 10, 32) priority, _ := strconv.ParseUint(r.Priority, 10, 32)
@ -187,13 +187,13 @@ func toRc(dc *models.DomainConfig, r *domainRecord) *models.RecordConfig {
SrvPort: uint16(port), SrvPort: uint16(port),
Original: r, Original: r,
} }
rc.SetLabel(r.Host, dc.Name) rc.SetLabel(r.Host, domain)
switch rtype := r.Type; rtype { // #rtype_variations switch rtype := r.Type; rtype { // #rtype_variations
case "TXT": case "TXT":
rc.SetTargetTXT(r.Target) rc.SetTargetTXT(r.Target)
case "CNAME", "MX", "NS", "SRV", "ALIAS": case "CNAME", "MX", "NS", "SRV", "ALIAS":
rc.SetTarget(dnsutil.AddOrigin(r.Target+".", dc.Name)) rc.SetTarget(dnsutil.AddOrigin(r.Target+".", domain))
case "CAA": case "CAA":
caaFlag, _ := strconv.ParseUint(r.CaaFlag, 10, 32) caaFlag, _ := strconv.ParseUint(r.CaaFlag, 10, 32)
rc.CaaFlag = uint8(caaFlag) rc.CaaFlag = uint8(caaFlag)