From f5d6f8074d7d5b3368b7291e0886ecdb4df2ff3a Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Fri, 21 Feb 2020 13:48:55 -0500 Subject: [PATCH] BIND: Implement get-zones (#642) * BIND: implement get-zones * BIND: Implement ZoneLister --- providers/activedir/domains.go | 7 +++---- providers/bind/bindProvider.go | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/providers/activedir/domains.go b/providers/activedir/domains.go index 77e78dda6..a21ad32ed 100644 --- a/providers/activedir/domains.go +++ b/providers/activedir/domains.go @@ -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 } diff --git a/providers/bind/bindProvider.go b/providers/bind/bindProvider.go index 4a56d079a..ebf322aab 100644 --- a/providers/bind/bindProvider.go +++ b/providers/bind/bindProvider.go @@ -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