(cherry picked from commit 39096208ed)
Co-authored-by: Emil Tullstedt <emil.tullstedt@grafana.com>
This commit is contained in:
co-authored by
Emil Tullstedt
parent
4371c45dff
commit
a4431a7cbf
+5
-16
@@ -1246,27 +1246,16 @@ func readAuthSettings(iniFile *ini.File, cfg *Cfg) (err error) {
|
||||
auth := iniFile.Section("auth")
|
||||
|
||||
cfg.LoginCookieName = valueAsString(auth, "login_cookie_name", "grafana_session")
|
||||
maxInactiveDaysVal := auth.Key("login_maximum_inactive_lifetime_days").MustString("")
|
||||
if maxInactiveDaysVal != "" {
|
||||
maxInactiveDaysVal = fmt.Sprintf("%sd", maxInactiveDaysVal)
|
||||
cfg.Logger.Warn("[Deprecated] the configuration setting 'login_maximum_inactive_lifetime_days' is deprecated, please use 'login_maximum_inactive_lifetime_duration' instead")
|
||||
} else {
|
||||
maxInactiveDaysVal = "7d"
|
||||
}
|
||||
maxInactiveDurationVal := valueAsString(auth, "login_maximum_inactive_lifetime_duration", maxInactiveDaysVal)
|
||||
|
||||
const defaultMaxInactiveLifetime = "7d"
|
||||
maxInactiveDurationVal := valueAsString(auth, "login_maximum_inactive_lifetime_duration", defaultMaxInactiveLifetime)
|
||||
cfg.LoginMaxInactiveLifetime, err = gtime.ParseDuration(maxInactiveDurationVal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
maxLifetimeDaysVal := auth.Key("login_maximum_lifetime_days").MustString("")
|
||||
if maxLifetimeDaysVal != "" {
|
||||
maxLifetimeDaysVal = fmt.Sprintf("%sd", maxLifetimeDaysVal)
|
||||
cfg.Logger.Warn("[Deprecated] the configuration setting 'login_maximum_lifetime_days' is deprecated, please use 'login_maximum_lifetime_duration' instead")
|
||||
} else {
|
||||
maxLifetimeDaysVal = "30d"
|
||||
}
|
||||
maxLifetimeDurationVal := valueAsString(auth, "login_maximum_lifetime_duration", maxLifetimeDaysVal)
|
||||
const defaultMaxLifetime = "30d"
|
||||
maxLifetimeDurationVal := valueAsString(auth, "login_maximum_lifetime_duration", defaultMaxLifetime)
|
||||
cfg.LoginMaxLifetime, err = gtime.ParseDuration(maxLifetimeDurationVal)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -301,9 +301,7 @@ func TestAuthDurationSettings(t *testing.T) {
|
||||
cfg := NewCfg()
|
||||
sec, err := f.NewSection("auth")
|
||||
require.NoError(t, err)
|
||||
_, err = sec.NewKey("login_maximum_inactive_lifetime_days", "10")
|
||||
require.NoError(t, err)
|
||||
_, err = sec.NewKey("login_maximum_inactive_lifetime_duration", "")
|
||||
_, err = sec.NewKey("login_maximum_inactive_lifetime_duration", "10d")
|
||||
require.NoError(t, err)
|
||||
err = readAuthSettings(f, cfg)
|
||||
require.NoError(t, err)
|
||||
@@ -323,9 +321,7 @@ func TestAuthDurationSettings(t *testing.T) {
|
||||
f = ini.Empty()
|
||||
sec, err = f.NewSection("auth")
|
||||
require.NoError(t, err)
|
||||
_, err = sec.NewKey("login_maximum_lifetime_days", "24")
|
||||
require.NoError(t, err)
|
||||
_, err = sec.NewKey("login_maximum_lifetime_duration", "")
|
||||
_, err = sec.NewKey("login_maximum_lifetime_duration", "24d")
|
||||
require.NoError(t, err)
|
||||
maxLifetimeDaysTest, err := time.ParseDuration("576h")
|
||||
require.NoError(t, err)
|
||||
@@ -347,8 +343,6 @@ func TestAuthDurationSettings(t *testing.T) {
|
||||
f = ini.Empty()
|
||||
sec, err = f.NewSection("auth")
|
||||
require.NoError(t, err)
|
||||
_, err = sec.NewKey("login_maximum_lifetime_days", "")
|
||||
require.NoError(t, err)
|
||||
_, err = sec.NewKey("login_maximum_lifetime_duration", "")
|
||||
require.NoError(t, err)
|
||||
maxLifetimeDurationTest, err = time.ParseDuration("720h")
|
||||
|
||||
Reference in New Issue
Block a user