From 9b3c2857767b1f245fb4d886cfa38f987d328e1f Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Tue, 20 Feb 2024 17:26:16 -0500 Subject: [PATCH 01/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables --- provider/dnsimple/dnsimple.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/provider/dnsimple/dnsimple.go b/provider/dnsimple/dnsimple.go index ee805695a..ae0ab63a8 100644 --- a/provider/dnsimple/dnsimple.go +++ b/provider/dnsimple/dnsimple.go @@ -100,6 +100,7 @@ const ( // NewDnsimpleProvider initializes a new Dnsimple based provider func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (provider.Provider, error) { oauthToken := os.Getenv("DNSIMPLE_OAUTH") + dnsimpleAccountId := os.Getenv("DNSIMPLE_ACCOUNT_ID") if len(oauthToken) == 0 { return nil, fmt.Errorf("no dnsimple oauth token provided") } @@ -122,7 +123,11 @@ func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provid if err != nil { return nil, err } - provider.accountID = int64ToString(whoamiResponse.Data.Account.ID) + if dnsimpleAccountId == "" { + provider.accountID = int64ToString(whoamiResponse.Data.Account.ID) + } else { + provider.accountID = dnsimpleAccountId + } return provider, nil } @@ -136,9 +141,29 @@ func (p *dnsimpleProvider) GetAccountID(ctx context.Context) (accountID string, return int64ToString(whoamiResponse.Data.Account.ID), nil } +func ZonesFromZoneString(zonestring string) (map[string]dnsimple.Zone) { + zones := make(map[string]dnsimple.Zone) + zoneNames := strings.Split(zonestring, ",") + for indexId, zoneName := range zoneNames { + zone := dnsimple.Zone{Name: zoneName, ID: int64(indexId)} + zones[int64ToString(zone.ID)] = zone + } + return zones +} + // Returns a list of filtered Zones func (p *dnsimpleProvider) Zones(ctx context.Context) (map[string]dnsimple.Zone, error) { zones := make(map[string]dnsimple.Zone) + + // If the DNSIMPLE_ZONES environment variable is specified, generate a list of Zones from it + // This is useful for when the DNSIMPLE_OAUTH environment variable is a User API token and + // not an Account API token as the User API token will not have permissions to list Zones + // belong to another account which the User has access permissions for. + envZonesStr := os.Getenv("DNSIMPLE_ZONES") + if envZonesStr != "" { + return ZonesFromZoneString(envZonesStr), nil + } + page := 1 listOptions := &dnsimple.ZoneListOptions{} for { From ea2d25948531da2e9c5a8c6af19016e4e047f247 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Mon, 26 Feb 2024 10:48:16 -0500 Subject: [PATCH 02/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Update documentation for these new environment variables --- docs/tutorials/dnsimple.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/tutorials/dnsimple.md b/docs/tutorials/dnsimple.md index 31c296649..980682c35 100644 --- a/docs/tutorials/dnsimple.md +++ b/docs/tutorials/dnsimple.md @@ -5,11 +5,15 @@ This tutorial describes how to setup ExternalDNS for usage with DNSimple. Make sure to use **>=0.4.6** version of ExternalDNS for this tutorial. -## Created a DNSimple API Access Token +## Create a DNSimple API Access Token A DNSimple API access token can be acquired by following the [provided documentation from DNSimple](https://support.dnsimple.com/articles/api-access-token/) -The environment variable `DNSIMPLE_OAUTH` must be set to the API token generated for to run ExternalDNS with DNSimple. +The environment variable `DNSIMPLE_OAUTH` must be set to the generated API token to run ExternalDNS with DNSimple. + +If the generated DNSimple API access token is a _User token_, as opposed to an _Account token_, the following environment variables must also be set: + - `DNSIMPLE_ACCOUNT_ID`: Set this to the account ID which the domains to be managed by ExternalDNS belong to (eg. `1001234`). + - `DNSIMPLE_ZONES`: Set this to a comma separated list of DNS zones to be managed by ExternalDNS (eg. `mydomain.com,example.com`). ## Deploy ExternalDNS @@ -44,6 +48,10 @@ spec: env: - name: DNSIMPLE_OAUTH value: "YOUR_DNSIMPLE_API_KEY" + - name: DNSIMPLE_ACCOUNT_ID + value: "SET THIS IF USING A DNSIMPLE USER ACCESS TOKEN" + - name: DNSIMPLE_ZONES + value: "SET THIS IF USING A DNSIMPLE USER ACCESS TOKEN" ``` ### Manifest (for clusters with RBAC enabled) @@ -109,6 +117,10 @@ spec: env: - name: DNSIMPLE_OAUTH value: "YOUR_DNSIMPLE_API_KEY" + - name: DNSIMPLE_ACCOUNT_ID + value: "SET THIS IF USING A DNSIMPLE USER ACCESS TOKEN" + - name: DNSIMPLE_ZONES + value: "SET THIS IF USING A DNSIMPLE USER ACCESS TOKEN" ``` From 26694e4b2669e8f7baa29366a0455c362ae660c1 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Mon, 26 Feb 2024 11:24:08 -0500 Subject: [PATCH 03/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Update tests to check that the Zones function returns the correct DNS zones when the DNSIMPLE_ZONES environment variable is set --- provider/dnsimple/dnsimple_test.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/provider/dnsimple/dnsimple_test.go b/provider/dnsimple/dnsimple_test.go index f89e08f77..ba5186c47 100644 --- a/provider/dnsimple/dnsimple_test.go +++ b/provider/dnsimple/dnsimple_test.go @@ -33,9 +33,10 @@ import ( ) var ( - mockProvider dnsimpleProvider - dnsimpleListRecordsResponse dnsimple.ZoneRecordsResponse - dnsimpleListZonesResponse dnsimple.ZonesResponse + mockProvider dnsimpleProvider + dnsimpleListRecordsResponse dnsimple.ZoneRecordsResponse + dnsimpleListZonesResponse dnsimple.ZonesResponse + dnsimpleListZonesFromEnvResponse dnsimple.ZonesResponse ) func TestDnsimpleServices(t *testing.T) { @@ -55,6 +56,16 @@ func TestDnsimpleServices(t *testing.T) { Response: dnsimple.Response{Pagination: &dnsimple.Pagination{}}, Data: zones, } + firstEnvDefinedZone := dnsimple.Zone{ + ID: 0, + AccountID: 12345, + Name: "example-from-env.com", + } + envDefinedZones := []dnsimple.Zone{firstEnvDefinedZone} + dnsimpleListZonesFromEnvResponse = dnsimple.ZonesResponse{ + Response: dnsimple.Response{Pagination: &dnsimple.Pagination{}}, + Data: envDefinedZones, + } firstRecord := dnsimple.ZoneRecord{ ID: 2, ZoneID: "example.com", @@ -151,6 +162,15 @@ func testDnsimpleProviderZones(t *testing.T) { mockProvider.accountID = "2" _, err = mockProvider.Zones(ctx) assert.NotNil(t, err) + + mockProvider.accountID = "3" + os.Setenv("DNSIMPLE_ZONES", "example-from-env.com") + result, err = mockProvider.Zones(ctx) + assert.Nil(t, err) + validateDnsimpleZones(t, result, dnsimpleListZonesFromEnvResponse.Data) + + mockProvider.accountID = "2" + os.Unsetenv("DNSIMPLE_ZONES") } func testDnsimpleProviderRecords(t *testing.T) { From d0c121b97cb7da27e07404ef16e04ca776d23549 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Mon, 26 Feb 2024 11:37:56 -0500 Subject: [PATCH 04/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Update tests to check that the dnsimpleSuitableZone function works properly when the DNSIMPLE_ZONES environment variable is set --- provider/dnsimple/dnsimple_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/provider/dnsimple/dnsimple_test.go b/provider/dnsimple/dnsimple_test.go index ba5186c47..56874f411 100644 --- a/provider/dnsimple/dnsimple_test.go +++ b/provider/dnsimple/dnsimple_test.go @@ -227,6 +227,17 @@ func testDnsimpleSuitableZone(t *testing.T) { zone := dnsimpleSuitableZone("example-beta.example.com", zones) assert.Equal(t, zone.Name, "example.com") + + os.Setenv("DNSIMPLE_ZONES", "environment-example.com,example.environment-example.com") + mockProvider.accountID = "3" + zones, err = mockProvider.Zones(ctx) + assert.Nil(t, err) + + zone = dnsimpleSuitableZone("hello.example.environment-example.com", zones) + assert.Equal(t, zone.Name, "example.environment-example.com") + + os.Unsetenv("DNSIMPLE_ZONES") + mockProvider.accountID = "1" } func TestNewDnsimpleProvider(t *testing.T) { From d475eb65576291ec9b1e35bec0a3e5c4dd198914 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Mon, 26 Feb 2024 11:54:52 -0500 Subject: [PATCH 05/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Small refactoring to NewDnsimpleProvider function to improve its testability --- provider/dnsimple/dnsimple.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/provider/dnsimple/dnsimple.go b/provider/dnsimple/dnsimple.go index ae0ab63a8..80c146d13 100644 --- a/provider/dnsimple/dnsimple.go +++ b/provider/dnsimple/dnsimple.go @@ -99,6 +99,11 @@ const ( // NewDnsimpleProvider initializes a new Dnsimple based provider func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (provider.Provider, error) { + return BuildDnsimpleProvider(domainFilter, zoneIDFilter, dryRun, false) +} + +// Create a new Dnsimple based provider but return a *dnsimpleProvider and allow for the call to provider.identity.Whoami to be bypassed - both for testing purposes +func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool, skipWhoami bool) (*dnsimpleProvider, error) { oauthToken := os.Getenv("DNSIMPLE_OAUTH") dnsimpleAccountId := os.Getenv("DNSIMPLE_ACCOUNT_ID") if len(oauthToken) == 0 { @@ -119,10 +124,15 @@ func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provid dryRun: dryRun, } - whoamiResponse, err := provider.identity.Whoami(context.Background()) - if err != nil { - return nil, err + whoamiResponse := &dnsimple.WhoamiResponse{} + if skipWhoami == false { + var err error + whoamiResponse, err = provider.identity.Whoami(context.Background()) + if err != nil { + return nil, err + } } + if dnsimpleAccountId == "" { provider.accountID = int64ToString(whoamiResponse.Data.Account.ID) } else { From 3babcbcd72360470b423a22033c8c6f75d9dcbda Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Mon, 26 Feb 2024 12:02:29 -0500 Subject: [PATCH 06/14] Fix provider/dnsimple/dnsimple_test.go: Add the missing call to NewDnsimpleProvider for testing its behavior when the DNSIMPLE_OAUTH environment variable is not set --- provider/dnsimple/dnsimple_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/provider/dnsimple/dnsimple_test.go b/provider/dnsimple/dnsimple_test.go index 56874f411..6626ad6f6 100644 --- a/provider/dnsimple/dnsimple_test.go +++ b/provider/dnsimple/dnsimple_test.go @@ -246,7 +246,9 @@ func TestNewDnsimpleProvider(t *testing.T) { if err == nil { t.Errorf("Expected to fail new provider on bad token") } + os.Unsetenv("DNSIMPLE_OAUTH") + _, err = NewDnsimpleProvider(endpoint.NewDomainFilter([]string{"example.com"}), provider.NewZoneIDFilter([]string{""}), true) if err == nil { t.Errorf("Expected to fail new provider on empty token") } From acf188f7199dab55538aa8465cedaa188df90ada Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Mon, 26 Feb 2024 12:13:24 -0500 Subject: [PATCH 07/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Update tests to check that the BuildDnsimpleProvider function (called by the NewDnsimpleProvider function) handles the DNSIMPLE_ACCOUNT_ID environment variable properly --- provider/dnsimple/dnsimple_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/provider/dnsimple/dnsimple_test.go b/provider/dnsimple/dnsimple_test.go index 6626ad6f6..b566d774f 100644 --- a/provider/dnsimple/dnsimple_test.go +++ b/provider/dnsimple/dnsimple_test.go @@ -252,6 +252,16 @@ func TestNewDnsimpleProvider(t *testing.T) { if err == nil { t.Errorf("Expected to fail new provider on empty token") } + + os.Setenv("DNSIMPLE_OAUTH", "xxxxxxxxxxxxxxxxxxxxxxxxxx") + os.Setenv("DNSIMPLE_ACCOUNT_ID", "12345678") + builtProvider, err := BuildDnsimpleProvider(endpoint.NewDomainFilter([]string{"example.com"}), provider.NewZoneIDFilter([]string{""}), true, true) + if err != nil { + t.Errorf("Unexpected error thrown when testing BuildDnsimpleProvider with the DNSIMPLE_ACCOUNT_ID environment variable set") + } + assert.Equal(t, builtProvider.accountID, "12345678") + os.Unsetenv("DNSIMPLE_OAUTH") + os.Unsetenv("DNSIMPLE_ACCOUNT_ID") } func testDnsimpleGetRecordID(t *testing.T) { From eb59b9bd4d6eca06759540e6758540a46fd9b441 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Thu, 14 Mar 2024 20:23:00 -0400 Subject: [PATCH 08/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Fix code linting error - use !skipWhoami instead of skipWhoami == false --- provider/dnsimple/dnsimple.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/dnsimple/dnsimple.go b/provider/dnsimple/dnsimple.go index 80c146d13..aa205a2e0 100644 --- a/provider/dnsimple/dnsimple.go +++ b/provider/dnsimple/dnsimple.go @@ -125,7 +125,7 @@ func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter prov } whoamiResponse := &dnsimple.WhoamiResponse{} - if skipWhoami == false { + if !skipWhoami { var err error whoamiResponse, err = provider.identity.Whoami(context.Background()) if err != nil { From c54a9a8df2e806f11441ce72820cdb978be3d97c Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Thu, 14 Mar 2024 20:45:21 -0400 Subject: [PATCH 09/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Fix code linting error - remove () from ZonesFromZoneString which only returns one value --- provider/dnsimple/dnsimple.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/dnsimple/dnsimple.go b/provider/dnsimple/dnsimple.go index aa205a2e0..ad1eb3566 100644 --- a/provider/dnsimple/dnsimple.go +++ b/provider/dnsimple/dnsimple.go @@ -151,7 +151,7 @@ func (p *dnsimpleProvider) GetAccountID(ctx context.Context) (accountID string, return int64ToString(whoamiResponse.Data.Account.ID), nil } -func ZonesFromZoneString(zonestring string) (map[string]dnsimple.Zone) { +func ZonesFromZoneString(zonestring string) map[string]dnsimple.Zone { zones := make(map[string]dnsimple.Zone) zoneNames := strings.Split(zonestring, ",") for indexId, zoneName := range zoneNames { From 9c24ecc1084c4eff695da14e1e6b1ef1b9202b77 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Fri, 15 Mar 2024 11:07:23 -0400 Subject: [PATCH 10/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Refactor the BuildDnsimpleProvider method so that it no longer needs the skipWhoami bool parameter --- provider/dnsimple/dnsimple.go | 17 ++++++----------- provider/dnsimple/dnsimple_test.go | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/provider/dnsimple/dnsimple.go b/provider/dnsimple/dnsimple.go index ad1eb3566..1331bce11 100644 --- a/provider/dnsimple/dnsimple.go +++ b/provider/dnsimple/dnsimple.go @@ -102,8 +102,9 @@ func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provid return BuildDnsimpleProvider(domainFilter, zoneIDFilter, dryRun, false) } -// Create a new Dnsimple based provider but return a *dnsimpleProvider and allow for the call to provider.identity.Whoami to be bypassed - both for testing purposes -func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool, skipWhoami bool) (*dnsimpleProvider, error) { +// Create a new Dnsimple based provider returning a *dnsimpleProvider. The *dnsimpleProvider return type is needed for testing purposes +// therefore this method, and not NewDnsimpleProvider, must be the one used by dnsimple_test.go +func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (*dnsimpleProvider, error) { oauthToken := os.Getenv("DNSIMPLE_OAUTH") dnsimpleAccountId := os.Getenv("DNSIMPLE_ACCOUNT_ID") if len(oauthToken) == 0 { @@ -124,19 +125,13 @@ func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter prov dryRun: dryRun, } - whoamiResponse := &dnsimple.WhoamiResponse{} - if !skipWhoami { - var err error - whoamiResponse, err = provider.identity.Whoami(context.Background()) + provider.accountID = dnsimpleAccountId + if provider.accountID == "" { + whoamiResponse, err := provider.identity.Whoami(context.Background()) if err != nil { return nil, err } - } - - if dnsimpleAccountId == "" { provider.accountID = int64ToString(whoamiResponse.Data.Account.ID) - } else { - provider.accountID = dnsimpleAccountId } return provider, nil } diff --git a/provider/dnsimple/dnsimple_test.go b/provider/dnsimple/dnsimple_test.go index b566d774f..604b88c19 100644 --- a/provider/dnsimple/dnsimple_test.go +++ b/provider/dnsimple/dnsimple_test.go @@ -255,7 +255,7 @@ func TestNewDnsimpleProvider(t *testing.T) { os.Setenv("DNSIMPLE_OAUTH", "xxxxxxxxxxxxxxxxxxxxxxxxxx") os.Setenv("DNSIMPLE_ACCOUNT_ID", "12345678") - builtProvider, err := BuildDnsimpleProvider(endpoint.NewDomainFilter([]string{"example.com"}), provider.NewZoneIDFilter([]string{""}), true, true) + builtProvider, err := BuildDnsimpleProvider(endpoint.NewDomainFilter([]string{"example.com"}), provider.NewZoneIDFilter([]string{""}), true) if err != nil { t.Errorf("Unexpected error thrown when testing BuildDnsimpleProvider with the DNSIMPLE_ACCOUNT_ID environment variable set") } From 660b20b4425da537b324f65c627b0483ea3319d0 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Fri, 15 Mar 2024 11:37:51 -0400 Subject: [PATCH 11/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Refactor the BuildDnsimpleProvider method so that it no longer needs the skipWhoami bool parameter --- provider/dnsimple/dnsimple.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/dnsimple/dnsimple.go b/provider/dnsimple/dnsimple.go index 1331bce11..0161b3d75 100644 --- a/provider/dnsimple/dnsimple.go +++ b/provider/dnsimple/dnsimple.go @@ -99,7 +99,7 @@ const ( // NewDnsimpleProvider initializes a new Dnsimple based provider func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (provider.Provider, error) { - return BuildDnsimpleProvider(domainFilter, zoneIDFilter, dryRun, false) + return BuildDnsimpleProvider(domainFilter, zoneIDFilter, dryRun) } // Create a new Dnsimple based provider returning a *dnsimpleProvider. The *dnsimpleProvider return type is needed for testing purposes From 3eb852fe2acda27f3bf15f75908de2ba966faa34 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Fri, 15 Mar 2024 13:03:53 -0400 Subject: [PATCH 12/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Grammar fix in docs/tutorials/dnsimple.md Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com> --- docs/tutorials/dnsimple.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorials/dnsimple.md b/docs/tutorials/dnsimple.md index 980682c35..75112ed0c 100644 --- a/docs/tutorials/dnsimple.md +++ b/docs/tutorials/dnsimple.md @@ -11,7 +11,7 @@ A DNSimple API access token can be acquired by following the [provided documenta The environment variable `DNSIMPLE_OAUTH` must be set to the generated API token to run ExternalDNS with DNSimple. -If the generated DNSimple API access token is a _User token_, as opposed to an _Account token_, the following environment variables must also be set: +When the generated DNSimple API access token is a _User token_, as opposed to an _Account token_, the following environment variables must also be set: - `DNSIMPLE_ACCOUNT_ID`: Set this to the account ID which the domains to be managed by ExternalDNS belong to (eg. `1001234`). - `DNSIMPLE_ZONES`: Set this to a comma separated list of DNS zones to be managed by ExternalDNS (eg. `mydomain.com,example.com`). From 487501d923a59cb9e93ec3ebf4ef5447476540a7 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Fri, 15 Mar 2024 15:46:01 -0400 Subject: [PATCH 13/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Refactor the BuildDnsimpleProvider method so that the dnsimpleAccountId variable, which was only used once, can be removed --- provider/dnsimple/dnsimple.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/provider/dnsimple/dnsimple.go b/provider/dnsimple/dnsimple.go index 0161b3d75..2e6af5946 100644 --- a/provider/dnsimple/dnsimple.go +++ b/provider/dnsimple/dnsimple.go @@ -106,7 +106,6 @@ func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provid // therefore this method, and not NewDnsimpleProvider, must be the one used by dnsimple_test.go func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (*dnsimpleProvider, error) { oauthToken := os.Getenv("DNSIMPLE_OAUTH") - dnsimpleAccountId := os.Getenv("DNSIMPLE_ACCOUNT_ID") if len(oauthToken) == 0 { return nil, fmt.Errorf("no dnsimple oauth token provided") } @@ -125,7 +124,7 @@ func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter prov dryRun: dryRun, } - provider.accountID = dnsimpleAccountId + provider.accountID = os.Getenv("DNSIMPLE_ACCOUNT_ID") if provider.accountID == "" { whoamiResponse, err := provider.identity.Whoami(context.Background()) if err != nil { From ed3efdb2608af0c387bba69ad6440e4f3f2c5c30 Mon Sep 17 00:00:00 2001 From: Michael Lescisin Date: Fri, 15 Mar 2024 18:28:25 -0400 Subject: [PATCH 14/14] Allow for DNSimple User API tokens to be used by implementing the DNSIMPLE_ACCOUNT_ID and DNSIMPLE_ZONES environment variables Refactor so that the BuildDnsimpleProvider method can be removed and the NewDnsimpleProvider method be used exclusively instead --- provider/dnsimple/dnsimple.go | 6 ------ provider/dnsimple/dnsimple_test.go | 7 ++++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/provider/dnsimple/dnsimple.go b/provider/dnsimple/dnsimple.go index 2e6af5946..ff74246a3 100644 --- a/provider/dnsimple/dnsimple.go +++ b/provider/dnsimple/dnsimple.go @@ -99,12 +99,6 @@ const ( // NewDnsimpleProvider initializes a new Dnsimple based provider func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (provider.Provider, error) { - return BuildDnsimpleProvider(domainFilter, zoneIDFilter, dryRun) -} - -// Create a new Dnsimple based provider returning a *dnsimpleProvider. The *dnsimpleProvider return type is needed for testing purposes -// therefore this method, and not NewDnsimpleProvider, must be the one used by dnsimple_test.go -func BuildDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (*dnsimpleProvider, error) { oauthToken := os.Getenv("DNSIMPLE_OAUTH") if len(oauthToken) == 0 { return nil, fmt.Errorf("no dnsimple oauth token provided") diff --git a/provider/dnsimple/dnsimple_test.go b/provider/dnsimple/dnsimple_test.go index 604b88c19..c2106482b 100644 --- a/provider/dnsimple/dnsimple_test.go +++ b/provider/dnsimple/dnsimple_test.go @@ -255,11 +255,12 @@ func TestNewDnsimpleProvider(t *testing.T) { os.Setenv("DNSIMPLE_OAUTH", "xxxxxxxxxxxxxxxxxxxxxxxxxx") os.Setenv("DNSIMPLE_ACCOUNT_ID", "12345678") - builtProvider, err := BuildDnsimpleProvider(endpoint.NewDomainFilter([]string{"example.com"}), provider.NewZoneIDFilter([]string{""}), true) + providerTypedProvider, err := NewDnsimpleProvider(endpoint.NewDomainFilter([]string{"example.com"}), provider.NewZoneIDFilter([]string{""}), true) + dnsimpleTypedProvider := providerTypedProvider.(*dnsimpleProvider) if err != nil { - t.Errorf("Unexpected error thrown when testing BuildDnsimpleProvider with the DNSIMPLE_ACCOUNT_ID environment variable set") + t.Errorf("Unexpected error thrown when testing NewDnsimpleProvider with the DNSIMPLE_ACCOUNT_ID environment variable set") } - assert.Equal(t, builtProvider.accountID, "12345678") + assert.Equal(t, dnsimpleTypedProvider.accountID, "12345678") os.Unsetenv("DNSIMPLE_OAUTH") os.Unsetenv("DNSIMPLE_ACCOUNT_ID") }