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"
"mstore/pkg/terms"
@@ -125,8 +126,8 @@ type CreateAccountParams struct {
NewPassword string
}
type CreateAccountResult struct {
AccountID string `yaml:"accountId"`
Grants map[string]string `yaml:"grantsIds,omitempty"`
AccountID auxuuid.UUID `yaml:"accountId"`
Grants map[auxuuid.UUID]string `yaml:"grantsIds,omitempty"`
}
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
@@ -140,7 +141,7 @@ func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
func (util *AccountUtil) createAccount(common *CommonAccountParams, params *CreateAccountParams) (*CreateAccountResult, error) {
var err error
res := &CreateAccountResult{
Grants: make(map[string]string, 0),
Grants: make(map[auxuuid.UUID]string, 0),
}
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
if err != nil {
@@ -202,7 +203,7 @@ func (util *AccountUtil) updateAccount(common *CommonAccountParams, params *Upda
re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID)
if re.MatchString(id) {
err = client.NewClient().UpdateAccountByID(ctx, hostname, id, params.NewUsername, params.NewPassword)
err = client.NewClient().UpdateAccountByID(ctx, hostname, auxuuid.UUID(id), params.NewUsername, params.NewPassword)
} else {
err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword)
}
@@ -243,7 +244,7 @@ func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAcco
re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID)
if re.MatchString(id) {
opRes, err = client.NewClient().GetAccountByID(ctx, hostname, id)
opRes, err = client.NewClient().GetAccountByID(ctx, hostname, auxuuid.UUID(id))
} else {
opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID)
}
@@ -280,7 +281,7 @@ func (util *AccountUtil) deleteAccount(common *CommonAccountParams, params *Dele
re := regexp.MustCompile(uuidRegex)
id := strings.ToLower(params.AccountID)
if re.MatchString(id) {
err = client.NewClient().DeleteAccountByID(ctx, hostname, id)
err = client.NewClient().DeleteAccountByID(ctx, hostname, auxuuid.UUID(id))
} else {
err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID)
}
@@ -298,9 +299,9 @@ type ListAccountsParams struct {
}
type Userinfo struct {
Username string `yaml:"username,omitempty"`
AccountID string `yaml:"accountId,omitempty"`
Rights map[string]string `yaml:"rights,omitempty"`
Username string `yaml:"username,omitempty"`
AccountID auxuuid.UUID `yaml:"accountId,omitempty"`
Rights map[auxuuid.UUID]string `yaml:"rights,omitempty"`
}
type ListAccountsResult struct {
@@ -349,7 +350,7 @@ func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListA
userinfo := Userinfo{
Username: account.Username,
AccountID: account.ID,
Rights: make(map[string]string, 0),
Rights: make(map[auxuuid.UUID]string, 0),
}
for _, grant := range account.Grants {
userinfo.Rights[grant.ID] = grant.Right