This commit is contained in:
Michael Quigley 2022-08-10 15:24:12 -04:00
parent 1d655a2b0d
commit 7f2afc13cd
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 48 additions and 37 deletions

View File

@ -21,11 +21,11 @@ func newControllerCommand() *controllerCommand {
Aliases: []string{"ctrl"}, Aliases: []string{"ctrl"},
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
} }
ccmd := &controllerCommand{ command := &controllerCommand{
cmd: cmd, cmd: cmd,
} }
cmd.Run = ccmd.run cmd.Run = command.run
return ccmd return command
} }
func (cmd *controllerCommand) run(_ *cobra.Command, args []string) { func (cmd *controllerCommand) run(_ *cobra.Command, args []string) {

View File

@ -9,7 +9,7 @@ import (
) )
func init() { func init() {
createCmd.AddCommand(createAccountCmd) createCmd.AddCommand(newCreateAccountCommand().cmd)
rootCmd.AddCommand(createCmd) rootCmd.AddCommand(createCmd)
} }
@ -18,37 +18,48 @@ var createCmd = &cobra.Command{
Short: "Create objects", Short: "Create objects",
} }
var createAccountCmd = &cobra.Command{ type createAccountCommand struct {
Use: "account", cmd *cobra.Command
Short: "create new zrok account", }
Run: func(_ *cobra.Command, _ []string) {
username, err := term.Prompt("New Username: ") func newCreateAccountCommand() *createAccountCommand {
if err != nil { cmd := &cobra.Command{
panic(err) Use: "account",
} Short: "Create new zrok account",
password, err := term.PromptPassword("New Password: ", false) Args: cobra.ExactArgs(0),
if err != nil { }
panic(err) command := &createAccountCommand{cmd: cmd}
} cmd.Run = command.run
confirm, err := term.PromptPassword("Confirm Password: ", false) return command
if err != nil { }
panic(err)
} func (cmd *createAccountCommand) run(_ *cobra.Command, _ []string) {
if confirm != password { username, err := term.Prompt("New Username: ")
panic("confirmed password mismatch") if err != nil {
} panic(err)
}
zrok := newZrokClient() password, err := term.PromptPassword("New Password: ", false)
req := identity.NewCreateAccountParams() if err != nil {
req.Body = &rest_model_zrok.AccountRequest{ panic(err)
Username: username, }
Password: password, confirm, err := term.PromptPassword("Confirm Password: ", false)
} if err != nil {
resp, err := zrok.Identity.CreateAccount(req) panic(err)
if err != nil { }
panic(err) if confirm != password {
} panic("confirmed password mismatch")
}
logrus.Infof("api token: %v", resp.Payload.Token)
}, zrok := newZrokClient()
req := identity.NewCreateAccountParams()
req.Body = &rest_model_zrok.AccountRequest{
Username: username,
Password: password,
}
resp, err := zrok.Identity.CreateAccount(req)
if err != nil {
panic(err)
}
logrus.Infof("api token: %v", resp.Payload.Token)
} }