working commit
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func (util *Util) CreateGrant(cmd *cobra.Command, args []string) {
|
||||
//util.createGrantParams.Filename = args[0]
|
||||
res, err := util.createGrant(util.createGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type createGrantParams struct{}
|
||||
type createGrantResult struct{}
|
||||
|
||||
func (util *Util) createGrant(params createGrantParams) (createGrantResult, error) {
|
||||
var err error
|
||||
res := createGrantResult{}
|
||||
return res, err
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
package grant
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
||||
*/
|
||||
package account
|
||||
package grant
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -4,13 +4,24 @@
|
||||
package grant
|
||||
|
||||
import (
|
||||
"mbase/pkg/client"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type CommonParams struct {
|
||||
Hostname string
|
||||
Port uint32
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
type Util struct {
|
||||
rootCmd *cobra.Command
|
||||
createGrantParams createGrantParams
|
||||
rootCmd *cobra.Command
|
||||
setGrantParams SetGrantParams
|
||||
deleteGrantParams deleteGrantParams
|
||||
commonParams CommonParams
|
||||
access client.Access
|
||||
}
|
||||
|
||||
func NewUtil() *Util {
|
||||
@@ -29,13 +40,13 @@ func (util *Util) BuildCmds() *cobra.Command {
|
||||
}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
var createGrantCmd = &cobra.Command{
|
||||
Use: "create name|id password",
|
||||
Short: "Create grant",
|
||||
var setGrantCmd = &cobra.Command{
|
||||
Use: "set name|id grant",
|
||||
Short: "Set grant",
|
||||
Args: cobra.ExactArgs(2),
|
||||
Run: util.CreateGrant,
|
||||
Run: util.SetGrant,
|
||||
}
|
||||
rootCmd.AddCommand(createGrantCmd)
|
||||
rootCmd.AddCommand(setGrantCmd)
|
||||
|
||||
var deleteGrantCmd = &cobra.Command{
|
||||
Use: "delete name|id grant",
|
||||
@@ -49,3 +60,11 @@ func (util *Util) BuildCmds() *cobra.Command {
|
||||
return util.rootCmd
|
||||
}
|
||||
|
||||
func (util *Util) SetAccess(cmd *cobra.Command, args []string) {
|
||||
util.access = client.Access{
|
||||
Hostname: util.commonParams.Hostname,
|
||||
Port: util.commonParams.Port,
|
||||
Username: util.commonParams.Username,
|
||||
Password: util.commonParams.Password,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user