44 lines
972 B
Go
44 lines
972 B
Go
/*
|
|
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
|
|
*/
|
|
package account
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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 `json:"accountId"`
|
|
}
|
|
|
|
func (util *Util) createAccount(params *CreateAccountParams) (*CreateAccountResult, error) {
|
|
var err error
|
|
res := &CreateAccountResult{}
|
|
ctx := context.Background()
|
|
operParams := &mbctl.CreateAccountParams{
|
|
Username: params.Username,
|
|
Password: params.Password,
|
|
}
|
|
operRes, err := util.oper.CreateAccount(ctx, util.operID, operParams)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
res.AccountID = operRes.AccountID
|
|
return res, err
|
|
}
|