From 263c6b72903b5df614a629d3c1f65d7479a6a321 Mon Sep 17 00:00:00 2001 From: Norman <85173861+norman-zon@users.noreply.github.com> Date: Wed, 19 Jan 2022 19:58:21 +0100 Subject: [PATCH] NS1: Enable get-zones (#1373) Refactor code to get zones from NS1 API into GetZonesRecords function to enable get-zones --- docs/_includes/matrix.html | 45 +++--------------------------------- providers/ns1/ns1Provider.go | 37 +++++++++++++++++------------ 2 files changed, 25 insertions(+), 57 deletions(-) diff --git a/docs/_includes/matrix.html b/docs/_includes/matrix.html index 93e8537c9..9d74566f7 100644 --- a/docs/_includes/matrix.html +++ b/docs/_includes/matrix.html @@ -1408,47 +1408,6 @@ - - AKAMAICDN - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - dual host @@ -1867,7 +1826,9 @@ - + + + diff --git a/providers/ns1/ns1Provider.go b/providers/ns1/ns1Provider.go index 73552d2e7..0fe37bedf 100644 --- a/providers/ns1/ns1Provider.go +++ b/providers/ns1/ns1Provider.go @@ -21,6 +21,7 @@ var docNotes = providers.DocumentationNotes{ providers.CanUsePTR: providers.Can(), providers.DocCreateDomains: providers.Can(), providers.DocDualHost: providers.Can(), + providers.CanGetZones: providers.Can(), providers.DocOfficiallySupported: providers.Cannot(), } @@ -68,36 +69,42 @@ func (n *nsone) GetNameservers(domain string) ([]*models.Nameserver, error) { // GetZoneRecords gets the records of a zone and returns them in RecordConfig format. func (n *nsone) 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 *nsone) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) { - dc.Punycode() - //dc.CombineMXs() - z, _, err := n.Zones.Get(dc.Name) + z, _, err := n.Zones.Get(domain) if err != nil { return nil, err } found := models.Records{} for _, r := range z.Records { - zrs, err := convert(r, dc.Name) + zrs, err := convert(r, domain) if err != nil { return nil, err } found = append(found, zrs...) } - foundGrouped := found.GroupedByKey() + return found, nil +} + +func (n *nsone) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) { + dc.Punycode() + //dc.CombineMXs() + + domain := dc.Name + + // Get existing records + existingRecords, err := n.GetZoneRecords(domain) + if err != nil { + return nil, err + } + + existingGrouped := existingRecords.GroupedByKey() desiredGrouped := dc.Records.GroupedByKey() // Normalize - models.PostProcessRecords(found) + models.PostProcessRecords(existingRecords) differ := diff.New(dc) - changedGroups, err := differ.ChangedGroups(found) + changedGroups, err := differ.ChangedGroups(existingRecords) if err != nil { return nil, err } @@ -107,7 +114,7 @@ func (n *nsone) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correct key := k desc := strings.Join(descs, "\n") - _, current := foundGrouped[k] + _, current := existingGrouped[k] recs, wanted := desiredGrouped[k] if wanted && !current { // pure addition