From 78cd9058a3d756b5b0e1a4c31943220382c1f013 Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Thu, 25 Apr 2019 17:12:56 +0300 Subject: [PATCH] Feature: add cron setting for the ldap settings (#16673) * Feature: add cron setting for the ldap settings * Move ldap configuration read to special function * Introduce cron setting (no docs for it yet, pending approval) * Chore: address code review comments --- conf/defaults.ini | 3 +++ devenv/docker/blocks/openldap/notes.md | 2 -- pkg/setting/setting.go | 18 ++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 9c720cff3f3..afa742fc4fc 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -363,6 +363,9 @@ enabled = false config_file = /etc/grafana/ldap.toml allow_sign_up = true +# LDAP backround sync (Enterprise only) +sync_cron = @hourly + #################################### SMTP / Emailing ##################### [smtp] enabled = false diff --git a/devenv/docker/blocks/openldap/notes.md b/devenv/docker/blocks/openldap/notes.md index d52e6bc6b6d..fb413085970 100644 --- a/devenv/docker/blocks/openldap/notes.md +++ b/devenv/docker/blocks/openldap/notes.md @@ -39,7 +39,5 @@ frontend ldap-daniel editors ldap-editors - - no groups ldap-viewer diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index de3862cedc3..2aab0001182 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -166,6 +166,7 @@ var ( // LDAP LdapEnabled bool LdapConfigFile string + LdapSyncCron string LdapAllowSignup = true // QUOTA @@ -877,14 +878,6 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { return err } - ldapSec := iniFile.Section("auth.ldap") - LdapEnabled = ldapSec.Key("enabled").MustBool(false) - LdapConfigFile, err = valueAsString(ldapSec, "config_file", "") - if err != nil { - return err - } - LdapAllowSignup = ldapSec.Key("allow_sign_up").MustBool(true) - alerting := iniFile.Section("alerting") AlertingEnabled = alerting.Key("enabled").MustBool(true) ExecuteAlerts = alerting.Key("execute_alerts").MustBool(true) @@ -917,6 +910,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { cfg.PluginsEnableAlpha = true } + cfg.readLDAPConfig() cfg.readSessionConfig() cfg.readSmtpSettings() cfg.readQuotaSettings() @@ -981,6 +975,14 @@ type RemoteCacheOptions struct { ConnStr string } +func (cfg *Cfg) readLDAPConfig() { + ldapSec := cfg.Raw.Section("auth.ldap") + LdapEnabled = ldapSec.Key("enabled").MustBool(false) + LdapConfigFile = ldapSec.Key("config_file").String() + LdapAllowSignup = ldapSec.Key("allow_sign_up").MustBool(true) + LdapSyncCron = ldapSec.Key("sync_cron").String() +} + func (cfg *Cfg) readSessionConfig() { sec, _ := cfg.Raw.GetSection("session")