1package setting
2
3import "strings"
4
5const (
6	AzurePublic       = "AzureCloud"
7	AzureChina        = "AzureChinaCloud"
8	AzureUSGovernment = "AzureUSGovernment"
9	AzureGermany      = "AzureGermanCloud"
10)
11
12type AzureSettings struct {
13	Cloud                   string
14	ManagedIdentityEnabled  bool
15	ManagedIdentityClientId string
16}
17
18func (cfg *Cfg) readAzureSettings() {
19	azureSection := cfg.Raw.Section("azure")
20
21	// Cloud
22	cloudName := azureSection.Key("cloud").MustString(AzurePublic)
23	cfg.Azure.Cloud = normalizeAzureCloud(cloudName)
24
25	// Managed Identity
26	cfg.Azure.ManagedIdentityEnabled = azureSection.Key("managed_identity_enabled").MustBool(false)
27	cfg.Azure.ManagedIdentityClientId = azureSection.Key("managed_identity_client_id").String()
28}
29
30func normalizeAzureCloud(cloudName string) string {
31	switch strings.ToLower(cloudName) {
32	// Public
33	case "azurecloud":
34		fallthrough
35	case "azurepublic":
36		fallthrough
37	case "azurepubliccloud":
38		fallthrough
39	case "public":
40		return AzurePublic
41
42	// China
43	case "azurechina":
44		fallthrough
45	case "azurechinacloud":
46		fallthrough
47	case "china":
48		return AzureChina
49
50	// US Government
51	case "azureusgovernment":
52		fallthrough
53	case "azureusgovernmentcloud":
54		fallthrough
55	case "usgov":
56		fallthrough
57	case "usgovernment":
58		return AzureUSGovernment
59
60	// Germany
61	case "azuregermancloud":
62		fallthrough
63	case "azuregermany":
64		fallthrough
65	case "german":
66		fallthrough
67	case "germany":
68		return AzureGermany
69	}
70
71	// Pass the name unchanged if it's not known
72	return cloudName
73}
74