From 2a93bc0983b02a545ba7f331a34164a389d28c03 Mon Sep 17 00:00:00 2001 From: Jason Collins Date: Wed, 14 Feb 2024 15:51:15 -0700 Subject: [PATCH] add constants --- pkg/discovery/gateway/client.go | 20 ++++++++++++-------- pkg/discovery/kong/authplugins.go | 6 ++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pkg/discovery/gateway/client.go b/pkg/discovery/gateway/client.go index 89395a6..f3eea9f 100644 --- a/pkg/discovery/gateway/client.go +++ b/pkg/discovery/gateway/client.go @@ -25,10 +25,14 @@ import ( "github.com/Axway/agents-kong/pkg/discovery/subscription" ) +const ( + https = "https" +) + var kongToCRDMapper = map[string]string{ - "basic-auth": provisioning.BasicAuthCRD, - "key-auth": provisioning.APIKeyCRD, - "oauth2": provisioning.OAuthSecretCRD, + kong.BasicAuthPlugin: provisioning.BasicAuthCRD, + kong.KeyAuthPlugin: provisioning.APIKeyCRD, + kong.OAuthPlugin: provisioning.OAuthSecretCRD, } func NewClient(agentConfig config.AgentConfig) (*Client, error) { @@ -305,11 +309,11 @@ func (ka *KongAPI) processSpecSecurity(spec apic.SpecProcessor, apiPlugins map[s ka.crds = append(ka.crds, crd) } switch k { - case "basic-auth": + case kong.BasicAuthPlugin: oasSpec.AddSecuritySchemes(oasSpec.GetSecurityBuilder().HTTPBasic().Build()) - case "key-auth": + case kong.KeyAuthPlugin: ka.apiKeySecurity(oasSpec, plugin.Config) - case "oauth2": + case kong.OAuthPlugin: ka.oAuthSecurity(oasSpec, plugin.Config) } } @@ -343,9 +347,9 @@ func (ka *KongAPI) oAuthSecurity(spec apic.OasSpecProcessor, config map[string]i s := url.URL{} for _, e := range ka.endpoints { - if e.Protocol == "https" { + if e.Protocol == https { s = url.URL{ - Scheme: "https", + Scheme: https, Host: fmt.Sprintf("%v:%v", e.Host, e.Port), Path: e.BasePath, } diff --git a/pkg/discovery/kong/authplugins.go b/pkg/discovery/kong/authplugins.go index 9e6a992..af15766 100644 --- a/pkg/discovery/kong/authplugins.go +++ b/pkg/discovery/kong/authplugins.go @@ -4,6 +4,12 @@ import ( "encoding/json" ) +const ( + BasicAuthPlugin = "basic-auth" + KeyAuthPlugin = "key-auth" + OAuthPlugin = "oauth2" +) + type OAuthPluginConfig struct { HideCredentials bool `json:"hide_credentials,omitempty"` PersistentRefreshToken bool `json:"persistent_refresh_token,omitempty"`