Commit 53f80883 by Jon Gyllenswärd Committed by GitHub

Auth Proxy: replace ini setting ldap_sync_ttl with sync_ttl (#20191)

* Renamed ttl config in code to be more consistent with behaviour
* Introduced new setting `sync_ttl` in .ini file
* Keeping the old setting `ldap_sync_ttl` in the .ini file as fallback and compatibility.
parent 0a7fcb1a
...@@ -435,6 +435,7 @@ header_name = X-WEBAUTH-USER ...@@ -435,6 +435,7 @@ header_name = X-WEBAUTH-USER
header_property = username header_property = username
auto_sign_up = true auto_sign_up = true
ldap_sync_ttl = 60 ldap_sync_ttl = 60
sync_ttl = 60
whitelist = whitelist =
headers = headers =
......
...@@ -92,7 +92,7 @@ func New(options *Options) *AuthProxy { ...@@ -92,7 +92,7 @@ func New(options *Options) *AuthProxy {
headerType: setting.AuthProxyHeaderProperty, headerType: setting.AuthProxyHeaderProperty,
headers: setting.AuthProxyHeaders, headers: setting.AuthProxyHeaders,
whitelistIP: setting.AuthProxyWhitelist, whitelistIP: setting.AuthProxyWhitelist,
cacheTTL: setting.AuthProxyLDAPSyncTtl, cacheTTL: setting.AuthProxySyncTtl,
LDAPAllowSignup: setting.LDAPAllowSignup, LDAPAllowSignup: setting.LDAPAllowSignup,
AuthProxyAutoSignUp: setting.AuthProxyAutoSignUp, AuthProxyAutoSignUp: setting.AuthProxyAutoSignUp,
} }
......
...@@ -147,7 +147,7 @@ var ( ...@@ -147,7 +147,7 @@ var (
AuthProxyHeaderName string AuthProxyHeaderName string
AuthProxyHeaderProperty string AuthProxyHeaderProperty string
AuthProxyAutoSignUp bool AuthProxyAutoSignUp bool
AuthProxyLDAPSyncTtl int AuthProxySyncTtl int
AuthProxyWhitelist string AuthProxyWhitelist string
AuthProxyHeaders map[string]string AuthProxyHeaders map[string]string
...@@ -854,7 +854,17 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { ...@@ -854,7 +854,17 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
return err return err
} }
AuthProxyAutoSignUp = authProxy.Key("auto_sign_up").MustBool(true) AuthProxyAutoSignUp = authProxy.Key("auto_sign_up").MustBool(true)
AuthProxyLDAPSyncTtl = authProxy.Key("ldap_sync_ttl").MustInt()
ldapSyncVal := authProxy.Key("ldap_sync_ttl").MustInt()
syncVal := authProxy.Key("sync_ttl").MustInt()
if ldapSyncVal != 60 {
AuthProxySyncTtl = ldapSyncVal
cfg.Logger.Warn("[Deprecated] the configuration setting 'ldap_sync_ttl' is deprecated, please use 'sync_ttl' instead")
} else {
AuthProxySyncTtl = syncVal
}
AuthProxyWhitelist, err = valueAsString(authProxy, "whitelist", "") AuthProxyWhitelist, err = valueAsString(authProxy, "whitelist", "")
if err != nil { if err != nil {
return err return err
......
...@@ -227,6 +227,50 @@ func TestLoadingSettings(t *testing.T) { ...@@ -227,6 +227,50 @@ func TestLoadingSettings(t *testing.T) {
So(cfg.RendererCallbackUrl, ShouldEqual, "http://myserver/renderer/") So(cfg.RendererCallbackUrl, ShouldEqual, "http://myserver/renderer/")
}) })
Convey("Only sync_ttl should return the value sync_ttl", func() {
cfg := NewCfg()
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:auth.proxy.sync_ttl=2"},
})
So(err, ShouldBeNil)
So(AuthProxySyncTtl, ShouldEqual, 2)
})
Convey("Only ldap_sync_ttl should return the value ldap_sync_ttl", func() {
cfg := NewCfg()
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:auth.proxy.ldap_sync_ttl=5"},
})
So(err, ShouldBeNil)
So(AuthProxySyncTtl, ShouldEqual, 5)
})
Convey("ldap_sync should override ldap_sync_ttl that is default value", func() {
cfg := NewCfg()
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:auth.proxy.sync_ttl=5"},
})
So(err, ShouldBeNil)
So(AuthProxySyncTtl, ShouldEqual, 5)
})
Convey("ldap_sync should not override ldap_sync_ttl that is different from default value", func() {
cfg := NewCfg()
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:auth.proxy.ldap_sync_ttl=12", "cfg:auth.proxy.sync_ttl=5"},
})
So(err, ShouldBeNil)
So(AuthProxySyncTtl, ShouldEqual, 12)
})
}) })
Convey("Test reading string values from .ini file", t, func() { Convey("Test reading string values from .ini file", t, func() {
......
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