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

BIND: Implement get-zones (#642)

* BIND: implement get-zones
* BIND: Implement ZoneLister
This commit is contained in:
Tom Limoncelli
2020-02-21 13:48:55 -05:00
committed by GitHub
parent d221471e38
commit f5d6f8074d
2 changed files with 22 additions and 5 deletions

View File

@ -38,11 +38,10 @@ var supportedTypes = map[string]bool{
}
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
func (client *adProvider) GetZoneRecords(domain string) (models.Records, error) {
// Read foundRecords:
foundRecords, err := c.getExistingRecords(dc.Name)
func (c *adProvider) GetZoneRecords(domain string) (models.Records, error) {
foundRecords, err := c.getExistingRecords(domain)
if err != nil {
return nil, fmt.Errorf("c.getExistingRecords(%q) failed: %v", dc.Name, err)
return nil, fmt.Errorf("c.getExistingRecords(%q) failed: %v", domain, err)
}
return foundRecords, nil
}

View File

@ -130,10 +130,28 @@ func (c *Bind) GetNameservers(string) ([]*models.Nameserver, error) {
return c.nameservers, nil
}
// ListZones returns all the zones in an account
func (c *Bind) ListZones() ([]string, error) {
if _, err := os.Stat(c.directory); os.IsNotExist(err) {
return nil, fmt.Errorf("BIND directory %q does not exist!\n", c.directory)
}
filenames, err := filepath.Glob(filepath.Join(c.directory, "*.zone"))
if err != nil {
return nil, err
}
var zones []string
for _, n := range filenames {
_, file := filepath.Split(n)
zones = append(zones, strings.TrimSuffix(file, ".zone"))
}
return zones, nil
}
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
func (c *Bind) GetZoneRecords(domain string) (models.Records, error) {
// Default SOA record. If we see one in the zone, this will be replaced.
// Default SOA record. If we see one in the zone, this will be replaced.
soaRec := makeDefaultSOA(c.DefaultSoa, domain)
foundRecords := models.Records{}
var oldSerial, newSerial uint32