Chore: remove session storage references (#16445)

* Chore: remove session storage references

* Small refactoring of the settings module

* Update docs - remove references for the session storage

* Update config files (sample and default configs)

* Add tests for warning during the config load on defined storage cache

* Remove all references to session storage

* Remove macaron session dependency

* Remove leftovers

* Fix: address review comments

* Fix: remove old deps

* Fix: add skipStaticRootValidation = true to tests

* Fix: improve the docs and warning message

As per discussion in here - https://github.com/grafana/grafana/pull/16445/files#r273026255

* Chore: make linter happy

Fixes #16148
Ref #16114
This commit is contained in:
Oleg Gaidarenko
2019-04-22 18:58:24 +03:00
committed by GitHub
parent f175046bc1
commit db584b3d28
12 changed files with 1047 additions and 545 deletions
+28 -43
View File
@@ -17,9 +17,10 @@ import (
"time"
"github.com/go-macaron/session"
ini "gopkg.in/ini.v1"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/util"
ini "gopkg.in/ini.v1"
)
type Scheme string
@@ -183,9 +184,6 @@ var (
// Explore UI
ExploreEnabled bool
// logger
logger log.Logger
// Grafana.NET URL
GrafanaComUrl string
@@ -199,7 +197,8 @@ var (
// TODO move all global vars to this struct
type Cfg struct {
Raw *ini.File
Raw *ini.File
Logger log.Logger
// HTTP Server Settings
AppUrl string
@@ -258,7 +257,6 @@ type CommandLineArgs struct {
func init() {
IsWindows = runtime.GOOS == "windows"
logger = log.New("settings")
}
func parseAppUrlAndSubUrl(section *ini.Section) (string, string) {
@@ -535,24 +533,25 @@ func setHomePath(args *CommandLineArgs) {
var skipStaticRootValidation = false
func validateStaticRootPath() error {
func NewCfg() *Cfg {
return &Cfg{
Logger: log.New("settings"),
Raw: ini.Empty(),
}
}
func (cfg *Cfg) validateStaticRootPath() error {
if skipStaticRootValidation {
return nil
}
if _, err := os.Stat(path.Join(StaticRootPath, "build")); err != nil {
logger.Error("Failed to detect generated javascript files in public/build")
cfg.Logger.Error("Failed to detect generated javascript files in public/build")
}
return nil
}
func NewCfg() *Cfg {
return &Cfg{
Raw: ini.Empty(),
}
}
func (cfg *Cfg) Load(args *CommandLineArgs) error {
setHomePath(args)
@@ -600,7 +599,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
EnforceDomain = server.Key("enforce_domain").MustBool(false)
StaticRootPath = makeAbsolute(server.Key("static_root_path").String(), HomePath)
if err := validateStaticRootPath(); err != nil {
if err := cfg.validateStaticRootPath(); err != nil {
return err
}
@@ -813,27 +812,13 @@ type RemoteCacheOptions struct {
}
func (cfg *Cfg) readSessionConfig() {
sec := cfg.Raw.Section("session")
SessionOptions = session.Options{}
SessionOptions.Provider = sec.Key("provider").In("memory", []string{"memory", "file", "redis", "mysql", "postgres", "memcache"})
SessionOptions.ProviderConfig = strings.Trim(sec.Key("provider_config").String(), "\" ")
SessionOptions.CookieName = sec.Key("cookie_name").MustString("grafana_sess")
SessionOptions.CookiePath = AppSubUrl
SessionOptions.Secure = sec.Key("cookie_secure").MustBool()
SessionOptions.Gclifetime = cfg.Raw.Section("session").Key("gc_interval_time").MustInt64(86400)
SessionOptions.Maxlifetime = cfg.Raw.Section("session").Key("session_life_time").MustInt64(86400)
SessionOptions.IDLength = 16
sec, _ := cfg.Raw.GetSection("session")
if SessionOptions.Provider == "file" {
SessionOptions.ProviderConfig = makeAbsolute(SessionOptions.ProviderConfig, cfg.DataPath)
os.MkdirAll(path.Dir(SessionOptions.ProviderConfig), os.ModePerm)
if sec != nil {
cfg.Logger.Warn(
"[Removed] Session setting was removed in v6.2, use remote_cache option instead",
)
}
if SessionOptions.CookiePath == "" {
SessionOptions.CookiePath = "/"
}
SessionConnMaxLifetime = cfg.Raw.Section("session").Key("conn_max_lifetime").MustInt64(14400)
}
func (cfg *Cfg) initLogging(file *ini.File) {
@@ -851,26 +836,26 @@ func (cfg *Cfg) LogConfigSources() {
var text bytes.Buffer
for _, file := range configFiles {
logger.Info("Config loaded from", "file", file)
cfg.Logger.Info("Config loaded from", "file", file)
}
if len(appliedCommandLineProperties) > 0 {
for _, prop := range appliedCommandLineProperties {
logger.Info("Config overridden from command line", "arg", prop)
cfg.Logger.Info("Config overridden from command line", "arg", prop)
}
}
if len(appliedEnvOverrides) > 0 {
text.WriteString("\tEnvironment variables used:\n")
for _, prop := range appliedEnvOverrides {
logger.Info("Config overridden from Environment variable", "var", prop)
cfg.Logger.Info("Config overridden from Environment variable", "var", prop)
}
}
logger.Info("Path Home", "path", HomePath)
logger.Info("Path Data", "path", cfg.DataPath)
logger.Info("Path Logs", "path", cfg.LogsPath)
logger.Info("Path Plugins", "path", PluginsPath)
logger.Info("Path Provisioning", "path", cfg.ProvisioningPath)
logger.Info("App mode " + Env)
cfg.Logger.Info("Path Home", "path", HomePath)
cfg.Logger.Info("Path Data", "path", cfg.DataPath)
cfg.Logger.Info("Path Logs", "path", cfg.LogsPath)
cfg.Logger.Info("Path Plugins", "path", PluginsPath)
cfg.Logger.Info("Path Provisioning", "path", cfg.ProvisioningPath)
cfg.Logger.Info("App mode " + Env)
}
+43
View File
@@ -0,0 +1,43 @@
package setting
import (
"path/filepath"
"testing"
"github.com/grafana/grafana/pkg/log"
. "github.com/smartystreets/goconvey/convey"
)
type testLogger struct {
log.Logger
warnCalled bool
warnMessage string
}
func (stub *testLogger) Warn(testMessage string, ctx ...interface{}) {
stub.warnCalled = true
stub.warnMessage = testMessage
}
func TestSessionSettings(t *testing.T) {
Convey("session config", t, func() {
skipStaticRootValidation = true
Convey("Reading session should log error ", func() {
var (
cfg = NewCfg()
homePath = "../../"
)
stub := &testLogger{}
cfg.Logger = stub
cfg.Load(&CommandLineArgs{
HomePath: homePath,
Config: filepath.Join(homePath, "pkg/setting/testdata/session.ini"),
})
So(stub.warnCalled, ShouldEqual, true)
So(len(stub.warnMessage), ShouldBeGreaterThan, 0)
})
})
}
-1
View File
@@ -188,6 +188,5 @@ func TestLoadingSettings(t *testing.T) {
So(cfg.RendererCallbackUrl, ShouldEqual, "http://myserver/renderer/")
})
})
}
+2
View File
@@ -0,0 +1,2 @@
[session]
provider = file