-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor SDKFactory to allow using mock SDK in reconcilers
- Loading branch information
1 parent
0b5df8e
commit 778a9d9
Showing
9 changed files
with
133 additions
and
64 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,12 @@ | ||
package ops | ||
|
||
import ( | ||
"context" | ||
|
||
sdkkonnectops "github.com/Kong/sdk-konnect-go/models/operations" | ||
) | ||
|
||
// MeSDK is the interface for Konnect "Me" SDK to get current organization. | ||
type MeSDK interface { | ||
GetOrganizationsMe(ctx context.Context, opts ...sdkkonnectops.Option) (*sdkkonnectops.GetOrganizationsMeResponse, error) | ||
} |
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
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,87 @@ | ||
package ops | ||
|
||
import ( | ||
sdkkonnectgo "github.com/Kong/sdk-konnect-go" | ||
sdkkonnectcomp "github.com/Kong/sdk-konnect-go/models/components" | ||
) | ||
|
||
// SDKWrapper is a wrapper of Konnect SDK to allow using mock SDKs in tests. | ||
type SDKWrapper interface { | ||
GetControlPlaneSDK() ControlPlaneSDK | ||
GetServicesSDK() ServicesSDK | ||
GetRoutesSDK() RoutesSDK | ||
GetConsumersSDK() ConsumersSDK | ||
GetConsumerGroupsSDK() ConsumerGroupSDK | ||
GetPluginSDK() PluginSDK | ||
GetMeSDK() MeSDK | ||
} | ||
|
||
type sdkWrapper struct { | ||
sdk *sdkkonnectgo.SDK | ||
} | ||
|
||
var _ SDKWrapper = sdkWrapper{} | ||
|
||
// GetControlPlaneSDK returns the SDK to operate Konenct control planes. | ||
func (w sdkWrapper) GetControlPlaneSDK() ControlPlaneSDK { | ||
return w.sdk.ControlPlanes | ||
} | ||
|
||
// GetServicesSDK returns the SDK to operate Kong services. | ||
func (w sdkWrapper) GetServicesSDK() ServicesSDK { | ||
return w.sdk.Services | ||
} | ||
|
||
// GetRoutesSDK returns the SDK to operate Kong routes. | ||
func (w sdkWrapper) GetRoutesSDK() RoutesSDK { | ||
return w.sdk.Routes | ||
} | ||
|
||
// GetConsumersSDK returns the SDK to operate Kong consumers. | ||
func (w sdkWrapper) GetConsumersSDK() ConsumersSDK { | ||
return w.sdk.Consumers | ||
} | ||
|
||
// GetConsumerGroupsSDK returns the SDK to operate Kong consumer groups. | ||
func (w sdkWrapper) GetConsumerGroupsSDK() ConsumerGroupSDK { | ||
return w.sdk.ConsumerGroups | ||
} | ||
|
||
// GetPluginSDK returns the SDK to operate plugins. | ||
func (w sdkWrapper) GetPluginSDK() PluginSDK { | ||
return w.sdk.Plugins | ||
} | ||
|
||
// GetMeSDK returns the "me" SDK to get current organization. | ||
func (w sdkWrapper) GetMeSDK() MeSDK { | ||
return w.sdk.Me | ||
} | ||
|
||
// 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) SDKWrapper | ||
} | ||
|
||
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) SDKWrapper { | ||
return sdkWrapper{ | ||
sdk: sdkkonnectgo.New( | ||
sdkkonnectgo.WithSecurity( | ||
sdkkonnectcomp.Security{ | ||
PersonalAccessToken: sdkkonnectgo.String(string(token)), | ||
}, | ||
), | ||
sdkkonnectgo.WithServerURL(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
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 was deleted.
Oops, something went wrong.
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