Skip to content

Commit

Permalink
feat(konnect): add KongCredentialHMAC
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Oct 3, 2024
1 parent ac6dd7b commit 3b96e87
Show file tree
Hide file tree
Showing 17 changed files with 768 additions and 3 deletions.
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ packages:
KongCredentialACLSDK:
KongCredentialBasicAuthSDK:
KongCredentialJWTSDK:
KongCredentialHMACSDK:
CACertificatesSDK:
CertificatesSDK:
KeysSDK:
Expand Down
46 changes: 46 additions & 0 deletions config/samples/konnect_kongconsumer_hmac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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-hmac-1
namespace: default
username: consumer1-hmac-1
spec:
controlPlaneRef:
type: konnectNamespacedRef
konnectNamespacedRef:
name: test-cp-basic-auth
---
apiVersion: configuration.konghq.com/v1alpha1
kind: KongCredentialHMAC
metadata:
name: hmac-1
namespace: default
spec:
consumerRef:
name: consumer-hmac-1
key: secretkey
username: consumer1-hmac-1
1 change: 1 addition & 0 deletions controller/konnect/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type SupportedKonnectEntityType interface {
configurationv1alpha1.KongCredentialAPIKey |
configurationv1alpha1.KongCredentialACL |
configurationv1alpha1.KongCredentialJWT |
configurationv1alpha1.KongCredentialHMAC |
configurationv1alpha1.KongUpstream |
configurationv1alpha1.KongCACertificate |
configurationv1alpha1.KongCertificate |
Expand Down
32 changes: 32 additions & 0 deletions controller/konnect/index_credentials_hmac.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 (
// IndexFieldKongCredentialHMACReferencesKongConsumer is the index name for KongCredentialHMAC -> Consumer.
IndexFieldKongCredentialHMACReferencesKongConsumer = "kongCredentialsHMACConsumerRef"
)

// IndexOptionsForCredentialsHMAC returns required Index options for KongCredentialHMAC.
func IndexOptionsForCredentialsHMAC() []ReconciliationIndexOption {
return []ReconciliationIndexOption{
{
IndexObject: &configurationv1alpha1.KongCredentialHMAC{},
IndexField: IndexFieldKongCredentialHMACReferencesKongConsumer,
ExtractValue: kongCredentialHMACReferencesConsumer,
},
}
}

// kongCredentialHMACReferencesConsumer returns the name of referenced Consumer.
func kongCredentialHMACReferencesConsumer(obj client.Object) []string {
cred, ok := obj.(*configurationv1alpha1.KongCredentialHMAC)
if !ok {
return nil
}
return []string{cred.Spec.ConsumerRef.Name}
}
14 changes: 14 additions & 0 deletions controller/konnect/ops/credentialhmac.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"
)

// KongCredentialHMACSDK is the interface for the Konnect KongCredentialHMACSDK.
type KongCredentialHMACSDK interface {
CreateHmacAuthWithConsumer(ctx context.Context, req sdkkonnectops.CreateHmacAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.CreateHmacAuthWithConsumerResponse, error)
DeleteHmacAuthWithConsumer(ctx context.Context, request sdkkonnectops.DeleteHmacAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.DeleteHmacAuthWithConsumerResponse, error)
UpsertHmacAuthWithConsumer(ctx context.Context, request sdkkonnectops.UpsertHmacAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.UpsertHmacAuthWithConsumerResponse, error)
}
259 changes: 259 additions & 0 deletions controller/konnect/ops/credentialhmac_mock.go

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

6 changes: 6 additions & 0 deletions controller/konnect/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func Create[
return e, createKongCredentialACL(ctx, sdk.GetACLCredentialsSDK(), ent)
case *configurationv1alpha1.KongCredentialJWT:
return e, createKongCredentialJWT(ctx, sdk.GetJWTCredentialsSDK(), ent)
case *configurationv1alpha1.KongCredentialHMAC:
return e, createKongCredentialHMAC(ctx, sdk.GetHMACCredentialsSDK(), ent)
case *configurationv1alpha1.KongCACertificate:
return e, createCACertificate(ctx, sdk.GetCACertificatesSDK(), ent)
case *configurationv1alpha1.KongCertificate:
Expand Down Expand Up @@ -136,6 +138,8 @@ func Delete[
return deleteKongCredentialACL(ctx, sdk.GetACLCredentialsSDK(), ent)
case *configurationv1alpha1.KongCredentialJWT:
return deleteKongCredentialJWT(ctx, sdk.GetJWTCredentialsSDK(), ent)
case *configurationv1alpha1.KongCredentialHMAC:
return deleteKongCredentialHMAC(ctx, sdk.GetHMACCredentialsSDK(), ent)
case *configurationv1alpha1.KongCACertificate:
return deleteCACertificate(ctx, sdk.GetCACertificatesSDK(), ent)
case *configurationv1alpha1.KongCertificate:
Expand Down Expand Up @@ -243,6 +247,8 @@ func Update[
return ctrl.Result{}, updateKongCredentialACL(ctx, sdk.GetACLCredentialsSDK(), ent)
case *configurationv1alpha1.KongCredentialJWT:
return ctrl.Result{}, updateKongCredentialJWT(ctx, sdk.GetJWTCredentialsSDK(), ent)
case *configurationv1alpha1.KongCredentialHMAC:
return ctrl.Result{}, updateKongCredentialHMAC(ctx, sdk.GetHMACCredentialsSDK(), ent)
case *configurationv1alpha1.KongCACertificate:
return ctrl.Result{}, updateCACertificate(ctx, sdk.GetCACertificatesSDK(), ent)
case *configurationv1alpha1.KongCertificate:
Expand Down
Loading

0 comments on commit 3b96e87

Please sign in to comment.