diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 973ded1..a5a90d5 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,10 +3,10 @@ id: b81e5def-5b1e-4753-ae7c-0efccc2e6f61 management: docChecksum: 621f79fe092199d80a95ca5aa0238ebc docVersion: 0.0.1 - speakeasyVersion: 1.439.0 - generationVersion: 2.457.9 - releaseVersion: 0.1.6 - configChecksum: 5464a3ce17d764c785662a6628d0b0ec + speakeasyVersion: 1.441.0 + generationVersion: 2.460.1 + releaseVersion: 0.1.7 + configChecksum: db304f60e3a64fc47b514a7de5d55c5b features: go: additionalDependencies: 0.1.0 diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index e7fbe11..9d81442 100755 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -13,7 +13,7 @@ generation: oAuth2ClientCredentialsEnabled: false oAuth2PasswordEnabled: false go: - version: 0.1.6 + version: 0.1.7 additionalDependencies: {} allowUnknownFieldsInWeakUnions: false clientServerStatusCodesAsErrors: true diff --git a/internal/hooks/README.md b/internal/hooks/README.md new file mode 100644 index 0000000..391fffa --- /dev/null +++ b/internal/hooks/README.md @@ -0,0 +1,17 @@ +# Configuration through environment variables + +This SDK can be configured via the environment variables. + +## Konnect domain + +Konnect domain can be customized via `KONG_CUSTOM_DOMAIN` environment variable. +This is useful when testing against a development environment or a custom domain. +This is optional and the default value is `konghq.com`. + +## Request and response logging + +Request and response logging can be enabled via: + +- `KONNECT_SDK_HTTP_DUMP_REQUEST`: Set to `true` to log request bodies. +- `KONNECT_SDK_HTTP_DUMP_RESPONSE`: Set to `true` to log response bodies. +- `KONNECT_SDK_HTTP_DUMP_RESPONSE_ERROR`: Set to `true` to log response bodies only when the response status code is an error. diff --git a/internal/hooks/registration.go b/internal/hooks/registration.go index a514d7c..38b7b5f 100644 --- a/internal/hooks/registration.go +++ b/internal/hooks/registration.go @@ -11,7 +11,9 @@ import "os" func initHooks(h *Hooks) { h.registerBeforeRequestHook(&UserAgentPreRequestHook{}) - h.registerBeforeRequestHook(&APIURLRequestHook{}) + h.registerBeforeRequestHook(&APIURLRequestHook{ + CustomDomain: os.Getenv("KONG_CUSTOM_DOMAIN"), + }) if os.Getenv("KONNECT_SDK_HTTP_DUMP_REQUEST") == "true" { h.registerBeforeRequestHook(&HTTPDumpRequestHook{}) diff --git a/internal/hooks/url.go b/internal/hooks/url.go index 13a977c..18f4786 100644 --- a/internal/hooks/url.go +++ b/internal/hooks/url.go @@ -5,21 +5,18 @@ import ( "strings" ) -type APIURLRequestHook struct{} +type APIURLRequestHook struct { + CustomDomain string +} var _ beforeRequestHook = (*APIURLRequestHook)(nil) +// Replace `.konghq.com` with the custom domain set in the `KONG_CUSTOM_DOMAIN` environment variable. func (i *APIURLRequestHook) BeforeRequest(hookCtx BeforeRequestContext, req *http.Request) (*http.Request, error) { - switch hookCtx.OperationID { - case "get-organizations-me": - // NOTE(pmalek): This is because we merge OpenAPI specs and /organizations/me - // is only served by the global API. - // @mheap mentioned that we can add operation specific URLs to do away with this. - if strings.HasSuffix(req.URL.Host, "api.konghq.tech") { - req.URL.Host = "global.api.konghq.tech" - } else { - req.URL.Host = "global.api.konghq.com" - } + if i.CustomDomain != "" { + req.URL.Host = strings.Replace(req.URL.Host, ".konghq.com", "."+i.CustomDomain, 1) + req.Host = strings.Replace(req.Host, ".konghq.com", "."+i.CustomDomain, 1) } + return req, nil } diff --git a/sdk.go b/sdk.go index bd15f02..08fce1c 100644 --- a/sdk.go +++ b/sdk.go @@ -261,9 +261,9 @@ func New(opts ...SDKOption) *SDK { sdkConfiguration: sdkConfiguration{ Language: "go", OpenAPIDocVersion: "0.0.1", - SDKVersion: "0.1.6", - GenVersion: "2.457.9", - UserAgent: "speakeasy-sdk/go 0.1.6 2.457.9 0.0.1 github.com/Kong/sdk-konnect-go", + SDKVersion: "0.1.7", + GenVersion: "2.460.1", + UserAgent: "speakeasy-sdk/go 0.1.7 2.460.1 0.0.1 github.com/Kong/sdk-konnect-go", Hooks: hooks.New(), }, }