working commit

This commit is contained in:
2026-06-07 15:06:37 +02:00
parent 52dd2cef20
commit c656b562d8
17 changed files with 291 additions and 85 deletions
@@ -4,6 +4,9 @@
package grant
import (
"context"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"mbase/app/operator"
@@ -11,10 +14,11 @@ import (
type Util struct {
oper *operator.Logic
subCmd *cobra.Command
operID string
subCmd *cobra.Command
createGrantParams createGrantParams
deleteGrantParams deleteGrantParams
commonParams CommonParams
commonParams CommonParams
}
func NewUtil(oper *operator.Logic) *Util {
@@ -34,9 +38,10 @@ func (util *Util) GetRooCmd() *cobra.Command {
func (util *Util) BuildCmds() *cobra.Command {
subCmd := &cobra.Command{
Use: "grant",
Short: "\nGrant operations",
SilenceUsage: true,
Use: "grant",
Short: "\nGrant operations",
SilenceUsage: true,
PersistentPreRunE: util.ValidateOper,
}
subCmd.CompletionOptions.DisableDefaultCmd = true
@@ -51,9 +56,6 @@ func (util *Util) BuildCmds() *cobra.Command {
util.commonParams.Username = vi.GetString("user")
util.commonParams.Password = vi.GetString("pass")
var createGrantCmd = &cobra.Command{
Use: "create name|id password",
Short: "Create grant",
@@ -73,3 +75,15 @@ func (util *Util) BuildCmds() *cobra.Command {
util.subCmd = subCmd
return util.subCmd
}
func (util *Util) ValidateOper(cmd *cobra.Command, args []string) error {
var err error
ctx := context.Background()
authOk, operID, err := util.oper.ValidateAccount(ctx, util.commonParams.Username, util.commonParams.Password)
if !authOk {
err := fmt.Errorf("Authentification error")
return err
}
util.operID = operID
return err
}