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
ca37b244
Commit
ca37b244
authored
Feb 14, 2015
by
Jason Wilder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CLI: Add account list command
parent
f6c07fda
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
1 deletions
+58
-1
main.go
+2
-1
pkg/cmd/accounts.go
+47
-0
pkg/models/account.go
+4
-0
pkg/services/sqlstore/account.go
+5
-0
No files found.
main.go
View file @
ca37b244
...
...
@@ -31,7 +31,8 @@ func main() {
app
.
Name
=
"Grafana Backend"
app
.
Usage
=
"grafana web"
app
.
Version
=
version
app
.
Commands
=
[]
cli
.
Command
{
cmd
.
CmdWeb
,
cmd
.
CmdImportJson
}
app
.
Commands
=
[]
cli
.
Command
{
cmd
.
CmdWeb
,
cmd
.
CmdImportJson
,
cmd
.
CmdListAccounts
}
app
.
Flags
=
append
(
app
.
Flags
,
[]
cli
.
Flag
{}
...
)
app
.
Run
(
os
.
Args
)
...
...
pkg/cmd/accounts.go
0 → 100644
View file @
ca37b244
package
cmd
import
(
"fmt"
"github.com/codegangsta/cli"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"os"
"text/tabwriter"
)
var
CmdListAccounts
=
cli
.
Command
{
Name
:
"account"
,
Usage
:
"list accounts"
,
Description
:
"Lists the accounts in the system"
,
Action
:
listAccounts
,
Flags
:
[]
cli
.
Flag
{
cli
.
StringFlag
{
Name
:
"config"
,
Value
:
"grafana.ini"
,
Usage
:
"path to config file"
,
},
},
}
func
listAccounts
(
c
*
cli
.
Context
)
{
setting
.
NewConfigContext
()
sqlstore
.
NewEngine
()
sqlstore
.
EnsureAdminUser
()
accountsQuery
:=
m
.
GetAccountsQuery
{}
if
err
:=
bus
.
Dispatch
(
&
accountsQuery
);
err
!=
nil
{
log
.
Error
(
3
,
"Failed to find accounts"
,
err
)
return
}
w
:=
tabwriter
.
NewWriter
(
os
.
Stdout
,
20
,
1
,
4
,
' '
,
0
)
fmt
.
Fprintf
(
w
,
"ID
\t
NAME
\n
"
)
for
_
,
account
:=
range
accountsQuery
.
Result
{
fmt
.
Fprintf
(
w
,
"%d
\t
%s
\n
"
,
account
.
Id
,
account
.
Name
)
}
w
.
Flush
()
}
pkg/models/account.go
View file @
ca37b244
...
...
@@ -49,6 +49,10 @@ type GetAccountByNameQuery struct {
Result
*
Account
}
type
GetAccountsQuery
struct
{
Result
[]
*
Account
}
type
AccountDTO
struct
{
Id
int64
`json:"id"`
Name
string
`json:"name"`
...
...
pkg/services/sqlstore/account.go
View file @
ca37b244
...
...
@@ -14,6 +14,11 @@ func init() {
bus
.
AddHandler
(
"sql"
,
SetUsingAccount
)
bus
.
AddHandler
(
"sql"
,
UpdateAccount
)
bus
.
AddHandler
(
"sql"
,
GetAccountByName
)
bus
.
AddHandler
(
"sql"
,
GetAccountsQuery
)
}
func
GetAccountsQuery
(
query
*
m
.
GetAccountsQuery
)
error
{
return
x
.
Find
(
&
query
.
Result
)
}
func
GetAccountById
(
query
*
m
.
GetAccountByIdQuery
)
error
{
...
...
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