right type used
This commit is contained in:
+12
-12
@@ -18,10 +18,10 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/client"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/terms"
|
||||
"mstore/pkg/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -126,8 +126,8 @@ type CreateAccountParams struct {
|
||||
NewPassword string
|
||||
}
|
||||
type CreateAccountResult struct {
|
||||
AccountID auxuuid.UUID `yaml:"accountId"`
|
||||
Grants map[auxuuid.UUID]string `yaml:"grantsIds,omitempty"`
|
||||
AccountID uuid.UUID `yaml:"accountId"`
|
||||
Grants map[uuid.UUID]terms.Right `yaml:"grantsIds,omitempty"`
|
||||
}
|
||||
|
||||
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
||||
@@ -141,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[auxuuid.UUID]string, 0),
|
||||
Grants: make(map[uuid.UUID]terms.Right, 0),
|
||||
}
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
@@ -154,7 +154,7 @@ func (util *AccountUtil) createAccount(common *CommonAccountParams, params *Crea
|
||||
return res, err
|
||||
}
|
||||
|
||||
fullRights := []string{
|
||||
fullRights := []terms.Right{
|
||||
terms.RightWriteAccounts,
|
||||
terms.RightReadAccounts,
|
||||
terms.RightWriteFiles,
|
||||
@@ -203,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, auxuuid.UUID(id), params.NewUsername, params.NewPassword)
|
||||
err = client.NewClient().UpdateAccountByID(ctx, hostname, uuid.UUID(id), params.NewUsername, params.NewPassword)
|
||||
} else {
|
||||
err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword)
|
||||
}
|
||||
@@ -244,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, auxuuid.UUID(id))
|
||||
opRes, err = client.NewClient().GetAccountByID(ctx, hostname, uuid.UUID(id))
|
||||
} else {
|
||||
opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID)
|
||||
}
|
||||
@@ -281,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, auxuuid.UUID(id))
|
||||
err = client.NewClient().DeleteAccountByID(ctx, hostname, uuid.UUID(id))
|
||||
} else {
|
||||
err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID)
|
||||
}
|
||||
@@ -299,9 +299,9 @@ type ListAccountsParams struct {
|
||||
}
|
||||
|
||||
type Userinfo struct {
|
||||
Username string `yaml:"username,omitempty"`
|
||||
AccountID auxuuid.UUID `yaml:"accountId,omitempty"`
|
||||
Rights map[auxuuid.UUID]string `yaml:"rights,omitempty"`
|
||||
Username string `yaml:"username,omitempty"`
|
||||
AccountID uuid.UUID `yaml:"accountId,omitempty"`
|
||||
Rights map[uuid.UUID]terms.Right `yaml:"rights,omitempty"`
|
||||
}
|
||||
|
||||
type ListAccountsResult struct {
|
||||
@@ -350,7 +350,7 @@ func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListA
|
||||
userinfo := Userinfo{
|
||||
Username: account.Username,
|
||||
AccountID: account.ID,
|
||||
Rights: make(map[auxuuid.UUID]string, 0),
|
||||
Rights: make(map[uuid.UUID]terms.Right, 0),
|
||||
}
|
||||
for _, grant := range account.Grants {
|
||||
userinfo.Rights[grant.ID] = grant.Right
|
||||
|
||||
+13
-12
@@ -18,9 +18,10 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"mstore/pkg/auxuuid"
|
||||
"mstore/pkg/client"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/terms"
|
||||
"mstore/pkg/uuid"
|
||||
)
|
||||
|
||||
func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||
@@ -116,7 +117,7 @@ type CreateGrantParams struct {
|
||||
Pattern string
|
||||
}
|
||||
type CreateGrantResult struct {
|
||||
GrantID auxuuid.UUID `yaml:"grantId"`
|
||||
GrantID uuid.UUID `yaml:"grantId"`
|
||||
}
|
||||
|
||||
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
||||
@@ -139,11 +140,11 @@ 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 auxuuid.UUID
|
||||
var operRes uuid.UUID
|
||||
if re.MatchString(id) {
|
||||
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, auxuuid.UUID(id), params.Right, params.Pattern)
|
||||
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, uuid.UUID(id), terms.Right(params.Right), params.Pattern)
|
||||
} else {
|
||||
operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||
operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, terms.Right(params.Right), params.Pattern)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -177,7 +178,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, auxuuid.UUID(id), params.Pattern)
|
||||
err = client.NewClient().UpdateGrant(ctx, hostname, uuid.UUID(id), params.Pattern)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -213,7 +214,7 @@ func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParam
|
||||
opRes := &descr.Grant{}
|
||||
|
||||
id := strings.ToLower(params.GrantID)
|
||||
opRes, err = client.NewClient().GetGrant(ctx, hostname, auxuuid.UUID(id))
|
||||
opRes, err = client.NewClient().GetGrant(ctx, hostname, uuid.UUID(id))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -244,7 +245,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, auxuuid.UUID(id))
|
||||
err = client.NewClient().DeleteGrant(ctx, hostname, uuid.UUID(id))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -258,8 +259,8 @@ type ListGrantsParams struct {
|
||||
}
|
||||
|
||||
type ListGrantsResult struct {
|
||||
Grants []descr.Grant `yaml:"grants,omitempty"`
|
||||
Rights map[auxuuid.UUID]string `yaml:"rights,omitempty"`
|
||||
Grants []descr.Grant `yaml:"grants,omitempty"`
|
||||
Rights map[uuid.UUID]terms.Right `yaml:"rights,omitempty"`
|
||||
}
|
||||
|
||||
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
||||
@@ -281,7 +282,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, auxuuid.UUID(id))
|
||||
grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, uuid.UUID(id))
|
||||
} else {
|
||||
grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID)
|
||||
}
|
||||
@@ -291,7 +292,7 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
|
||||
if params.Detail {
|
||||
res.Grants = grants
|
||||
} else {
|
||||
res.Rights = make(map[auxuuid.UUID]string, 0)
|
||||
res.Rights = make(map[uuid.UUID]terms.Right, 0)
|
||||
for _, item := range grants {
|
||||
res.Rights[item.ID] = item.Right
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user