Commit 81531a29 by Jason Wilder

CLI: Add account:create command

Creates a new account attached to the default admin account for now.
parent 7d4c319f
......@@ -32,7 +32,7 @@ func main() {
app.Usage = "grafana web"
app.Version = version
app.Commands = []cli.Command{cmd.CmdWeb, cmd.CmdImportJson,
cmd.CmdListAccounts}
cmd.CmdListAccounts, cmd.CmdCreateAccount}
app.Flags = append(app.Flags, []cli.Flag{}...)
app.Run(os.Args)
......
......@@ -26,6 +26,20 @@ var CmdListAccounts = cli.Command{
},
}
var CmdCreateAccount = cli.Command{
Name: "account:create",
Usage: "create a new account",
Description: "Creates a new account",
Action: createAccount,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config",
Value: "grafana.ini",
Usage: "path to config file",
},
},
}
func listAccounts(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
......@@ -45,3 +59,32 @@ func listAccounts(c *cli.Context) {
}
w.Flush()
}
func createAccount(c *cli.Context) {
setting.NewConfigContext()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
if !c.Args().Present() {
fmt.Printf("Account name arg is required\n")
return
}
name := c.Args().First()
adminQuery := m.GetUserByLoginQuery{LoginOrEmail: setting.AdminUser}
if err := bus.Dispatch(&adminQuery); err == m.ErrUserNotFound {
log.Error(3, "Failed to find default admin user", err)
return
}
adminUser := adminQuery.Result
cmd := m.CreateAccountCommand{Name: name, UserId: adminUser.Id}
if err := bus.Dispatch(&cmd); err != nil {
log.Error(3, "Failed to create account", err)
return
}
fmt.Printf("Account %s created for admin user %s\n", name, adminUser.Email)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment