Browse Source

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
Oleg Gaidarenko 6 years ago
parent
commit
78cd9058a3
3 changed files with 13 additions and 10 deletions
  1. 3 0
      conf/defaults.ini
  2. 0 2
      devenv/docker/blocks/openldap/notes.md
  3. 10 8
      pkg/setting/setting.go

+ 3 - 0
conf/defaults.ini

@@ -363,6 +363,9 @@ enabled = false
 config_file = /etc/grafana/ldap.toml
 config_file = /etc/grafana/ldap.toml
 allow_sign_up = true
 allow_sign_up = true
 
 
+# LDAP backround sync (Enterprise only)
+sync_cron = @hourly
+
 #################################### SMTP / Emailing #####################
 #################################### SMTP / Emailing #####################
 [smtp]
 [smtp]
 enabled = false
 enabled = false

+ 0 - 2
devenv/docker/blocks/openldap/notes.md

@@ -39,7 +39,5 @@ frontend
   ldap-daniel
   ldap-daniel
 editors
 editors
   ldap-editors
   ldap-editors
-
-
 no groups
 no groups
   ldap-viewer
   ldap-viewer

+ 10 - 8
pkg/setting/setting.go

@@ -166,6 +166,7 @@ var (
 	// LDAP
 	// LDAP
 	LdapEnabled     bool
 	LdapEnabled     bool
 	LdapConfigFile  string
 	LdapConfigFile  string
+	LdapSyncCron    string
 	LdapAllowSignup = true
 	LdapAllowSignup = true
 
 
 	// QUOTA
 	// QUOTA
@@ -877,14 +878,6 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
 		return err
 		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")
 	alerting := iniFile.Section("alerting")
 	AlertingEnabled = alerting.Key("enabled").MustBool(true)
 	AlertingEnabled = alerting.Key("enabled").MustBool(true)
 	ExecuteAlerts = alerting.Key("execute_alerts").MustBool(true)
 	ExecuteAlerts = alerting.Key("execute_alerts").MustBool(true)
@@ -917,6 +910,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
 		cfg.PluginsEnableAlpha = true
 		cfg.PluginsEnableAlpha = true
 	}
 	}
 
 
+	cfg.readLDAPConfig()
 	cfg.readSessionConfig()
 	cfg.readSessionConfig()
 	cfg.readSmtpSettings()
 	cfg.readSmtpSettings()
 	cfg.readQuotaSettings()
 	cfg.readQuotaSettings()
@@ -981,6 +975,14 @@ type RemoteCacheOptions struct {
 	ConnStr string
 	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() {
 func (cfg *Cfg) readSessionConfig() {
 	sec, _ := cfg.Raw.GetSection("session")
 	sec, _ := cfg.Raw.GetSection("session")