Skip to content

Commit

Permalink
fix(config): omit issuer check for detecting dns provider (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
akrieg-ionos authored Jul 12, 2024
1 parent 0912de4 commit 24ec4dd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 1 addition & 7 deletions cmd/webhook/init/dnsprovider/dnsprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
18 changes: 16 additions & 2 deletions cmd/webhook/init/dnsprovider/dnsprovider_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dnsprovider

import (
"encoding/base64"
"testing"

"github.com/ionos-cloud/external-dns-ionos-webhook/internal/ionoscloud"
Expand All @@ -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
Expand All @@ -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",
},
Expand Down

0 comments on commit 24ec4dd

Please # to comment.