Skip to content

Commit

Permalink
add constants
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-axway committed Feb 14, 2024
1 parent 8cf7fb6 commit 2a93bc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/discovery/gateway/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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,
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/discovery/kong/authplugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 2a93bc0

Please sign in to comment.