2021-05-12 09:23:37 -05:00
|
|
|
package setting
|
|
|
|
|
2023-05-15 12:00:54 -05:00
|
|
|
import (
|
|
|
|
"github.com/grafana/grafana-azure-sdk-go/azsettings"
|
|
|
|
)
|
2021-05-12 09:23:37 -05:00
|
|
|
|
|
|
|
func (cfg *Cfg) readAzureSettings() {
|
2022-04-01 06:26:49 -05:00
|
|
|
azureSettings := &azsettings.AzureSettings{}
|
|
|
|
|
2021-05-12 09:23:37 -05:00
|
|
|
azureSection := cfg.Raw.Section("azure")
|
|
|
|
|
|
|
|
// Cloud
|
2022-04-01 06:26:49 -05:00
|
|
|
cloudName := azureSection.Key("cloud").MustString(azsettings.AzurePublic)
|
|
|
|
azureSettings.Cloud = azsettings.NormalizeAzureCloud(cloudName)
|
2021-05-12 09:23:37 -05:00
|
|
|
|
2023-05-15 12:00:54 -05:00
|
|
|
// Managed Identity authentication
|
2022-04-01 06:26:49 -05:00
|
|
|
azureSettings.ManagedIdentityEnabled = azureSection.Key("managed_identity_enabled").MustBool(false)
|
|
|
|
azureSettings.ManagedIdentityClientId = azureSection.Key("managed_identity_client_id").String()
|
2021-05-12 09:23:37 -05:00
|
|
|
|
2023-05-15 12:00:54 -05:00
|
|
|
// User Identity authentication
|
|
|
|
if azureSection.Key("user_identity_enabled").MustBool(false) {
|
|
|
|
azureSettings.UserIdentityEnabled = true
|
|
|
|
tokenEndpointSettings := &azsettings.TokenEndpointSettings{}
|
|
|
|
|
|
|
|
// Get token endpoint from Azure AD settings if enabled
|
|
|
|
azureAdSection := cfg.Raw.Section("auth.azuread")
|
|
|
|
if azureAdSection.Key("enabled").MustBool(false) {
|
|
|
|
tokenEndpointSettings.TokenUrl = azureAdSection.Key("token_url").String()
|
|
|
|
tokenEndpointSettings.ClientId = azureAdSection.Key("client_id").String()
|
|
|
|
tokenEndpointSettings.ClientSecret = azureAdSection.Key("client_secret").String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override individual settings
|
|
|
|
if val := azureSection.Key("user_identity_token_url").String(); val != "" {
|
|
|
|
tokenEndpointSettings.TokenUrl = val
|
|
|
|
}
|
|
|
|
if val := azureSection.Key("user_identity_client_id").String(); val != "" {
|
|
|
|
tokenEndpointSettings.ClientId = val
|
|
|
|
tokenEndpointSettings.ClientSecret = ""
|
|
|
|
}
|
|
|
|
if val := azureSection.Key("user_identity_client_secret").String(); val != "" {
|
|
|
|
tokenEndpointSettings.ClientSecret = val
|
|
|
|
}
|
|
|
|
|
|
|
|
azureSettings.UserIdentityTokenEndpoint = tokenEndpointSettings
|
|
|
|
}
|
|
|
|
|
2022-04-01 06:26:49 -05:00
|
|
|
cfg.Azure = azureSettings
|
2021-05-12 09:23:37 -05:00
|
|
|
}
|