grafana/pkg/setting/setting_azure.go
Sergey Kostrukov 81ad9769fa
AzureMonitor: Azure settings in Grafana server config (#33728)
* Azure cloud settings

* Fix typos

* Grouped Azure settings

* Doc fixes

* Some settings are not needed

* Updated cloud name aliases
2021-05-12 16:23:37 +02:00

63 lines
1.3 KiB
Go

package setting
import "strings"
const (
AzurePublic = "AzureCloud"
AzureChina = "AzureChinaCloud"
AzureUSGovernment = "AzureUSGovernment"
AzureGermany = "AzureGermanCloud"
)
type AzureSettings struct {
Cloud string
ManagedIdentityEnabled bool
ManagedIdentityClientId string
}
func (cfg *Cfg) readAzureSettings() {
azureSection := cfg.Raw.Section("azure")
// Cloud
cloudName := azureSection.Key("cloud").MustString(AzurePublic)
cfg.Azure.Cloud = normalizeAzureCloud(cloudName)
// Managed Identity
cfg.Azure.ManagedIdentityEnabled = azureSection.Key("managed_identity_enabled").MustBool(false)
cfg.Azure.ManagedIdentityClientId = azureSection.Key("managed_identity_client_id").String()
}
func normalizeAzureCloud(cloudName string) string {
switch strings.ToLower(cloudName) {
// Public
case "azurecloud":
case "azurepublic":
case "azurepubliccloud":
case "public":
return AzurePublic
// China
case "azurechina":
case "azurechinacloud":
case "china":
return AzureChina
// US Government
case "azureusgovernment":
case "azureusgovernmentcloud":
case "usgov":
case "usgovernment":
return AzureUSGovernment
// Germany
case "azuregermancloud":
case "azuregermany":
case "german":
case "germany":
return AzureGermany
}
// Pass the name unchanged if it's not known
return cloudName
}