From e10f169056b62c23aad1636ce13aa39a0b2edd69 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Tue, 7 Mar 2023 09:13:36 -0800 Subject: [PATCH] wip! --- providers/hostingde/hostingdeProvider.go | 15 +++++++++++++-- providers/inwx/inwxProvider.go | 7 ++++++- providers/linode/linodeProvider.go | 15 +++++++++++++++ providers/msdns/corrections.go | 2 +- providers/msdns/msdnsProvider.go | 2 +- providers/providers.go | 8 ++++++++ 6 files changed, 44 insertions(+), 5 deletions(-) diff --git a/providers/hostingde/hostingdeProvider.go b/providers/hostingde/hostingdeProvider.go index f39afd478..8cf0fdfbf 100644 --- a/providers/hostingde/hostingdeProvider.go +++ b/providers/hostingde/hostingdeProvider.go @@ -122,8 +122,6 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m return nil, err } - zoneChanged := false - // TTL must be between (inclusive) 1m and 1y (in fact, a little bit more) for _, r := range dc.Records { if r.TTL < 60 { @@ -140,6 +138,19 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m records := hp.APIRecordsToStandardRecordsModel(dc.Name, zone.Records) + return hp.GetZoneRecordsCorrections(dc, records) +} + +func (hp *hostingdeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, records models.Records) ([]*models.Correction, error) { + var err error + + zoneChanged := false + + zone, err := hp.getZone(dc.Name) + if err != nil { + return nil, err + } + var create, del, mod diff.Changeset if !diff2.EnableDiff2 { _, create, del, mod, err = diff.New(dc).IncrementalDiff(records) diff --git a/providers/inwx/inwxProvider.go b/providers/inwx/inwxProvider.go index 265e1132f..513e06957 100644 --- a/providers/inwx/inwxProvider.go +++ b/providers/inwx/inwxProvider.go @@ -237,7 +237,12 @@ func (api *inwxAPI) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Cor models.PostProcessRecords(foundRecords) txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records - err = checkRecords(dc.Records) + return api.GetZoneRecordsCorrections(dc, foundRecords) +} + +func (api *inwxAPI) GetZoneRecordsCorrections(dc *models.DomainConfig, foundRecords models.Records) ([]*models.Correction, error) { + + err := checkRecords(dc.Records) if err != nil { return nil, err } diff --git a/providers/linode/linodeProvider.go b/providers/linode/linodeProvider.go index 3f4239ea6..d83dc8a94 100644 --- a/providers/linode/linodeProvider.go +++ b/providers/linode/linodeProvider.go @@ -148,6 +148,10 @@ func (api *linodeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod // Normalize models.PostProcessRecords(existingRecords) + return api.GetZoneRecordsCorrections(dc, existingRecords) +} + +func (api *linodeProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) { // Linode doesn't allow selecting an arbitrary TTL, only a set of predefined values // We need to make sure we don't change it every time if it is as close as it's going to get // By experimentation, Linode always rounds up. 300 -> 300, 301 -> 3600. @@ -156,8 +160,19 @@ func (api *linodeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod record.TTL = fixTTL(record.TTL) } + if api.domainIndex == nil { + if err := api.fetchDomainList(); err != nil { + return nil, err + } + } + domainID, ok := api.domainIndex[dc.Name] + if !ok { + return nil, fmt.Errorf("'%s' not a zone in Linode account", dc.Name) + } + var corrections []*models.Correction var create, del, modify diff.Changeset + var err error if !diff2.EnableDiff2 { differ := diff.New(dc) _, create, del, modify, err = differ.IncrementalDiff(existingRecords) diff --git a/providers/msdns/corrections.go b/providers/msdns/corrections.go index 56678a089..5b2b55f28 100644 --- a/providers/msdns/corrections.go +++ b/providers/msdns/corrections.go @@ -10,7 +10,7 @@ import ( ) // GetDomainCorrections gets existing records, diffs them against existing, and returns corrections. -func (client *msdnsProvider) GenerateDomainCorrections(dc *models.DomainConfig, foundRecords models.Records) ([]*models.Correction, error) { +func (client *msdnsProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, foundRecords models.Records) ([]*models.Correction, error) { // Normalize models.PostProcessRecords(foundRecords) diff --git a/providers/msdns/msdnsProvider.go b/providers/msdns/msdnsProvider.go index a3b60252b..a2ade234d 100644 --- a/providers/msdns/msdnsProvider.go +++ b/providers/msdns/msdnsProvider.go @@ -91,7 +91,7 @@ func (client *msdnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m clean := PrepFoundRecords(existing) PrepDesiredRecords(dc) - return client.GenerateDomainCorrections(dc, clean) + return client.GetZoneRecordsCorrections(dc, clean) } // GetZoneRecords gathers the DNS records and converts them to diff --git a/providers/providers.go b/providers/providers.go index eaf11d5fe..7dcfe6728 100644 --- a/providers/providers.go +++ b/providers/providers.go @@ -164,6 +164,14 @@ func (n None) GetZoneRecords(domain string) (models.Records, error) { // a single function. For most providers this should be relatively easy. } +// GetZoneRecordsCorrections gets the records of a zone and returns them in RecordConfig format. +func (n None) GetZoneRecordsCorrections(dc *models.DomainConfig, records models.Records) ([]*models.Correction, 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. +} + // GetDomainCorrections returns corrections to update a domain. func (n None) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Correction, error) { return nil, nil