From e040c1019744f20dcfdcf55ac3ecf1387b21e299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Thu, 1 Aug 2024 17:50:35 +0200 Subject: [PATCH] chore: add Konnect SDK factory (#458) * chore: add Konnect SDK factory * Update controller/konnect/sdkfactory.go --- controller/konnect/sdkfactory.go | 33 ++++++++++++++++++++++++++++++++ go.mod | 3 +++ go.sum | 4 ++++ 3 files changed, 40 insertions(+) create mode 100644 controller/konnect/sdkfactory.go diff --git a/controller/konnect/sdkfactory.go b/controller/konnect/sdkfactory.go new file mode 100644 index 000000000..e1d784cb0 --- /dev/null +++ b/controller/konnect/sdkfactory.go @@ -0,0 +1,33 @@ +package konnect + +import ( + sdkkonnectgo "github.com/Kong/sdk-konnect-go" + sdkkonnectgocomp "github.com/Kong/sdk-konnect-go/models/components" +) + +// SDKToken is a token used to authenticate with the Konnect SDK. +type SDKToken string + +// SDKFactory is a factory for creating Konnect SDKs. +type SDKFactory interface { + NewKonnectSDK(serverURL string, token SDKToken) *sdkkonnectgo.SDK +} + +type sdkFactory struct{} + +// NewSDKFactory creates a new SDKFactory. +func NewSDKFactory() SDKFactory { + return sdkFactory{} +} + +// NewKonnectSDK creates a new Konnect SDK. +func (f sdkFactory) NewKonnectSDK(serverURL string, token SDKToken) *sdkkonnectgo.SDK { + return sdkkonnectgo.New( + sdkkonnectgo.WithSecurity( + sdkkonnectgocomp.Security{ + PersonalAccessToken: sdkkonnectgo.String(string(token)), + }, + ), + sdkkonnectgo.WithServerURL("https://"+serverURL), + ) +} diff --git a/go.mod b/go.mod index 3e2a66880..b342e155f 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ toolchain go1.22.4 retract v1.2.2 require ( + github.com/Kong/sdk-konnect-go v0.0.0-20240801091928-39a27951b473 github.com/Masterminds/semver v1.5.0 github.com/cert-manager/cert-manager v1.15.2 github.com/cloudflare/cfssl v1.6.5 @@ -38,8 +39,10 @@ require ( github.com/aws/aws-sdk-go v1.49.13 // indirect github.com/bombsimon/logrusr/v3 v3.1.0 // indirect github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect + github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect github.com/distribution/reference v0.5.0 // indirect + github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/go-logr/stdr v1.2.2 // indirect diff --git a/go.sum b/go.sum index 5b3cdf93b..5777ea2f6 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg6 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/Kong/sdk-konnect-go v0.0.0-20240801091928-39a27951b473 h1:vIYHnHxEcWTGPZ113NPlLvWEOWYaPRYwwpuoU2J64yY= +github.com/Kong/sdk-konnect-go v0.0.0-20240801091928-39a27951b473/go.mod h1:75YzLhfnYfmCvBJgkafzVuREwBAec2/jihCW2fyn6hY= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= @@ -72,6 +74,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731 h1:R/ZjJpjQKsZ6L/+Gf9WHbt31GG8NMVcpRqUE+1mMIyo= +github.com/ericlagergren/decimal v0.0.0-20240411145413-00de7ca16731/go.mod h1:M9R1FoZ3y//hwwnJtO51ypFGwm8ZfpxPT/ZLtO1mcgQ= github.com/evanphx/json-patch v5.9.0+incompatible h1:fBXyNpNMuTTDdquAq/uisOr2lShz4oaXpDTX2bLe7ls= github.com/evanphx/json-patch v5.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=