Skip to content

Commit

Permalink
fix: use custom type for export types
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Sep 17, 2024
1 parent 59cb302 commit d8cb183
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
18 changes: 14 additions & 4 deletions api/v1alpha1/nats_account_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ExportType defines the type of import/export.
type ExportType int

const (
// Unknown is used if we don't know the type
Unknown ExportType = iota
// Stream defines the type field value for a stream "stream"
Stream
// Service defines the type field value for a service "service"
Service
)

// Export ...
type Export struct {
Name string `json:"name,omitempty"`
Subject jwt.Subject `json:"subject,omitempty"`
Type jwt.ExportType `json:"type,omitempty"`
Type ExportType `json:"type,omitempty"`
TokenReq bool `json:"token_req,omitempty"`
Revocations jwt.RevocationList `json:"revocations,omitempty"`
ResponseType jwt.ResponseType `json:"response_type,omitempty"`
Expand Down Expand Up @@ -45,16 +57,14 @@ type NatsAccountSpec struct {
Exports []Export `json:"exports,omitempty"`
Limits OperatorLimits `json:"limits,omitempty"`
Revocations jwt.RevocationList `json:"revocations,omitempty"`

// FIXME: Scoped signing keys
}

func (s NatsAccountSpec) ToJWTAccount() jwt.Account {
exports := lo.Map(s.Exports, func(e Export, _ int) *jwt.Export {
return &jwt.Export{
Name: e.Name,
Subject: e.Subject,
Type: e.Type,
Type: jwt.ExportType(e.Type),
TokenReq: e.TokenReq,
Revocations: e.Revocations,
ResponseType: e.ResponseType,
Expand Down
7 changes: 5 additions & 2 deletions controllers/natsoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (r *NatsOperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request
{
Name: "account-monitoring-services",
Subject: "$SYS.REQ.ACCOUNT.*.*",
Type: jwt.Service,
Type: natsv1alpha1.Service,
ResponseType: jwt.ResponseTypeStream,
AccountTokenPosition: 4,
Info: jwt.Info{
Expand All @@ -112,7 +112,7 @@ func (r *NatsOperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request
{
Name: "account-monitoring-streams",
Subject: "$SYS.ACCOUNT.*.>",
Type: jwt.Stream,
Type: natsv1alpha1.Stream,
AccountTokenPosition: 3,
Info: jwt.Info{
Description: `Account specific monitoring stream`,
Expand All @@ -134,6 +134,9 @@ func (r *NatsOperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request
}

if err := r.Create(ctx, systemAccount); err != nil {
for _, e := range systemAccount.Spec.Exports {
logger.Info("export", "name", e.Name, "subject", e.Subject, "type", e.Type)
}
return ctrl.Result{}, err
}

Expand Down
1 change: 1 addition & 0 deletions helm/charts/natz-operator/templates/crds/natsaccounts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
type: array
exports:
items:
description: Export ...
properties:
account_token_position:
type: integer
Expand Down
1 change: 1 addition & 0 deletions manifests/crd/bases/natz.zeiss.com_natsaccounts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
type: array
exports:
items:
description: Export ...
properties:
account_token_position:
type: integer
Expand Down

0 comments on commit d8cb183

Please sign in to comment.