mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CLI: Add datasource:delete command
This commit is contained in:
parent
22652889b2
commit
b97361b193
2
main.go
2
main.go
@ -33,7 +33,7 @@ func main() {
|
||||
app.Version = version
|
||||
app.Commands = []cli.Command{cmd.Web, cmd.ImportJson,
|
||||
cmd.ListAccounts, cmd.CreateAccount, cmd.DeleteAccount,
|
||||
cmd.ListDataSources, cmd.CreateDataSource, cmd.DescribeDataSource}
|
||||
cmd.ListDataSources, cmd.CreateDataSource, cmd.DescribeDataSource, cmd.DeleteDataSource}
|
||||
app.Flags = append(app.Flags, []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "config",
|
||||
|
@ -60,6 +60,12 @@ var (
|
||||
Description: "Describes the details of a datasource",
|
||||
Action: describeDataSource,
|
||||
}
|
||||
DeleteDataSource = cli.Command{
|
||||
Name: "datasource:delete",
|
||||
Usage: "Deletes a datasource",
|
||||
Description: "Deletes a datasource",
|
||||
Action: deleteDataSource,
|
||||
}
|
||||
)
|
||||
|
||||
func createDataSource(c *cli.Context) {
|
||||
@ -198,3 +204,36 @@ func describeDataSource(c *cli.Context) {
|
||||
}
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
func deleteDataSource(c *cli.Context) {
|
||||
setting.NewConfigContext()
|
||||
sqlstore.NewEngine()
|
||||
sqlstore.EnsureAdminUser()
|
||||
|
||||
if len(c.Args()) != 2 {
|
||||
log.ConsoleFatal("Account and datasource name args are required")
|
||||
}
|
||||
|
||||
name := c.Args().First()
|
||||
ds := c.Args()[1]
|
||||
|
||||
accountQuery := m.GetAccountByNameQuery{Name: name}
|
||||
if err := bus.Dispatch(&accountQuery); err != nil {
|
||||
log.ConsoleFatalf("Failed to find account: %s", err)
|
||||
}
|
||||
|
||||
accountId := accountQuery.Result.Id
|
||||
|
||||
query := m.GetDataSourceByNameQuery{AccountId: accountId, Name: ds}
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
log.ConsoleFatalf("Failed to find datasource: %s", err)
|
||||
}
|
||||
datasource := query.Result
|
||||
|
||||
cmd := m.DeleteDataSourceCommand{AccountId: accountId, Id: datasource.Id}
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
log.ConsoleFatalf("Failed to delete datasource: %s", err)
|
||||
}
|
||||
|
||||
log.ConsoleInfof("DataSource %s deleted", ds)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user