Skip to content

Commit

Permalink
fix: normalized user spec for comparison (#5)
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
  • Loading branch information
siredmar authored Jun 5, 2023
1 parent 5ec09ea commit d92edf9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
21 changes: 21 additions & 0 deletions apis/user/v1alpha1/normalize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v1alpha1

import "github.com/edgefarm/vault-plugin-secrets-nats/pkg/claims/user/v1alpha1"

func FixEmptySlices(params *v1alpha1.UserClaims) {
if params == nil {
return
}
if params.Permissions.Pub.Allow == nil {
params.Permissions.Pub.Allow = []string{}
}
if params.Permissions.Pub.Deny == nil {
params.Permissions.Pub.Deny = []string{}
}
if params.Permissions.Sub.Allow == nil {
params.Permissions.Sub.Allow = []string{}
}
if params.Permissions.Sub.Deny == nil {
params.Permissions.Sub.Deny = []string{}
}
}
21 changes: 1 addition & 20 deletions internal/clients/issue/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,12 @@ import (
v1alpha1 "github.com/edgefarm/provider-natssecrets/apis/user/v1alpha1"
vault "github.com/edgefarm/provider-natssecrets/internal/clients"
natsbackend "github.com/edgefarm/vault-plugin-secrets-nats"
vaultv1alpha1 "github.com/edgefarm/vault-plugin-secrets-nats/pkg/claims/user/v1alpha1"
)

func UserPath(mount string, operator string, account string, user string) string {
return mount + "/issue/operator/" + operator + "/account/" + account + "/user/" + user
}

func fixEmptySlices(params *vaultv1alpha1.UserClaims) {
if params == nil {
return
}
if params.Permissions.Pub.Allow == nil {
params.Permissions.Pub.Allow = []string{}
}
if params.Permissions.Pub.Deny == nil {
params.Permissions.Pub.Deny = []string{}
}
if params.Permissions.Sub.Allow == nil {
params.Permissions.Sub.Allow = []string{}
}
if params.Permissions.Sub.Deny == nil {
params.Permissions.Sub.Deny = []string{}
}
}

func ReadUser(c *vault.Client, operator string, account string, user string) (*v1alpha1.UserParameters, *natsbackend.IssueUserStatus, error) {
path := UserPath(c.Mount, operator, account, user)

Expand All @@ -39,7 +20,7 @@ func ReadUser(c *vault.Client, operator string, account string, user string) (*v
return nil, nil, err
}
if resp != nil {
fixEmptySlices(&resp.Claims)
v1alpha1.FixEmptySlices(&resp.Claims)
return &v1alpha1.UserParameters{
Operator: resp.Operator,
Account: resp.Account,
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
if !ok {
return managed.ExternalObservation{}, errors.New(errNotUser)
}

v1alpha1.FixEmptySlices(&cr.Spec.ForProvider.Claims)
user, err := getExternalName(cr)
if err != nil {
return managed.ExternalObservation{}, err
Expand Down

0 comments on commit d92edf9

Please sign in to comment.