uuid used

This commit is contained in:
2026-02-20 15:06:15 +02:00
parent 35e83ed705
commit 8546ad496f
31 changed files with 265 additions and 238 deletions
+11 -10
View File
@@ -18,6 +18,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"mstore/pkg/auxuuid"
"mstore/pkg/client"
"mstore/pkg/descr"
)
@@ -115,7 +116,7 @@ type CreateGrantParams struct {
Pattern string
}
type CreateGrantResult struct {
GrantID string `yaml:"grantId"`
GrantID auxuuid.UUID `yaml:"grantId"`
}
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
@@ -138,9 +139,9 @@ func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGran
ctx, _ := context.WithTimeout(context.Background(), timeout)
re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID)
var operRes string
var operRes auxuuid.UUID
if re.MatchString(id) {
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, params.AccountID, params.Right, params.Pattern)
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, auxuuid.UUID(id), params.Right, params.Pattern)
} else {
operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern)
}
@@ -176,7 +177,7 @@ func (util *GrantUtil) updateGrant(common *CommonGrantParams, params *UpdateGran
timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout)
id := strings.ToLower(params.GrantID)
err = client.NewClient().UpdateGrant(ctx, hostname, id, params.Pattern)
err = client.NewClient().UpdateGrant(ctx, hostname, auxuuid.UUID(id), params.Pattern)
if err != nil {
return res, err
}
@@ -212,7 +213,7 @@ func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParam
opRes := &descr.Grant{}
id := strings.ToLower(params.GrantID)
opRes, err = client.NewClient().GetGrant(ctx, hostname, id)
opRes, err = client.NewClient().GetGrant(ctx, hostname, auxuuid.UUID(id))
if err != nil {
return res, err
}
@@ -243,7 +244,7 @@ func (util *GrantUtil) deleteGrant(common *CommonGrantParams, params *DeleteGran
timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout)
id := strings.ToLower(params.GrantID)
err = client.NewClient().DeleteGrant(ctx, hostname, id)
err = client.NewClient().DeleteGrant(ctx, hostname, auxuuid.UUID(id))
if err != nil {
return res, err
}
@@ -257,8 +258,8 @@ type ListGrantsParams struct {
}
type ListGrantsResult struct {
Grants []descr.Grant `yaml:"grants,omitempty"`
Rights map[string]string `yaml:"rights,omitempty"`
Grants []descr.Grant `yaml:"grants,omitempty"`
Rights map[auxuuid.UUID]string `yaml:"rights,omitempty"`
}
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
@@ -280,7 +281,7 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID)
if re.MatchString(id) {
grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, params.AccountID)
grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, auxuuid.UUID(id))
} else {
grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID)
}
@@ -290,7 +291,7 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
if params.Detail {
res.Grants = grants
} else {
res.Rights = make(map[string]string, 0)
res.Rights = make(map[auxuuid.UUID]string, 0)
for _, item := range grants {
res.Rights[item.ID] = item.Right
}