working commit
This commit is contained in:
+11
-12
@@ -21,7 +21,6 @@ import (
|
||||
"mstore/pkg/client"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/term"
|
||||
"mstore/pkg/auxid"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -126,8 +125,8 @@ type CreateAccountParams struct {
|
||||
NewPassword string
|
||||
}
|
||||
type CreateAccountResult struct {
|
||||
AccountID uint64 `yaml:"accountId"`
|
||||
Grants map[uint64]term.Right `yaml:"grantsIds,omitempty"`
|
||||
AccountID string `yaml:"accountId"`
|
||||
Grants map[string]string `yaml:"grantsIds,omitempty"`
|
||||
}
|
||||
|
||||
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
||||
@@ -141,7 +140,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[uint64]term.Right, 0),
|
||||
Grants: make(map[string]string, 0),
|
||||
}
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
@@ -154,7 +153,7 @@ func (util *AccountUtil) createAccount(common *CommonAccountParams, params *Crea
|
||||
return res, err
|
||||
}
|
||||
|
||||
fullRights := []term.Right{
|
||||
fullRights := []string{
|
||||
term.RightWriteAccounts,
|
||||
term.RightReadAccounts,
|
||||
term.RightWriteFiles,
|
||||
@@ -203,7 +202,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, uint64(id), params.NewUsername, params.NewPassword)
|
||||
err = client.NewClient().UpdateAccountByID(ctx, hostname, id, params.NewUsername, params.NewPassword)
|
||||
} else {
|
||||
err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword)
|
||||
}
|
||||
@@ -244,7 +243,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, uint64(id))
|
||||
opRes, err = client.NewClient().GetAccountByID(ctx, hostname, id)
|
||||
} else {
|
||||
opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID)
|
||||
}
|
||||
@@ -281,7 +280,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, uint64(id))
|
||||
err = client.NewClient().DeleteAccountByID(ctx, hostname, id)
|
||||
} else {
|
||||
err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID)
|
||||
}
|
||||
@@ -299,9 +298,9 @@ type ListAccountsParams struct {
|
||||
}
|
||||
|
||||
type Userinfo struct {
|
||||
Username string `yaml:"username,omitempty"`
|
||||
AccountID uint64 `yaml:"accountId,omitempty"`
|
||||
Rights map[uint64]term.Right `yaml:"rights,omitempty"`
|
||||
Username string `yaml:"username,omitempty"`
|
||||
AccountID string `yaml:"accountId,omitempty"`
|
||||
Rights map[string]string `yaml:"rights,omitempty"`
|
||||
}
|
||||
|
||||
type ListAccountsResult struct {
|
||||
@@ -350,7 +349,7 @@ func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListA
|
||||
userinfo := Userinfo{
|
||||
Username: account.Username,
|
||||
AccountID: account.ID,
|
||||
Rights: make(map[uint64]term.Right, 0),
|
||||
Rights: make(map[string]string, 0),
|
||||
}
|
||||
for _, grant := range account.Grants {
|
||||
userinfo.Rights[grant.ID] = grant.Right
|
||||
|
||||
+19
-19
@@ -338,18 +338,18 @@ func (util *FileUtil) listFiles(common *CommonFileParams, params *ListFilesParam
|
||||
if params.AsRegexp {
|
||||
params.AsPrefix = false
|
||||
}
|
||||
var pathAs term.PathUsage
|
||||
var pathUsage string
|
||||
switch {
|
||||
case params.AsRegexp:
|
||||
pathAs = term.AsRegexp
|
||||
pathUsage = term.AsRegexp
|
||||
case params.AsPrefix:
|
||||
pathAs = term.AsPrefix
|
||||
pathUsage = term.AsPrefix
|
||||
default:
|
||||
pathAs = term.AsFinePath
|
||||
pathUsage = term.AsFinePath
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath, pathAs)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath, pathUsage)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -464,18 +464,18 @@ func (util *FileUtil) exportFiles(common *CommonFileParams, params *ExportFilesP
|
||||
if params.AsRegexp {
|
||||
params.AsPrefix = false
|
||||
}
|
||||
var pathAs term.PathUsage
|
||||
var pathUsage string
|
||||
switch {
|
||||
case params.AsRegexp:
|
||||
pathAs = term.AsRegexp
|
||||
pathUsage = term.AsRegexp
|
||||
case params.AsPrefix:
|
||||
pathAs = term.AsPrefix
|
||||
pathUsage = term.AsPrefix
|
||||
default:
|
||||
pathAs = term.AsFinePath
|
||||
pathUsage = term.AsFinePath
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath, pathAs)
|
||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath, pathUsage)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -553,18 +553,18 @@ func (util *FileUtil) listCollections(common *CommonFileParams, params *ListColl
|
||||
if params.AsRegexp {
|
||||
params.AsPrefix = false
|
||||
}
|
||||
var pathAs term.PathUsage
|
||||
var pathUsage string
|
||||
switch {
|
||||
case params.AsRegexp:
|
||||
pathAs = term.AsRegexp
|
||||
pathUsage = term.AsRegexp
|
||||
case params.AsPrefix:
|
||||
pathAs = term.AsPrefix
|
||||
pathUsage = term.AsPrefix
|
||||
default:
|
||||
pathAs = term.AsFinePath
|
||||
pathUsage = term.AsFinePath
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
collecions, err := client.NewClient().ListCollections(ctx, params.Path, pathAs)
|
||||
collecions, err := client.NewClient().ListCollections(ctx, params.Path, pathUsage)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -603,14 +603,14 @@ func (util *FileUtil) deleteCollection(common *CommonFileParams, params *DeleteC
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
var pathAs term.PathUsage
|
||||
var pathUsage string
|
||||
switch {
|
||||
case params.AsPrefix:
|
||||
pathAs = term.AsPrefix
|
||||
pathUsage = term.AsPrefix
|
||||
default:
|
||||
pathAs = term.AsFinePath
|
||||
pathUsage = term.AsFinePath
|
||||
}
|
||||
files, err := client.NewClient().DeleteCollection(ctx, params.Path, pathAs, params.DryRun)
|
||||
files, err := client.NewClient().DeleteCollection(ctx, params.Path, pathUsage, params.DryRun)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
+11
-13
@@ -20,8 +20,6 @@ import (
|
||||
|
||||
"mstore/pkg/client"
|
||||
"mstore/pkg/descr"
|
||||
"mstore/pkg/term"
|
||||
"mstore/pkg/auxid"
|
||||
)
|
||||
|
||||
func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||
@@ -117,7 +115,7 @@ type CreateGrantParams struct {
|
||||
Pattern string
|
||||
}
|
||||
type CreateGrantResult struct {
|
||||
GrantID uint64 `yaml:"grantId"`
|
||||
GrantID string `yaml:"grantId"`
|
||||
}
|
||||
|
||||
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
||||
@@ -140,11 +138,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 uint64
|
||||
var operRes string
|
||||
if re.MatchString(id) {
|
||||
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, uint64(id), term.Right(params.Right), params.Pattern)
|
||||
operRes, err = client.NewClient().CreateGrantByAccountID(ctx, hostname, id, params.Right, params.Pattern)
|
||||
} else {
|
||||
operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, term.Right(params.Right), params.Pattern)
|
||||
operRes, err = client.NewClient().CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -178,7 +176,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, uint64(id), params.Pattern)
|
||||
err = client.NewClient().UpdateGrant(ctx, hostname, id, params.Pattern)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -214,7 +212,7 @@ func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParam
|
||||
opRes := &descr.Grant{}
|
||||
|
||||
id := strings.ToLower(params.GrantID)
|
||||
opRes, err = client.NewClient().GetGrant(ctx, hostname, uint64(id))
|
||||
opRes, err = client.NewClient().GetGrant(ctx, hostname, id)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -245,7 +243,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, uint64(id))
|
||||
err = client.NewClient().DeleteGrant(ctx, hostname, id)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -259,8 +257,8 @@ type ListGrantsParams struct {
|
||||
}
|
||||
|
||||
type ListGrantsResult struct {
|
||||
Grants []descr.Grant `yaml:"grants,omitempty"`
|
||||
Rights map[uint64]term.Right `yaml:"rights,omitempty"`
|
||||
Grants []descr.Grant `yaml:"grants,omitempty"`
|
||||
Rights map[string]string `yaml:"rights,omitempty"`
|
||||
}
|
||||
|
||||
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
||||
@@ -282,7 +280,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, uint64(id))
|
||||
grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, id)
|
||||
} else {
|
||||
grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID)
|
||||
}
|
||||
@@ -292,7 +290,7 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
|
||||
if params.Detail {
|
||||
res.Grants = grants
|
||||
} else {
|
||||
res.Rights = make(map[uint64]term.Right, 0)
|
||||
res.Rights = make(map[string]string, 0)
|
||||
for _, item := range grants {
|
||||
res.Rights[item.ID] = item.Right
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user