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
90cd10e0
Commit
90cd10e0
authored
Feb 15, 2015
by
Jason Wilder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CLI: Add account:delete command
parent
c1d4acc0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
1 deletions
+71
-1
main.go
+1
-1
pkg/cmd/accounts.go
+38
-0
pkg/models/account.go
+4
-0
pkg/services/sqlstore/account.go
+28
-0
No files found.
main.go
View file @
90cd10e0
...
...
@@ -32,7 +32,7 @@ func main() {
app
.
Usage
=
"grafana web"
app
.
Version
=
version
app
.
Commands
=
[]
cli
.
Command
{
cmd
.
CmdWeb
,
cmd
.
CmdImportJson
,
cmd
.
CmdListAccounts
,
cmd
.
CmdCreateAccount
}
cmd
.
CmdListAccounts
,
cmd
.
CmdCreateAccount
,
cmd
.
CmdDeleteAccount
}
app
.
Flags
=
append
(
app
.
Flags
,
[]
cli
.
Flag
{}
...
)
app
.
Run
(
os
.
Args
)
...
...
pkg/cmd/accounts.go
View file @
90cd10e0
...
...
@@ -40,6 +40,20 @@ var CmdCreateAccount = cli.Command{
},
}
var
CmdDeleteAccount
=
cli
.
Command
{
Name
:
"account:delete"
,
Usage
:
"delete an existing account"
,
Description
:
"Deletes an existing account"
,
Action
:
deleteAccount
,
Flags
:
[]
cli
.
Flag
{
cli
.
StringFlag
{
Name
:
"config"
,
Value
:
"grafana.ini"
,
Usage
:
"path to config file"
,
},
},
}
func
listAccounts
(
c
*
cli
.
Context
)
{
setting
.
NewConfigContext
()
sqlstore
.
NewEngine
()
...
...
@@ -85,3 +99,27 @@ func createAccount(c *cli.Context) {
log
.
ConsoleInfof
(
"Account %s created for admin user %s
\n
"
,
name
,
adminUser
.
Email
)
}
func
deleteAccount
(
c
*
cli
.
Context
)
{
setting
.
NewConfigContext
()
sqlstore
.
NewEngine
()
sqlstore
.
EnsureAdminUser
()
if
!
c
.
Args
()
.
Present
()
{
log
.
ConsoleFatal
(
"Account name arg is required"
)
}
name
:=
c
.
Args
()
.
First
()
accountQuery
:=
m
.
GetAccountByNameQuery
{
Name
:
name
}
if
err
:=
bus
.
Dispatch
(
&
accountQuery
);
err
!=
nil
{
log
.
ConsoleFatalf
(
"Failed to find account: %s"
,
err
)
}
accountId
:=
accountQuery
.
Result
.
Id
cmd
:=
m
.
DeleteAccountCommand
{
Id
:
accountId
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
log
.
ConsoleFatalf
(
"Failed to delete account: %s"
,
err
)
}
log
.
ConsoleInfof
(
"Account %s deleted"
,
name
)
}
pkg/models/account.go
View file @
90cd10e0
...
...
@@ -29,6 +29,10 @@ type CreateAccountCommand struct {
Result
Account
`json:"-"`
}
type
DeleteAccountCommand
struct
{
Id
int64
}
type
UpdateAccountCommand
struct
{
Name
string
`json:"name" binding:"Required"`
AccountId
int64
`json:"-"`
...
...
pkg/services/sqlstore/account.go
View file @
90cd10e0
...
...
@@ -5,6 +5,7 @@ import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
)
...
...
@@ -15,6 +16,7 @@ func init() {
bus
.
AddHandler
(
"sql"
,
UpdateAccount
)
bus
.
AddHandler
(
"sql"
,
GetAccountByName
)
bus
.
AddHandler
(
"sql"
,
GetAccountsQuery
)
bus
.
AddHandler
(
"sql"
,
DeleteAccount
)
}
func
GetAccountsQuery
(
query
*
m
.
GetAccountsQuery
)
error
{
...
...
@@ -106,3 +108,29 @@ func UpdateAccount(cmd *m.UpdateAccountCommand) error {
return
nil
})
}
func
DeleteAccount
(
cmd
*
m
.
DeleteAccountCommand
)
error
{
return
inTransaction2
(
func
(
sess
*
session
)
error
{
deletes
:=
[]
string
{
"DELETE FROM star WHERE EXISTS (SELECT 1 FROM dashboard WHERE account_id = ?)"
,
"DELETE FROM dashboard_tag WHERE EXISTS (SELECT 1 FROM dashboard WHERE account_id = ?)"
,
"DELETE FROM dashboard WHERE account_id = ?"
,
"DELETE FROM api_key WHERE account_id = ?"
,
"DELETE FROM data_source WHERE account_id = ?"
,
"DELETE FROM account_user WHERE account_id = ?"
,
"DELETE FROM user WHERE account_id = ?"
,
"DELETE FROM account WHERE id = ?"
,
}
for
_
,
sql
:=
range
deletes
{
log
.
Trace
(
sql
)
_
,
err
:=
sess
.
Exec
(
sql
,
cmd
.
Id
)
if
err
!=
nil
{
return
err
}
}
return
nil
})
}
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