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:
@@ -28,7 +28,7 @@ var features = providers.DocumentationNotes{
|
||||
providers.DocCreateDomains: providers.Cannot("New domains require registration"),
|
||||
providers.DocDualHost: providers.Cannot("Apex NS records not editable"),
|
||||
providers.DocOfficiallySupported: providers.Can(),
|
||||
providers.CanGetZones: providers.Unimplemented(),
|
||||
providers.CanGetZones: providers.Can(),
|
||||
}
|
||||
|
||||
func newReg(conf map[string]string) (providers.Registrar, error) {
|
||||
|
@@ -20,24 +20,28 @@ var defaultNameservers = []*models.Nameserver{
|
||||
}
|
||||
|
||||
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
|
||||
func (client *NameCom) 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 (n *NameCom) GetZoneRecords(domain string) (models.Records, error) {
|
||||
records, err := n.getRecords(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
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.
|
||||
func (n *NameCom) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
|
||||
dc.Punycode()
|
||||
records, err := n.getRecords(dc.Name)
|
||||
|
||||
actual, err := n.GetZoneRecords(dc.Name)
|
||||
if err != nil {
|
||||
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 {
|
||||
if rec.Type == "ALIAS" {
|
||||
|
29
providers/namedotcom/zones.go
Normal file
29
providers/namedotcom/zones.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user