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.
This commit is contained in:
Jon Gyllenswärd 2019-11-07 11:24:54 +01:00 committed by GitHub
parent 0a7fcb1a37
commit 53f8088316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 3 deletions

View File

@ -435,6 +435,7 @@ header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = true
ldap_sync_ttl = 60
sync_ttl = 60
whitelist =
headers =

View File

@ -92,7 +92,7 @@ func New(options *Options) *AuthProxy {
headerType: setting.AuthProxyHeaderProperty,
headers: setting.AuthProxyHeaders,
whitelistIP: setting.AuthProxyWhitelist,
cacheTTL: setting.AuthProxyLDAPSyncTtl,
cacheTTL: setting.AuthProxySyncTtl,
LDAPAllowSignup: setting.LDAPAllowSignup,
AuthProxyAutoSignUp: setting.AuthProxyAutoSignUp,
}

View File

@ -147,7 +147,7 @@ var (
AuthProxyHeaderName string
AuthProxyHeaderProperty string
AuthProxyAutoSignUp bool
AuthProxyLDAPSyncTtl int
AuthProxySyncTtl int
AuthProxyWhitelist string
AuthProxyHeaders map[string]string
@ -854,7 +854,17 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
return err
}
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", "")
if err != nil {
return err

View File

@ -227,6 +227,50 @@ func TestLoadingSettings(t *testing.T) {
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() {