49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
/*
|
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
|
*/
|
|
package account
|
|
|
|
import (
|
|
"context"
|
|
|
|
"mbase/pkg/client"
|
|
"mbase/pkg/mbctl"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func (util *Util) UpdateAccount(cmd *cobra.Command, args []string) {
|
|
util.updateAccountParams.Username = args[0]
|
|
res, err := util.updateAccount(util.updateAccountParams)
|
|
printResponse(res, err)
|
|
}
|
|
|
|
type UpdateAccountParams struct {
|
|
Username string
|
|
NewUsername string
|
|
NewPassword string
|
|
}
|
|
type UpdateAccountResult struct{}
|
|
|
|
func (util *Util) updateAccount(params UpdateAccountParams) (UpdateAccountResult, error) {
|
|
var err error
|
|
res := UpdateAccountResult{}
|
|
|
|
grpcConn, cli, err := client.NewClient(&util.access)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
defer grpcConn.Close()
|
|
operParams := &mbctl.UpdateAccountParams{
|
|
Username: params.Username,
|
|
NewPassword: params.NewPassword,
|
|
NewUsername: params.NewUsername,
|
|
}
|
|
ctx := context.Background()
|
|
_, err = cli.UpdateAccount(ctx, operParams)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
return res, err
|
|
}
|