From 24ec4dd0c74ccdd8a3e1fbe922f2e028928b73fd Mon Sep 17 00:00:00 2001 From: Alexander Krieg <128027135+akrieg-ionos@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:48:29 +0200 Subject: [PATCH] fix(config): omit issuer check for detecting dns provider (#41) --- .github/workflows/pull_request.yml | 4 ++-- Makefile | 2 +- cmd/webhook/init/dnsprovider/dnsprovider.go | 8 +------- .../init/dnsprovider/dnsprovider_test.go | 18 ++++++++++++++++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b33eef0..b54daa1 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -50,5 +50,5 @@ jobs: uses: goreleaser/goreleaser-action@v4 with: distribution: goreleaser - version: latest - args: release --snapshot --clean --skip-publish + version: v1.26.2 + args: release --snapshot --clean --skip=publish diff --git a/Makefile b/Makefile index b8061a5..71696ef 100644 --- a/Makefile +++ b/Makefile @@ -91,7 +91,7 @@ unit-test: ## Run unit tests .PHONY: release-check release-check: ## Check if the release will work - GITHUB_SERVER_URL=github.com GITHUB_REPOSITORY=ionos-cloud/external-dns-ionos-webhook REGISTRY=$(REGISTRY) IMAGE_NAME=$(IMAGE_NAME) goreleaser release --snapshot --clean --skip-publish + GITHUB_SERVER_URL=github.com GITHUB_REPOSITORY=ionos-cloud/external-dns-ionos-webhook REGISTRY=$(REGISTRY) IMAGE_NAME=$(IMAGE_NAME) goreleaser release --snapshot --clean --skip=publish ##@ License diff --git a/cmd/webhook/init/dnsprovider/dnsprovider.go b/cmd/webhook/init/dnsprovider/dnsprovider.go index 4f098b1..cafc0a3 100644 --- a/cmd/webhook/init/dnsprovider/dnsprovider.go +++ b/cmd/webhook/init/dnsprovider/dnsprovider.go @@ -19,10 +19,6 @@ import ( log "github.com/sirupsen/logrus" ) -const ( - webtokenIonosISSValue = "ionoscloud" -) - type IONOSProviderFactory func(baseProvider *provider.BaseProvider, ionosConfig *ionos.Configuration) provider.Provider func setDefaults(apiEndpointURL, authHeader string, ionosConfig *ionos.Configuration) { @@ -94,9 +90,7 @@ func detectProvider(ionosConfig *ionos.Configuration) IONOSProviderFactory { if err != nil { return IonosCoreProviderFactory } - if tokenMap["iss"] == webtokenIonosISSValue { - return IonosCloudProviderFactory - } + return IonosCloudProviderFactory } return IonosCoreProviderFactory } diff --git a/cmd/webhook/init/dnsprovider/dnsprovider_test.go b/cmd/webhook/init/dnsprovider/dnsprovider_test.go index 5be8827..c70334c 100644 --- a/cmd/webhook/init/dnsprovider/dnsprovider_test.go +++ b/cmd/webhook/init/dnsprovider/dnsprovider_test.go @@ -1,6 +1,7 @@ package dnsprovider import ( + "encoding/base64" "testing" "github.com/ionos-cloud/external-dns-ionos-webhook/internal/ionoscloud" @@ -13,6 +14,7 @@ import ( func TestInit(t *testing.T) { log.SetLevel(log.DebugLevel) + jwtPayloadEncoded := base64.RawURLEncoding.EncodeToString([]byte(`{ "something" : "we dont care" }`)) cases := []struct { name string @@ -28,10 +30,22 @@ func TestInit(t *testing.T) { providerType: "core", }, { - name: "minimal config for ionos cloud provider ( token is jwt with payload iss=ionoscloud )", + name: "config for ionos core provider, apikey with 2 dots but no jwt because no json", + config: configuration.Config{}, + env: map[string]string{"IONOS_API_KEY": "algorithm.nojson.signature"}, + providerType: "core", + }, + { + name: "config for ionos core provider, apikey with 2 dots but no jwt because payload not base64 encoded", + config: configuration.Config{}, + env: map[string]string{"IONOS_API_KEY": "algorithm.==.signature"}, + providerType: "core", + }, + { + name: "minimal config for ionos cloud provider, token can be decoded as jwt ", config: configuration.Config{}, env: map[string]string{ - "IONOS_API_KEY": "algorithm.eyAiaXNzIiA6ICJpb25vc2Nsb3VkIiB9.signature", + "IONOS_API_KEY": "algorithm." + jwtPayloadEncoded + ".signature", }, providerType: "cloud", },