working commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package grant
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"mbase/pkg/client"
|
||||
"mbase/pkg/mbctl"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) SetGrant(cmd *cobra.Command, args []string) {
|
||||
util.setGrantParams.Username = args[0]
|
||||
util.setGrantParams.Grantname = args[1]
|
||||
res, err := util.setGrant(util.setGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type SetGrantParams struct {
|
||||
Username string
|
||||
Grantname string
|
||||
}
|
||||
type SetGrantResult struct {
|
||||
GrantID string
|
||||
}
|
||||
|
||||
func (util *Util) setGrant(params SetGrantParams) (SetGrantResult, error) {
|
||||
var err error
|
||||
res := SetGrantResult{}
|
||||
|
||||
grpcConn, cli, err := client.NewClient(&util.access)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
defer grpcConn.Close()
|
||||
operParams := &mbctl.SetGrantParams{
|
||||
Username: params.Username,
|
||||
Grantname: params.Grantname,
|
||||
}
|
||||
ctx := context.Background()
|
||||
operRes, err := cli.SetGrant(ctx, operParams)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.GrantID = operRes.GrantID
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user