Commit b6428b08 by Jason Wilder

CLI: Fix config flag being ignored

Passing --config had no effect when passed.  It will now be applied as
the last config file and before any env var overrrides.
parent 9223c954
...@@ -39,8 +39,7 @@ func main() { ...@@ -39,8 +39,7 @@ func main() {
app.Flags = append(app.Flags, []cli.Flag{ app.Flags = append(app.Flags, []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "config", Name: "config",
Value: "grafana.ini", Usage: "path to grafana.ini config file",
Usage: "path to config file",
}, },
}...) }...)
app.Run(os.Args) app.Run(os.Args)
......
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"os" "os"
"text/tabwriter" "text/tabwriter"
...@@ -34,9 +33,7 @@ var DeleteAccount = cli.Command{ ...@@ -34,9 +33,7 @@ var DeleteAccount = cli.Command{
} }
func listAccounts(c *cli.Context) { func listAccounts(c *cli.Context) {
setting.NewConfigContext() initRuntime(c)
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
accountsQuery := m.GetAccountsQuery{} accountsQuery := m.GetAccountsQuery{}
if err := bus.Dispatch(&accountsQuery); err != nil { if err := bus.Dispatch(&accountsQuery); err != nil {
...@@ -53,9 +50,7 @@ func listAccounts(c *cli.Context) { ...@@ -53,9 +50,7 @@ func listAccounts(c *cli.Context) {
} }
func createAccount(c *cli.Context) { func createAccount(c *cli.Context) {
setting.NewConfigContext() initRuntime(c)
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
if !c.Args().Present() { if !c.Args().Present() {
log.ConsoleFatal("Account name arg is required") log.ConsoleFatal("Account name arg is required")
...@@ -80,9 +75,7 @@ func createAccount(c *cli.Context) { ...@@ -80,9 +75,7 @@ func createAccount(c *cli.Context) {
} }
func deleteAccount(c *cli.Context) { func deleteAccount(c *cli.Context) {
setting.NewConfigContext() initRuntime(c)
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
if !c.Args().Present() { if !c.Args().Present() {
log.ConsoleFatal("Account name arg is required") log.ConsoleFatal("Account name arg is required")
......
package cmd
import (
"github.com/codegangsta/cli"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
)
func initRuntime(c *cli.Context) {
setting.NewConfigContext(c.GlobalString("config"))
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
}
...@@ -10,8 +10,6 @@ import ( ...@@ -10,8 +10,6 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
) )
var ImportDashboard = cli.Command{ var ImportDashboard = cli.Command{
...@@ -48,9 +46,7 @@ func runImport(c *cli.Context) { ...@@ -48,9 +46,7 @@ func runImport(c *cli.Context) {
accountName := c.Args().First() accountName := c.Args().First()
setting.NewConfigContext() initRuntime(c)
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
accountQuery := m.GetAccountByNameQuery{Name: accountName} accountQuery := m.GetAccountByNameQuery{Name: accountName}
if err := bus.Dispatch(&accountQuery); err != nil { if err := bus.Dispatch(&accountQuery); err != nil {
......
...@@ -6,8 +6,6 @@ import ( ...@@ -6,8 +6,6 @@ import (
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting"
"os" "os"
"text/tabwriter" "text/tabwriter"
) )
...@@ -69,9 +67,7 @@ var ( ...@@ -69,9 +67,7 @@ var (
) )
func createDataSource(c *cli.Context) { func createDataSource(c *cli.Context) {
setting.NewConfigContext() initRuntime(c)
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
if len(c.Args()) != 3 { if len(c.Args()) != 3 {
log.ConsoleFatal("Missing required arguments") log.ConsoleFatal("Missing required arguments")
...@@ -131,9 +127,7 @@ func createDataSource(c *cli.Context) { ...@@ -131,9 +127,7 @@ func createDataSource(c *cli.Context) {
} }
func listDatasources(c *cli.Context) { func listDatasources(c *cli.Context) {
setting.NewConfigContext() initRuntime(c)
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
if !c.Args().Present() { if !c.Args().Present() {
log.ConsoleFatal("Account name arg is required") log.ConsoleFatal("Account name arg is required")
...@@ -163,9 +157,7 @@ func listDatasources(c *cli.Context) { ...@@ -163,9 +157,7 @@ func listDatasources(c *cli.Context) {
} }
func describeDataSource(c *cli.Context) { func describeDataSource(c *cli.Context) {
setting.NewConfigContext() initRuntime(c)
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
if len(c.Args()) != 2 { if len(c.Args()) != 2 {
log.ConsoleFatal("Account and datasource name args are required") log.ConsoleFatal("Account and datasource name args are required")
...@@ -206,9 +198,7 @@ func describeDataSource(c *cli.Context) { ...@@ -206,9 +198,7 @@ func describeDataSource(c *cli.Context) {
} }
func deleteDataSource(c *cli.Context) { func deleteDataSource(c *cli.Context) {
setting.NewConfigContext() initRuntime(c)
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
if len(c.Args()) != 2 { if len(c.Args()) != 2 {
log.ConsoleFatal("Account and datasource name args are required") log.ConsoleFatal("Account and datasource name args are required")
......
...@@ -17,7 +17,6 @@ import ( ...@@ -17,7 +17,6 @@ import (
"github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/services/eventpublisher" "github.com/grafana/grafana/pkg/services/eventpublisher"
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/social" "github.com/grafana/grafana/pkg/social"
) )
...@@ -71,10 +70,9 @@ func runWeb(c *cli.Context) { ...@@ -71,10 +70,9 @@ func runWeb(c *cli.Context) {
log.Info("Starting Grafana") log.Info("Starting Grafana")
log.Info("Version: %v, Commit: %v, Build date: %v", setting.BuildVersion, setting.BuildCommit, time.Unix(setting.BuildStamp, 0)) log.Info("Version: %v, Commit: %v, Build date: %v", setting.BuildVersion, setting.BuildCommit, time.Unix(setting.BuildStamp, 0))
setting.NewConfigContext() initRuntime(c)
social.NewOAuthService() social.NewOAuthService()
sqlstore.NewEngine()
sqlstore.EnsureAdminUser()
eventpublisher.Init() eventpublisher.Init()
var err error var err error
......
...@@ -164,9 +164,13 @@ func loadEnvVariableOverrides() { ...@@ -164,9 +164,13 @@ func loadEnvVariableOverrides() {
} }
} }
func NewConfigContext() { func NewConfigContext(config string) {
configFiles := findConfigFiles() configFiles := findConfigFiles()
if config != "" {
configFiles = append(configFiles, config)
}
//log.Info("Loading config files: %v", configFiles) //log.Info("Loading config files: %v", configFiles)
var err error var err error
......
...@@ -15,7 +15,7 @@ func TestLoadingSettings(t *testing.T) { ...@@ -15,7 +15,7 @@ func TestLoadingSettings(t *testing.T) {
Convey("Testing loading settings from ini file", t, func() { Convey("Testing loading settings from ini file", t, func() {
Convey("Given the default ini files", func() { Convey("Given the default ini files", func() {
NewConfigContext() NewConfigContext("")
So(AppName, ShouldEqual, "Grafana") So(AppName, ShouldEqual, "Grafana")
So(AdminUser, ShouldEqual, "admin") So(AdminUser, ShouldEqual, "admin")
...@@ -23,7 +23,7 @@ func TestLoadingSettings(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestLoadingSettings(t *testing.T) {
Convey("Should be able to override via environment variables", func() { Convey("Should be able to override via environment variables", func() {
os.Setenv("GF_SECURITY_ADMIN_USER", "superduper") os.Setenv("GF_SECURITY_ADMIN_USER", "superduper")
NewConfigContext() NewConfigContext("")
So(AdminUser, ShouldEqual, "superduper") So(AdminUser, ShouldEqual, "superduper")
}) })
......
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