From dda76dc0f1687216f21a5bd6f86ec2c6a947c99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Mon, 9 Mar 2026 10:54:41 +0200 Subject: [PATCH] mstorectl: replaced yaml tag to json --- cmd/mstorectl/accountcmd/createacc.go | 4 +- cmd/mstorectl/accountcmd/creategrant.go | 2 +- cmd/mstorectl/accountcmd/getacc.go | 2 +- cmd/mstorectl/accountcmd/getgrant.go | 2 +- cmd/mstorectl/accountcmd/grantcmd.go | 218 ------------------------ cmd/mstorectl/accountcmd/listacc.go | 10 +- cmd/mstorectl/accountcmd/listgrant.go | 4 +- cmd/mstorectl/accountcmd/updacc.go | 2 +- cmd/mstorectl/filecmd/expfiles.go | 4 +- cmd/mstorectl/filecmd/filecmd.go | 6 +- cmd/mstorectl/filecmd/fileinfo.go | 6 +- 11 files changed, 21 insertions(+), 239 deletions(-) diff --git a/cmd/mstorectl/accountcmd/createacc.go b/cmd/mstorectl/accountcmd/createacc.go index f87df74..f9d457e 100644 --- a/cmd/mstorectl/accountcmd/createacc.go +++ b/cmd/mstorectl/accountcmd/createacc.go @@ -25,8 +25,8 @@ type CreateAccountParams struct { NewPassword string } type CreateAccountResult struct { - AccountID string `yaml:"accountId"` - Grants map[string]string `yaml:"grantsIds,omitempty"` + AccountID string `json:"accountId"` + Grants map[string]string `json:"grantsIds,omitempty"` } func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) { diff --git a/cmd/mstorectl/accountcmd/creategrant.go b/cmd/mstorectl/accountcmd/creategrant.go index 4d0b516..4d235c2 100644 --- a/cmd/mstorectl/accountcmd/creategrant.go +++ b/cmd/mstorectl/accountcmd/creategrant.go @@ -27,7 +27,7 @@ type CreateGrantParams struct { Pattern string } type CreateGrantResult struct { - GrantID string `yaml:"grantId"` + GrantID string `json:"grantId"` } func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) { diff --git a/cmd/mstorectl/accountcmd/getacc.go b/cmd/mstorectl/accountcmd/getacc.go index 1bf549a..2ca959b 100644 --- a/cmd/mstorectl/accountcmd/getacc.go +++ b/cmd/mstorectl/accountcmd/getacc.go @@ -35,7 +35,7 @@ func (util *AccountUtil) GetAccount(cmd *cobra.Command, args []string) { } 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) { diff --git a/cmd/mstorectl/accountcmd/getgrant.go b/cmd/mstorectl/accountcmd/getgrant.go index 21c6f41..b34cb58 100644 --- a/cmd/mstorectl/accountcmd/getgrant.go +++ b/cmd/mstorectl/accountcmd/getgrant.go @@ -26,7 +26,7 @@ type GetGrantParams 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) { diff --git a/cmd/mstorectl/accountcmd/grantcmd.go b/cmd/mstorectl/accountcmd/grantcmd.go index e6b6fd3..be3fb0f 100644 --- a/cmd/mstorectl/accountcmd/grantcmd.go +++ b/cmd/mstorectl/accountcmd/grantcmd.go @@ -101,221 +101,3 @@ type CommonGrantParams struct { Timeout uint64 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 -} -*/ diff --git a/cmd/mstorectl/accountcmd/listacc.go b/cmd/mstorectl/accountcmd/listacc.go index a47e036..cd32d72 100644 --- a/cmd/mstorectl/accountcmd/listacc.go +++ b/cmd/mstorectl/accountcmd/listacc.go @@ -28,14 +28,14 @@ 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 `json:"username,omitempty"` + AccountID string `json:"accountId,omitempty"` + Rights map[string]string `json:"rights,omitempty"` } type ListAccountsResult struct { - Accounts []descr.AccountShort `yaml:"accounts,omitempty"` - Users []Userinfo `yaml:"users,omitempty"` + Accounts []descr.AccountShort `json:"accounts,omitempty"` + Users []Userinfo `json:"users,omitempty"` } func (util *AccountUtil) ListAccounts(cmd *cobra.Command, args []string) { diff --git a/cmd/mstorectl/accountcmd/listgrant.go b/cmd/mstorectl/accountcmd/listgrant.go index 923925d..ade8880 100644 --- a/cmd/mstorectl/accountcmd/listgrant.go +++ b/cmd/mstorectl/accountcmd/listgrant.go @@ -28,8 +28,8 @@ type ListGrantsParams struct { } type ListGrantsResult struct { - Grants []descr.Grant `yaml:"grants,omitempty"` - Rights map[string]string `yaml:"rights,omitempty"` + Grants []descr.Grant `json:"grants,omitempty"` + Rights map[string]string `json:"rights,omitempty"` } func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) { diff --git a/cmd/mstorectl/accountcmd/updacc.go b/cmd/mstorectl/accountcmd/updacc.go index 0aa47cf..bc4d491 100644 --- a/cmd/mstorectl/accountcmd/updacc.go +++ b/cmd/mstorectl/accountcmd/updacc.go @@ -29,7 +29,7 @@ type UpdateAccountParams struct { NewPassword string } type UpdateAccountResult struct { - File *descr.File `yaml:"file,omitempty"` + File *descr.File `json:"file,omitempty"` } func (util *AccountUtil) UpdateAccount(cmd *cobra.Command, args []string) { diff --git a/cmd/mstorectl/filecmd/expfiles.go b/cmd/mstorectl/filecmd/expfiles.go index 493d7ec..64687c3 100644 --- a/cmd/mstorectl/filecmd/expfiles.go +++ b/cmd/mstorectl/filecmd/expfiles.go @@ -35,8 +35,8 @@ type ExportFilesParams struct { } type ExportFilesResult struct { - Files []descr.File `yaml:"files,omitempty"` - Filenames []string `yaml:"filenames,omitempty"` + Files []descr.File `json:"files,omitempty"` + Filenames []string `json:"filenames,omitempty"` } func (util *FileUtil) ExportFiles(cmd *cobra.Command, args []string) { diff --git a/cmd/mstorectl/filecmd/filecmd.go b/cmd/mstorectl/filecmd/filecmd.go index 9ad60b5..f216419 100644 --- a/cmd/mstorectl/filecmd/filecmd.go +++ b/cmd/mstorectl/filecmd/filecmd.go @@ -177,9 +177,9 @@ type CommonFileParams struct { func printResponse(res any, err error) { type Response struct { - Error bool `json:"error" yaml:"error"` - Message string `json:"message,omitempty" yaml:"message,omitempty"` - Result any `json:"result,omitempty" yaml:"result,omitempty"` + Error bool `json:"error" json:"error"` + Message string `json:"message,omitempty" json:"message,omitempty"` + Result any `json:"result,omitempty" json:"result,omitempty"` } resp := Response{} if err != nil { diff --git a/cmd/mstorectl/filecmd/fileinfo.go b/cmd/mstorectl/filecmd/fileinfo.go index 7282b00..5eaed1f 100644 --- a/cmd/mstorectl/filecmd/fileinfo.go +++ b/cmd/mstorectl/filecmd/fileinfo.go @@ -25,9 +25,9 @@ type FileInfoParams struct { Filepath string } type FileInfoResult struct { - File *descr.File `yaml:"file,omitempty"` - Size int64 `yaml:"size,omitempty"` - Digest string `yaml:"digest,omitempty"` + File *descr.File `json:"file,omitempty"` + Size int64 `json:"size,omitempty"` + Digest string `json:"digest,omitempty"` } func (util *FileUtil) FileInfo(cmd *cobra.Command, args []string) {