working commit
This commit is contained in:
@@ -13,14 +13,14 @@ import (
|
||||
|
||||
func (util *Util) DeleteGrant(cmd *cobra.Command, args []string) {
|
||||
util.deleteGrantParams.Username = args[0]
|
||||
util.deleteGrantParams.Operation = args[1]
|
||||
util.deleteGrantParams.Grantname = args[1]
|
||||
res, err := util.deleteGrant(&util.deleteGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type DeleteGrantParams struct {
|
||||
Username string
|
||||
Operation string
|
||||
Grantname string
|
||||
}
|
||||
type DeleteGrantResult struct{}
|
||||
|
||||
@@ -30,7 +30,7 @@ func (util *Util) deleteGrant(params *DeleteGrantParams) (*DeleteGrantResult, er
|
||||
ctx := context.Background()
|
||||
operParams := &mbctl.DeleteGrantParams{
|
||||
Username: params.Username,
|
||||
Operation: params.Operation,
|
||||
Grantname: params.Grantname,
|
||||
}
|
||||
_, err = util.oper.DeleteGrant(ctx, util.operID, operParams)
|
||||
if err != nil {
|
||||
|
||||
@@ -13,14 +13,14 @@ import (
|
||||
|
||||
func (util *Util) SetGrant(cmd *cobra.Command, args []string) {
|
||||
util.setGrantParams.Username = args[0]
|
||||
util.setGrantParams.Operation = args[1]
|
||||
util.setGrantParams.Grantname = args[1]
|
||||
res, err := util.setGrant(&util.setGrantParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
type SetGrantParams struct {
|
||||
Username string
|
||||
Operation string
|
||||
Grantname string
|
||||
}
|
||||
type SetGrantResult struct {
|
||||
GrantID string `json:"grantId"`
|
||||
@@ -32,7 +32,7 @@ func (util *Util) setGrant(params *SetGrantParams) (*SetGrantResult, error) {
|
||||
ctx := context.Background()
|
||||
operParams := &mbctl.SetGrantParams{
|
||||
Username: params.Username,
|
||||
Operation: params.Operation,
|
||||
Grantname: params.Grantname,
|
||||
}
|
||||
operRes, err := util.oper.SetGrant(ctx, util.operID, operParams)
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCert(t *testing.T) {
|
||||
var err error
|
||||
util := NewUtil()
|
||||
|
||||
err = util.Build()
|
||||
require.NoError(t, err)
|
||||
|
||||
args := []string{"seed"}
|
||||
err = util.Exec(args)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (util *Util) Build() error {
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
var dumpDatabaseCmd = &cobra.Command{
|
||||
Use: "dump [filename|-]",
|
||||
Use: "dump filename|-",
|
||||
Short: "Dump application database",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.DumpDatabase,
|
||||
@@ -43,7 +43,7 @@ func (util *Util) Build() error {
|
||||
rootCmd.AddCommand(dumpDatabaseCmd)
|
||||
|
||||
var restoreDatabaseCmd = &cobra.Command{
|
||||
Use: "restore [] [filename|-]",
|
||||
Use: "restore filename|-",
|
||||
Short: "Restore application database",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.RestoreDatabase,
|
||||
|
||||
Reference in New Issue
Block a user