Skip to content

Commit

Permalink
feat(konnect): add KongCredentialAPIKey reconciler (#635)
Browse files Browse the repository at this point in the history
* feat(konnect): add KongCredentialAPIKey

* chore: typo in controller/konnect/index_credentials_apikey.go
  • Loading branch information
pmalek authored Sep 25, 2024
1 parent 23b649b commit 1b3c328
Show file tree
Hide file tree
Showing 16 changed files with 824 additions and 43 deletions.
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ packages:
TargetsSDK:
VaultSDK:
MeSDK:
KongCredentialAPIKeySDK:
KongCredentialBasicAuthSDK:
CACertificatesSDK:
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
[#592](https://github.com/Kong/gateway-operator/pull/592)
- Add support for `KongConsumer` credentials:
- basic-auth [#625](https://github.com/Kong/gateway-operator/pull/625)
- API key [#635](https://github.com/Kong/gateway-operator/pull/635)

### Fixed

Expand Down
45 changes: 45 additions & 0 deletions config/samples/konnect_kongconsumer_apikey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
kind: KonnectAPIAuthConfiguration
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: konnect-api-auth-dev-1
namespace: default
spec:
type: token
token: kpat_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
serverURL: us.api.konghq.com
---
kind: KonnectGatewayControlPlane
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: test-cp-basic-auth
namespace: default
spec:
name: test-cp-basic-auth
labels:
app: test-cp-basic-auth
key1: test-cp-basic-auth
konnect:
authRef:
name: konnect-api-auth-dev-1
---
kind: KongConsumer
apiVersion: configuration.konghq.com/v1
metadata:
name: consumer-api-key-1
namespace: default
username: consumer1
spec:
controlPlaneRef:
type: konnectNamespacedRef
konnectNamespacedRef:
name: test-cp-basic-auth
---
apiVersion: configuration.konghq.com/v1alpha1
kind: KongCredentialAPIKey
metadata:
name: api-key-1
namespace: default
spec:
consumerRef:
name: consumer-api-key-1
key: secretkey
1 change: 1 addition & 0 deletions controller/konnect/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type SupportedKonnectEntityType interface {
configurationv1beta1.KongConsumerGroup |
configurationv1alpha1.KongPluginBinding |
configurationv1alpha1.KongCredentialBasicAuth |
configurationv1alpha1.KongCredentialAPIKey |
configurationv1alpha1.KongUpstream |
configurationv1alpha1.KongCACertificate |
configurationv1alpha1.KongTarget |
Expand Down
32 changes: 32 additions & 0 deletions controller/konnect/index_credentials_apikey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package konnect

import (
"sigs.k8s.io/controller-runtime/pkg/client"

configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
)

const (
// IndexFieldKongCredentialAPIKeyReferencesKongConsumer is the index name for KongCredentialAPIKey -> Consumer.
IndexFieldKongCredentialAPIKeyReferencesKongConsumer = "kongCredentialsAPIKeyConsumerRef"
)

// IndexOptionsForCredentialsAPIKey returns required Index options for KongCredentialAPIKey.
func IndexOptionsForCredentialsAPIKey() []ReconciliationIndexOption {
return []ReconciliationIndexOption{
{
IndexObject: &configurationv1alpha1.KongCredentialAPIKey{},
IndexField: IndexFieldKongCredentialAPIKeyReferencesKongConsumer,
ExtractValue: kongCredentialAPIKeyReferencesConsumer,
},
}
}

// kongCredentialAPIKeyReferencesConsumer returns the name of referenced Consumer.
func kongCredentialAPIKeyReferencesConsumer(obj client.Object) []string {
cred, ok := obj.(*configurationv1alpha1.KongCredentialAPIKey)
if !ok {
return nil
}
return []string{cred.Spec.ConsumerRef.Name}
}
14 changes: 14 additions & 0 deletions controller/konnect/ops/credentialapikey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ops

import (
"context"

sdkkonnectops "github.com/Kong/sdk-konnect-go/models/operations"
)

// KongCredentialAPIKeySDK is the interface for the Konnect KongCredentialAPIKeySDK.
type KongCredentialAPIKeySDK interface {
CreateKeyAuthWithConsumer(ctx context.Context, req sdkkonnectops.CreateKeyAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.CreateKeyAuthWithConsumerResponse, error)
DeleteKeyAuthWithConsumer(ctx context.Context, request sdkkonnectops.DeleteKeyAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.DeleteKeyAuthWithConsumerResponse, error)
UpsertKeyAuthWithConsumer(ctx context.Context, request sdkkonnectops.UpsertKeyAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.UpsertKeyAuthWithConsumerResponse, error)
}
259 changes: 259 additions & 0 deletions controller/konnect/ops/credentialapikey_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1b3c328

Please sign in to comment.