working commit

This commit is contained in:
2026-06-08 09:42:32 +02:00
parent 0506b35cd1
commit 5f16f33a8b
21 changed files with 786 additions and 114 deletions
+2 -6
View File
@@ -13,10 +13,6 @@ import (
"github.com/spf13/viper"
)
const (
defaultHostname = "localhost:1025"
)
type Util struct {
oper *operator.Operator
subCmd *cobra.Command
@@ -84,8 +80,8 @@ func (util *Util) BuildCmds() *cobra.Command {
Args: cobra.ExactArgs(1),
Run: util.UpdateAccount,
}
updateAccountsCmd.Flags().StringVarP(&util.updateAccountParams.Password, "newpass", "N", util.updateAccountParams.Password, "New password")
updateAccountsCmd.Flags().StringVarP(&util.updateAccountParams.Username, "newname", "M", util.updateAccountParams.Username, "New username")
updateAccountsCmd.Flags().StringVarP(&util.updateAccountParams.NewPassword, "newpass", "N", util.updateAccountParams.NewPassword, "New password")
updateAccountsCmd.Flags().StringVarP(&util.updateAccountParams.NewUsername, "newname", "M", util.updateAccountParams.NewUsername, "New username")
updateAccountsCmd.MarkFlagsOneRequired("newpass", "newname")
subCmd.AddCommand(updateAccountsCmd)
+6 -4
View File
@@ -18,8 +18,9 @@ func (util *Util) UpdateAccount(cmd *cobra.Command, args []string) {
}
type UpdateAccountParams struct {
Username string
Password string
Username string
NewPassword string
NewUsername string
}
type UpdateAccountResult struct {
AccountID string
@@ -30,8 +31,9 @@ func (util *Util) updateAccount(params *UpdateAccountParams) (*UpdateAccountResu
res := &UpdateAccountResult{}
ctx := context.Background()
operParams := &mbctl.UpdateAccountParams{
Username: params.Username,
//Password: params.Password,
Username: params.Username,
NewPassword: params.NewPassword,
NewUsername: params.NewUsername,
}
_, err = util.oper.UpdateAccount(ctx, util.operID, operParams)
if err != nil {
+3 -6
View File
@@ -22,22 +22,19 @@ type DeleteGrantParams struct {
Username string
Operation string
}
type DeleteGrantResult struct {
GrantID string `json:"grantId"`
}
type DeleteGrantResult struct{}
func (util *Util) deleteGrant(params *DeleteGrantParams) (*DeleteGrantResult, error) {
var err error
res := &DeleteGrantResult{}
ctx := context.Background()
operParams := &mbctl.SetGrantParams{
operParams := &mbctl.DeleteGrantParams{
Username: params.Username,
Operation: params.Operation,
}
operRes, err := util.oper.SetGrant(ctx, util.operID, operParams)
_, err = util.oper.DeleteGrant(ctx, util.operID, operParams)
if err != nil {
return res, err
}
res.GrantID = operRes.GrantID
return res, err
}
+3 -3
View File
@@ -57,7 +57,7 @@ func (util *Util) BuildCmds() *cobra.Command {
util.commonParams.Password = vi.GetString("pass")
var setGrantCmd = &cobra.Command{
Use: "set name|id password",
Use: "set username grant",
Short: "Set grant for account",
Args: cobra.ExactArgs(2),
Run: util.SetGrant,
@@ -65,9 +65,9 @@ func (util *Util) BuildCmds() *cobra.Command {
subCmd.AddCommand(setGrantCmd)
var deleteGrantCmd = &cobra.Command{
Use: "delete name|id grant",
Use: "delete username|id grant",
Short: "Delete grant for account",
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(2),
Run: util.DeleteGrant,
}
subCmd.AddCommand(deleteGrantCmd)