mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
NAMECHEAP: Add get zone functionality (#1207)
This commit is contained in:
@ -36,7 +36,7 @@ var features = providers.DocumentationNotes{
|
|||||||
providers.DocCreateDomains: providers.Cannot("Requires domain registered through their service"),
|
providers.DocCreateDomains: providers.Cannot("Requires domain registered through their service"),
|
||||||
providers.DocDualHost: providers.Cannot("Doesn't allow control of apex NS records"),
|
providers.DocDualHost: providers.Cannot("Doesn't allow control of apex NS records"),
|
||||||
providers.DocOfficiallySupported: providers.Cannot(),
|
providers.DocOfficiallySupported: providers.Cannot(),
|
||||||
providers.CanGetZones: providers.Unimplemented(),
|
providers.CanGetZones: providers.Can(),
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -112,10 +112,18 @@ func doWithRetry(f func() 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 (n *namecheapProvider) GetZoneRecords(domain string) (models.Records, error) {
|
func (n *namecheapProvider) GetZoneRecords(domain string) (models.Records, error) {
|
||||||
return nil, fmt.Errorf("not implemented")
|
sld, tld := splitDomain(domain)
|
||||||
// This enables the get-zones subcommand.
|
var records *nc.DomainDNSGetHostsResult
|
||||||
// Implement this by extracting the code from GetDomainCorrections into
|
var err error
|
||||||
// a single function. For most providers this should be relatively easy.
|
doWithRetry(func() error {
|
||||||
|
records, err = n.client.DomainsDNSGetHosts(sld, tld)
|
||||||
|
return err
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return toRecords(records, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDomainCorrections returns the corrections for the domain.
|
// GetDomainCorrections returns the corrections for the domain.
|
||||||
@ -219,6 +227,23 @@ func (n *namecheapProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mo
|
|||||||
return corrections, nil
|
return corrections, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toRecords(result *nc.DomainDNSGetHostsResult, origin string) ([]*models.RecordConfig, error) {
|
||||||
|
var records []*models.RecordConfig
|
||||||
|
for _, dnsHost := range result.Hosts {
|
||||||
|
record := models.RecordConfig{
|
||||||
|
Type: dnsHost.Type,
|
||||||
|
TTL: uint32(dnsHost.TTL),
|
||||||
|
MxPreference: uint16(dnsHost.MXPref),
|
||||||
|
Name: dnsHost.Name,
|
||||||
|
}
|
||||||
|
record.PopulateFromString(dnsHost.Type, dnsHost.Address, origin)
|
||||||
|
|
||||||
|
records = append(records, &record)
|
||||||
|
}
|
||||||
|
|
||||||
|
return records, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (n *namecheapProvider) generateRecords(dc *models.DomainConfig) error {
|
func (n *namecheapProvider) generateRecords(dc *models.DomainConfig) error {
|
||||||
|
|
||||||
var recs []nc.DomainDNSHost
|
var recs []nc.DomainDNSHost
|
||||||
|
Reference in New Issue
Block a user