Settings: Add ability to override skip_org_role_sync with Env variables (#68364)

Switch to using the SectionsWithOverride for settings for skip org role sync
This commit is contained in:
Eric Leijonmarck 2023-05-12 13:45:31 +01:00 committed by GitHub
parent 4f987a4a5d
commit 1a79c8a601
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1406,44 +1406,44 @@ func readSecuritySettings(iniFile *ini.File, cfg *Cfg) error {
return nil return nil
} }
func readAuthAzureADSettings(iniFile *ini.File, cfg *Cfg) { func readAuthAzureADSettings(cfg *Cfg) {
sec := iniFile.Section("auth.azuread") sec := cfg.SectionWithEnvOverrides("auth.azuread")
cfg.AzureADEnabled = sec.Key("enabled").MustBool(false) cfg.AzureADEnabled = sec.Key("enabled").MustBool(false)
cfg.AzureADSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false) cfg.AzureADSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false)
} }
func readAuthGrafanaComSettings(iniFile *ini.File, cfg *Cfg) { func readAuthGrafanaComSettings(cfg *Cfg) {
sec := iniFile.Section("auth.grafana_com") sec := cfg.SectionWithEnvOverrides("auth.grafana_com")
cfg.GrafanaComAuthEnabled = sec.Key("enabled").MustBool(false) cfg.GrafanaComAuthEnabled = sec.Key("enabled").MustBool(false)
cfg.GrafanaComSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false) cfg.GrafanaComSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false)
} }
func readAuthGithubSettings(iniFile *ini.File, cfg *Cfg) { func readAuthGithubSettings(cfg *Cfg) {
sec := iniFile.Section("auth.github") sec := cfg.SectionWithEnvOverrides("auth.github")
cfg.GitHubAuthEnabled = sec.Key("enabled").MustBool(false) cfg.GitHubAuthEnabled = sec.Key("enabled").MustBool(false)
cfg.GitHubSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false) cfg.GitHubSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false)
} }
func readAuthGoogleSettings(iniFile *ini.File, cfg *Cfg) { func readAuthGoogleSettings(cfg *Cfg) {
sec := iniFile.Section("auth.google") sec := cfg.SectionWithEnvOverrides("auth.google")
cfg.GoogleAuthEnabled = sec.Key("enabled").MustBool(false) cfg.GoogleAuthEnabled = sec.Key("enabled").MustBool(false)
cfg.GoogleSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false) cfg.GoogleSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false)
} }
func readAuthGitlabSettings(iniFile *ini.File, cfg *Cfg) { func readAuthGitlabSettings(cfg *Cfg) {
sec := iniFile.Section("auth.gitlab") sec := cfg.SectionWithEnvOverrides("auth.gitlab")
cfg.GitLabAuthEnabled = sec.Key("enabled").MustBool(false) cfg.GitLabAuthEnabled = sec.Key("enabled").MustBool(false)
cfg.GitLabSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false) cfg.GitLabSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false)
} }
func readGenericOAuthSettings(iniFile *ini.File, cfg *Cfg) { func readGenericOAuthSettings(cfg *Cfg) {
sec := iniFile.Section("auth.generic_oauth") sec := cfg.SectionWithEnvOverrides("auth.generic_oauth")
cfg.GenericOAuthAuthEnabled = sec.Key("enabled").MustBool(false) cfg.GenericOAuthAuthEnabled = sec.Key("enabled").MustBool(false)
cfg.GenericOAuthSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false) cfg.GenericOAuthSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false)
} }
func readAuthOktaSettings(iniFile *ini.File, cfg *Cfg) { func readAuthOktaSettings(cfg *Cfg) {
sec := iniFile.Section("auth.okta") sec := cfg.SectionWithEnvOverrides("auth.okta")
cfg.OktaAuthEnabled = sec.Key("enabled").MustBool(false) cfg.OktaAuthEnabled = sec.Key("enabled").MustBool(false)
cfg.OktaSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false) cfg.OktaSkipOrgRoleSync = sec.Key("skip_org_role_sync").MustBool(false)
} }
@ -1505,19 +1505,25 @@ func readAuthSettings(iniFile *ini.File, cfg *Cfg) (err error) {
// Azure Auth // Azure Auth
AzureAuthEnabled = auth.Key("azure_auth_enabled").MustBool(false) AzureAuthEnabled = auth.Key("azure_auth_enabled").MustBool(false)
cfg.AzureAuthEnabled = AzureAuthEnabled cfg.AzureAuthEnabled = AzureAuthEnabled
readAuthAzureADSettings(iniFile, cfg) readAuthAzureADSettings(cfg)
// Google Auth // Google Auth
readAuthGoogleSettings(iniFile, cfg) readAuthGoogleSettings(cfg)
// GitLab Auth // GitLab Auth
readAuthGitlabSettings(iniFile, cfg) readAuthGitlabSettings(cfg)
// Generic OAuth // Generic OAuth
readGenericOAuthSettings(iniFile, cfg) readGenericOAuthSettings(cfg)
// Okta Auth // Okta Auth
readAuthOktaSettings(iniFile, cfg) readAuthOktaSettings(cfg)
// GrafanaCom
readAuthGrafanaComSettings(cfg)
// Github
readAuthGithubSettings(cfg)
// anonymous access // anonymous access
cfg.AnonymousEnabled = iniFile.Section("auth.anonymous").Key("enabled").MustBool(false) cfg.AnonymousEnabled = iniFile.Section("auth.anonymous").Key("enabled").MustBool(false)
@ -1578,11 +1584,6 @@ func readAuthSettings(iniFile *ini.File, cfg *Cfg) (err error) {
cfg.AuthProxyHeadersEncoded = authProxy.Key("headers_encoded").MustBool(false) cfg.AuthProxyHeadersEncoded = authProxy.Key("headers_encoded").MustBool(false)
// GrafanaCom
readAuthGrafanaComSettings(iniFile, cfg)
// Github
readAuthGithubSettings(iniFile, cfg)
return nil return nil
} }