mstorectl: replaced yaml tag to json
This commit is contained in:
@@ -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
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user