working commit

This commit is contained in:
Олег Бородин
2026-05-26 09:58:10 +02:00
parent 315f69b123
commit a53197e432
17 changed files with 1057 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*/
package accountcmd
import (
"context"
"strings"
"time"
"github.com/spf13/cobra"
"mbase/pkg/accntcli"
"mbase/pkg/descr"
)
// GetGrant
type GetGrantParams struct {
GrantID string
}
type GetGrantResult struct {
Grant *descr.Grant `json:"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
}