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

NAMEDOTCOM: Implement get-zones (#645)

* NAMEDOTCOM: Implement get-zones
This commit is contained in:
Tom Limoncelli
2020-02-21 15:03:27 -05:00
committed by GitHub
parent 3c507d6b77
commit b360ddd1e9
3 changed files with 44 additions and 11 deletions

View File

@@ -28,7 +28,7 @@ var features = providers.DocumentationNotes{
providers.DocCreateDomains: providers.Cannot("New domains require registration"), providers.DocCreateDomains: providers.Cannot("New domains require registration"),
providers.DocDualHost: providers.Cannot("Apex NS records not editable"), providers.DocDualHost: providers.Cannot("Apex NS records not editable"),
providers.DocOfficiallySupported: providers.Can(), providers.DocOfficiallySupported: providers.Can(),
providers.CanGetZones: providers.Unimplemented(), providers.CanGetZones: providers.Can(),
} }
func newReg(conf map[string]string) (providers.Registrar, error) { func newReg(conf map[string]string) (providers.Registrar, error) {

View File

@@ -20,24 +20,28 @@ var defaultNameservers = []*models.Nameserver{
} }
// 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 *NameCom) GetZoneRecords(domain string) (models.Records, error) { func (n *NameCom) GetZoneRecords(domain string) (models.Records, error) {
return nil, fmt.Errorf("not implemented") records, err := n.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. }
actual := make([]*models.RecordConfig, len(records))
for i, r := range records {
actual[i] = toRecord(r, domain)
}
return actual, nil
} }
// GetDomainCorrections gathers correctios that would bring n to match dc. // GetDomainCorrections gathers correctios that would bring n to match dc.
func (n *NameCom) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) { func (n *NameCom) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
dc.Punycode() dc.Punycode()
records, err := n.getRecords(dc.Name)
actual, err := n.GetZoneRecords(dc.Name)
if err != nil { if err != nil {
return nil, err return nil, err
} }
actual := make([]*models.RecordConfig, len(records))
for i, r := range records {
actual[i] = toRecord(r, dc.Name)
}
for _, rec := range dc.Records { for _, rec := range dc.Records {
if rec.Type == "ALIAS" { if rec.Type == "ALIAS" {

View File

@@ -0,0 +1,29 @@
package namedotcom
import (
"github.com/namedotcom/go/namecom"
)
// ListZones returns all the zones in an account
func (c *NameCom) ListZones() ([]string, error) {
var names []string
var page int32
for true {
n, err := c.client.ListDomains(&namecom.ListDomainsRequest{Page: page})
if err != nil {
return nil, err
}
page = n.NextPage
for _, j := range n.Domains {
names = append(names, j.DomainName)
}
if page == 0 {
break
}
}
return names, nil
}