mstorectl: replaced yaml tag to json
This commit is contained in:
@@ -25,8 +25,8 @@ type CreateAccountParams struct {
|
|||||||
NewPassword string
|
NewPassword string
|
||||||
}
|
}
|
||||||
type CreateAccountResult struct {
|
type CreateAccountResult struct {
|
||||||
AccountID string `yaml:"accountId"`
|
AccountID string `json:"accountId"`
|
||||||
Grants map[string]string `yaml:"grantsIds,omitempty"`
|
Grants map[string]string `json:"grantsIds,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type CreateGrantParams struct {
|
|||||||
Pattern string
|
Pattern string
|
||||||
}
|
}
|
||||||
type CreateGrantResult struct {
|
type CreateGrantResult struct {
|
||||||
GrantID string `yaml:"grantId"`
|
GrantID string `json:"grantId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func (util *AccountUtil) GetAccount(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetAccountResult struct {
|
type GetAccountResult struct {
|
||||||
Account *descr.AccountShort `yaml:"account,omitempty"`
|
Account *descr.AccountShort `json:"account,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAccountParams) (*GetAccountResult, error) {
|
func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAccountParams) (*GetAccountResult, error) {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type GetGrantParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetGrantResult struct {
|
type GetGrantResult struct {
|
||||||
Grant *descr.Grant `yaml:"grant,omitempty"`
|
Grant *descr.Grant `json:"grant,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -101,221 +101,3 @@ type CommonGrantParams struct {
|
|||||||
Timeout uint64
|
Timeout uint64
|
||||||
SkipTLSVerify bool
|
SkipTLSVerify bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// CreateGrant
|
|
||||||
type CreateGrantParams struct {
|
|
||||||
AccountID string
|
|
||||||
Right string
|
|
||||||
Pattern string
|
|
||||||
}
|
|
||||||
type CreateGrantResult struct {
|
|
||||||
GrantID string `yaml:"grantId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
|
||||||
util.commonGrantParams.Hostname = args[0]
|
|
||||||
util.createGrantParams.AccountID = args[1]
|
|
||||||
util.createGrantParams.Right = args[2]
|
|
||||||
util.createGrantParams.Pattern = args[3]
|
|
||||||
res, err := util.createGrant(&util.commonGrantParams, &util.createGrantParams)
|
|
||||||
printResponse(res, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGrantParams) (*CreateGrantResult, error) {
|
|
||||||
var err error
|
|
||||||
res := &CreateGrantResult{}
|
|
||||||
|
|
||||||
timeout := time.Duration(common.Timeout) * time.Second
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
|
||||||
ref, err := accntcli.ParseHostinfo(common.Hostname)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
ref.SetUserinfo(common.Username, common.Password)
|
|
||||||
mw := accntcli.NewBasicAuthMiddleware(ref.Userinfo())
|
|
||||||
cli := accntcli.NewClient(nil, mw)
|
|
||||||
|
|
||||||
|
|
||||||
re := regexp.MustCompile(uuidRegex)
|
|
||||||
id := strings.ToLower(params.AccountID)
|
|
||||||
var opres string
|
|
||||||
if re.MatchString(id) {
|
|
||||||
opres, err = cli.CreateGrantByAccountID(ctx, ref.Host(), id, params.Right, params.Pattern)
|
|
||||||
} else {
|
|
||||||
opres, err = cli.CreateGrantByUsername(ctx, ref.Host(), params.AccountID, params.Right, params.Pattern)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
res.GrantID = opres
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateGrant
|
|
||||||
type UpdateGrantParams struct {
|
|
||||||
GrantID string
|
|
||||||
Pattern string
|
|
||||||
}
|
|
||||||
type UpdateGrantResult struct{}
|
|
||||||
|
|
||||||
func (util *GrantUtil) UpdateGrant(cmd *cobra.Command, args []string) {
|
|
||||||
util.commonGrantParams.Hostname = args[0]
|
|
||||||
util.updateGrantParams.GrantID = args[1]
|
|
||||||
util.updateGrantParams.Pattern = args[2]
|
|
||||||
res, err := util.updateGrant(&util.commonGrantParams, &util.updateGrantParams)
|
|
||||||
printResponse(res, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (util *GrantUtil) updateGrant(common *CommonGrantParams, params *UpdateGrantParams) (*UpdateGrantResult, error) {
|
|
||||||
var err error
|
|
||||||
res := &UpdateGrantResult{}
|
|
||||||
|
|
||||||
timeout := time.Duration(common.Timeout) * time.Second
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
|
||||||
ref, err := accntcli.ParseHostinfo(common.Hostname)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
ref.SetUserinfo(common.Username, common.Password)
|
|
||||||
mw := accntcli.NewBasicAuthMiddleware(ref.Userinfo())
|
|
||||||
cli := accntcli.NewClient(nil, mw)
|
|
||||||
|
|
||||||
|
|
||||||
id := strings.ToLower(params.GrantID)
|
|
||||||
err = cli.UpdateGrant(ctx, ref.Host(), id, params.Pattern)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetGrant
|
|
||||||
type GetGrantParams struct {
|
|
||||||
GrantID string
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetGrantResult struct {
|
|
||||||
Grant *descr.Grant `yaml:"grant,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
|
||||||
util.commonGrantParams.Hostname = args[0]
|
|
||||||
util.getGrantParams.GrantID = args[1]
|
|
||||||
|
|
||||||
res, err := util.getGrant(&util.commonGrantParams, &util.getGrantParams)
|
|
||||||
printResponse(res, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParams) (*GetGrantResult, error) {
|
|
||||||
var err error
|
|
||||||
res := &GetGrantResult{}
|
|
||||||
opres := &descr.Grant{}
|
|
||||||
|
|
||||||
timeout := time.Duration(common.Timeout) * time.Second
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
|
||||||
ref, err := accntcli.ParseHostinfo(common.Hostname)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
ref.SetUserinfo(common.Username, common.Password)
|
|
||||||
mw := accntcli.NewBasicAuthMiddleware(ref.Userinfo())
|
|
||||||
cli := accntcli.NewClient(nil, mw)
|
|
||||||
|
|
||||||
id := strings.ToLower(params.GrantID)
|
|
||||||
opres, err = cli.GetGrant(ctx, ref.Host(), id)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
res.Grant = opres
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteGrant
|
|
||||||
type DeleteGrantParams struct {
|
|
||||||
GrantID string
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteGrantResult struct{}
|
|
||||||
|
|
||||||
func (util *GrantUtil) DeleteGrant(cmd *cobra.Command, args []string) {
|
|
||||||
util.commonGrantParams.Hostname = args[0]
|
|
||||||
util.deleteGrantParams.GrantID = args[1]
|
|
||||||
res, err := util.deleteGrant(&util.commonGrantParams, &util.deleteGrantParams)
|
|
||||||
printResponse(res, err)
|
|
||||||
}
|
|
||||||
func (util *GrantUtil) deleteGrant(common *CommonGrantParams, params *DeleteGrantParams) (*DeleteGrantResult, error) {
|
|
||||||
var err error
|
|
||||||
res := &DeleteGrantResult{}
|
|
||||||
|
|
||||||
timeout := time.Duration(common.Timeout) * time.Second
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
|
||||||
ref, err := accntcli.ParseHostinfo(common.Hostname)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
ref.SetUserinfo(common.Username, common.Password)
|
|
||||||
mw := accntcli.NewBasicAuthMiddleware(ref.Userinfo())
|
|
||||||
cli := accntcli.NewClient(nil, mw)
|
|
||||||
|
|
||||||
id := strings.ToLower(params.GrantID)
|
|
||||||
err = cli.DeleteGrant(ctx, ref.Host(), id)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListGrants
|
|
||||||
type ListGrantsParams struct {
|
|
||||||
Detail bool
|
|
||||||
AccountID string
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListGrantsResult struct {
|
|
||||||
Grants []descr.Grant `yaml:"grants,omitempty"`
|
|
||||||
Rights map[string]string `yaml:"rights,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
|
||||||
util.commonGrantParams.Hostname = args[0]
|
|
||||||
util.listGrantsParams.AccountID = args[1]
|
|
||||||
res, err := util.listGrants(&util.commonGrantParams, &util.listGrantsParams)
|
|
||||||
printResponse(res, err)
|
|
||||||
}
|
|
||||||
func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsParams) (*ListGrantsResult, error) {
|
|
||||||
var err error
|
|
||||||
res := &ListGrantsResult{}
|
|
||||||
|
|
||||||
timeout := time.Duration(common.Timeout) * time.Second
|
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
|
||||||
ref, err := accntcli.ParseHostinfo(common.Hostname)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
ref.SetUserinfo(common.Username, common.Password)
|
|
||||||
mw := accntcli.NewBasicAuthMiddleware(ref.Userinfo())
|
|
||||||
cli := accntcli.NewClient(nil, mw)
|
|
||||||
|
|
||||||
grants := make([]descr.Grant, 0)
|
|
||||||
re := regexp.MustCompile(uuidRegex)
|
|
||||||
id := strings.ToLower(params.AccountID)
|
|
||||||
if re.MatchString(id) {
|
|
||||||
grants, err = cli.ListGrantsByAccountID(ctx, ref.Host(), id)
|
|
||||||
} else {
|
|
||||||
grants, err = cli.ListGrantsByUsername(ctx, ref.Host(), params.AccountID)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
if params.Detail {
|
|
||||||
res.Grants = grants
|
|
||||||
} else {
|
|
||||||
res.Rights = make(map[string]string, 0)
|
|
||||||
for _, item := range grants {
|
|
||||||
res.Rights[item.ID] = item.Right
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ type ListAccountsParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Userinfo struct {
|
type Userinfo struct {
|
||||||
Username string `yaml:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
AccountID string `yaml:"accountId,omitempty"`
|
AccountID string `json:"accountId,omitempty"`
|
||||||
Rights map[string]string `yaml:"rights,omitempty"`
|
Rights map[string]string `json:"rights,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListAccountsResult struct {
|
type ListAccountsResult struct {
|
||||||
Accounts []descr.AccountShort `yaml:"accounts,omitempty"`
|
Accounts []descr.AccountShort `json:"accounts,omitempty"`
|
||||||
Users []Userinfo `yaml:"users,omitempty"`
|
Users []Userinfo `json:"users,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) ListAccounts(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) ListAccounts(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ type ListGrantsParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ListGrantsResult struct {
|
type ListGrantsResult struct {
|
||||||
Grants []descr.Grant `yaml:"grants,omitempty"`
|
Grants []descr.Grant `json:"grants,omitempty"`
|
||||||
Rights map[string]string `yaml:"rights,omitempty"`
|
Rights map[string]string `json:"rights,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type UpdateAccountParams struct {
|
|||||||
NewPassword string
|
NewPassword string
|
||||||
}
|
}
|
||||||
type UpdateAccountResult struct {
|
type UpdateAccountResult struct {
|
||||||
File *descr.File `yaml:"file,omitempty"`
|
File *descr.File `json:"file,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) UpdateAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) UpdateAccount(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ type ExportFilesParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ExportFilesResult struct {
|
type ExportFilesResult struct {
|
||||||
Files []descr.File `yaml:"files,omitempty"`
|
Files []descr.File `json:"files,omitempty"`
|
||||||
Filenames []string `yaml:"filenames,omitempty"`
|
Filenames []string `json:"filenames,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *FileUtil) ExportFiles(cmd *cobra.Command, args []string) {
|
func (util *FileUtil) ExportFiles(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -177,9 +177,9 @@ type CommonFileParams struct {
|
|||||||
|
|
||||||
func printResponse(res any, err error) {
|
func printResponse(res any, err error) {
|
||||||
type Response struct {
|
type Response struct {
|
||||||
Error bool `json:"error" yaml:"error"`
|
Error bool `json:"error" json:"error"`
|
||||||
Message string `json:"message,omitempty" yaml:"message,omitempty"`
|
Message string `json:"message,omitempty" json:"message,omitempty"`
|
||||||
Result any `json:"result,omitempty" yaml:"result,omitempty"`
|
Result any `json:"result,omitempty" json:"result,omitempty"`
|
||||||
}
|
}
|
||||||
resp := Response{}
|
resp := Response{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ type FileInfoParams struct {
|
|||||||
Filepath string
|
Filepath string
|
||||||
}
|
}
|
||||||
type FileInfoResult struct {
|
type FileInfoResult struct {
|
||||||
File *descr.File `yaml:"file,omitempty"`
|
File *descr.File `json:"file,omitempty"`
|
||||||
Size int64 `yaml:"size,omitempty"`
|
Size int64 `json:"size,omitempty"`
|
||||||
Digest string `yaml:"digest,omitempty"`
|
Digest string `json:"digest,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *FileUtil) FileInfo(cmd *cobra.Command, args []string) {
|
func (util *FileUtil) FileInfo(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user