working commit
This commit is contained in:
@@ -10,19 +10,11 @@
|
||||
package accountcmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"mstore/pkg/client"
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
|
||||
func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||
func (util *GrantUtil) MakeGrantCmds() *cobra.Command {
|
||||
var subCmd = &cobra.Command{
|
||||
Use: "grants",
|
||||
Short: "Grant operations",
|
||||
@@ -110,6 +102,7 @@ type CommonGrantParams struct {
|
||||
SkipTLSVerify bool
|
||||
}
|
||||
|
||||
/*
|
||||
// CreateGrant
|
||||
type CreateGrantParams struct {
|
||||
AccountID string
|
||||
@@ -132,24 +125,30 @@ func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
||||
func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGrantParams) (*CreateGrantResult, error) {
|
||||
var err error
|
||||
res := &CreateGrantResult{}
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
re := regexp.MustCompile(uuidRegex)
|
||||
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 operRes string
|
||||
var opres string
|
||||
if re.MatchString(id) {
|
||||
operRes, err = client.NewClient(common.SkipTLSVerify).CreateGrantByAccountID(ctx, hostname, id, params.Right, params.Pattern)
|
||||
opres, err = cli.CreateGrantByAccountID(ctx, ref.Host(), id, params.Right, params.Pattern)
|
||||
} else {
|
||||
operRes, err = client.NewClient(common.SkipTLSVerify).CreateGrantByUsername(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||
opres, err = cli.CreateGrantByUsername(ctx, ref.Host(), params.AccountID, params.Right, params.Pattern)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.GrantID = operRes
|
||||
res.GrantID = opres
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -171,14 +170,20 @@ func (util *GrantUtil) UpdateGrant(cmd *cobra.Command, args []string) {
|
||||
func (util *GrantUtil) updateGrant(common *CommonGrantParams, params *UpdateGrantParams) (*UpdateGrantResult, error) {
|
||||
var err error
|
||||
res := &UpdateGrantResult{}
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
|
||||
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
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
ref.SetUserinfo(common.Username, common.Password)
|
||||
mw := accntcli.NewBasicAuthMiddleware(ref.Userinfo())
|
||||
cli := accntcli.NewClient(nil, mw)
|
||||
|
||||
|
||||
id := strings.ToLower(params.GrantID)
|
||||
err = client.NewClient(common.SkipTLSVerify).UpdateGrant(ctx, hostname, id, params.Pattern)
|
||||
err = cli.UpdateGrant(ctx, ref.Host(), id, params.Pattern)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -205,20 +210,24 @@ func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
||||
func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParams) (*GetGrantResult, error) {
|
||||
var err error
|
||||
res := &GetGrantResult{}
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
opres := &descr.Grant{}
|
||||
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
opRes := &descr.Grant{}
|
||||
|
||||
id := strings.ToLower(params.GrantID)
|
||||
opRes, err = client.NewClient(common.SkipTLSVerify).GetGrant(ctx, hostname, id)
|
||||
ref, err := accntcli.ParseHostinfo(common.Hostname)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Grant = opRes
|
||||
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
|
||||
}
|
||||
|
||||
@@ -238,14 +247,19 @@ func (util *GrantUtil) DeleteGrant(cmd *cobra.Command, args []string) {
|
||||
func (util *GrantUtil) deleteGrant(common *CommonGrantParams, params *DeleteGrantParams) (*DeleteGrantResult, error) {
|
||||
var err error
|
||||
res := &DeleteGrantResult{}
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
|
||||
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
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
ref.SetUserinfo(common.Username, common.Password)
|
||||
mw := accntcli.NewBasicAuthMiddleware(ref.Userinfo())
|
||||
cli := accntcli.NewClient(nil, mw)
|
||||
|
||||
id := strings.ToLower(params.GrantID)
|
||||
err = client.NewClient(common.SkipTLSVerify).DeleteGrant(ctx, hostname, id)
|
||||
err = cli.DeleteGrant(ctx, ref.Host(), id)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -272,19 +286,24 @@ func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
||||
func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsParams) (*ListGrantsResult, error) {
|
||||
var err error
|
||||
res := &ListGrantsResult{}
|
||||
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||
|
||||
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
|
||||
}
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||
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 = client.NewClient(common.SkipTLSVerify).ListGrantsByAccountID(ctx, hostname, id)
|
||||
grants, err = cli.ListGrantsByAccountID(ctx, ref.Host(), id)
|
||||
} else {
|
||||
grants, err = client.NewClient(common.SkipTLSVerify).ListGrantsByUsername(ctx, hostname, params.AccountID)
|
||||
grants, err = cli.ListGrantsByUsername(ctx, ref.Host(), params.AccountID)
|
||||
}
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -299,3 +318,4 @@ func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsP
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user