51 lines
1.0 KiB
Go
51 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) CreateAccount(cmd *cobra.Command, args []string) {
|
|
util.createAccountParams.Username = args[0]
|
|
util.createAccountParams.Password = args[1]
|
|
res, err := util.createAccount(util.createAccountParams)
|
|
printResponse(res, err)
|
|
}
|
|
|
|
type CreateAccountParams struct {
|
|
Username string
|
|
Password string
|
|
}
|
|
type CreateAccountResult struct {
|
|
AccountID string
|
|
}
|
|
|
|
func (util *Util) createAccount(params CreateAccountParams) (CreateAccountResult, error) {
|
|
var err error
|
|
res := CreateAccountResult{}
|
|
|
|
grpcConn, cli, err := client.NewClient(&util.access)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
defer grpcConn.Close()
|
|
operParams := &mbctl.CreateAccountParams{
|
|
Username: params.Username,
|
|
Password: params.Password,
|
|
}
|
|
ctx := context.Background()
|
|
operRes, err := cli.CreateAccount(ctx, operParams)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
res.AccountID = operRes.AccountID
|
|
return res, err
|
|
}
|