Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
81531a29
Commit
81531a29
authored
Feb 15, 2015
by
Jason Wilder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CLI: Add account:create command
Creates a new account attached to the default admin account for now.
parent
7d4c319f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
1 deletions
+44
-1
main.go
+1
-1
pkg/cmd/accounts.go
+43
-0
No files found.
main.go
View file @
81531a29
...
...
@@ -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
)
...
...
pkg/cmd/accounts.go
View file @
81531a29
...
...
@@ -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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment