-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add Konnect SDK factory (#458)
* chore: add Konnect SDK factory * Update controller/konnect/sdkfactory.go
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters