-
-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathcloud_environments.go
More file actions
107 lines (99 loc) · 4.37 KB
/
Copy pathcloud_environments.go
File metadata and controls
107 lines (99 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package azure
import (
"fmt"
"sort"
"strings"
errUtils "github.com/cloudposse/atmos/errors"
)
// CloudEnvironment defines the endpoints for a specific Azure cloud (public, government, China).
type CloudEnvironment struct {
// Name is the canonical name of the cloud environment.
Name string
// LoginEndpoint is the Azure AD / Entra ID authority host (e.g., "login.microsoftonline.com").
LoginEndpoint string
// ManagementScope is the Azure Resource Manager API scope.
ManagementScope string
// LegacyManagementScopes are the legacy ARM audience scope forms
// (management.core.*) that az and azidentity derive by default. ARM accepts
// both audiences interchangeably, so the seeded management token is stored
// with all forms in its MSAL `target` for cache-lookup coverage.
LegacyManagementScopes []string
// GraphAPIScope is the Microsoft Graph API scope.
GraphAPIScope string
// KeyVaultScope is the Azure KeyVault API scope.
KeyVaultScope string
// BlobStorageSuffix is the blob storage URL suffix (e.g., "blob.core.windows.net").
BlobStorageSuffix string
// PortalURL is the Azure Portal base URL.
PortalURL string
// AzureProfileEnvName is the environment name used in azureProfile.json (e.g., "AzureCloud").
AzureProfileEnvName string
}
// Well-known Azure cloud environments.
var cloudEnvironments = map[string]*CloudEnvironment{
"public": {
Name: "public",
LoginEndpoint: "login.microsoftonline.com",
ManagementScope: "https://management.azure.com/.default",
LegacyManagementScopes: []string{"https://management.core.windows.net/.default", "https://management.core.windows.net//.default"},
GraphAPIScope: "https://graph.microsoft.com/.default",
KeyVaultScope: "https://vault.azure.net/.default",
BlobStorageSuffix: "blob.core.windows.net",
PortalURL: "https://portal.azure.com/",
AzureProfileEnvName: "AzureCloud",
},
"usgovernment": {
Name: "usgovernment",
LoginEndpoint: "login.microsoftonline.us",
ManagementScope: "https://management.usgovcloudapi.net/.default",
LegacyManagementScopes: []string{"https://management.core.usgovcloudapi.net/.default", "https://management.core.usgovcloudapi.net//.default"},
GraphAPIScope: "https://graph.microsoft.us/.default",
KeyVaultScope: "https://vault.usgovcloudapi.net/.default",
BlobStorageSuffix: "blob.core.usgovcloudapi.net",
PortalURL: "https://portal.azure.us/",
AzureProfileEnvName: "AzureUSGovernment",
},
"china": {
Name: "china",
LoginEndpoint: "login.chinacloudapi.cn",
ManagementScope: "https://management.chinacloudapi.cn/.default",
LegacyManagementScopes: []string{"https://management.core.chinacloudapi.cn/.default", "https://management.core.chinacloudapi.cn//.default"},
GraphAPIScope: "https://microsoftgraph.chinacloudapi.cn/.default",
KeyVaultScope: "https://vault.azure.cn/.default",
BlobStorageSuffix: "blob.core.chinacloudapi.cn",
PortalURL: "https://portal.azure.cn/",
AzureProfileEnvName: "AzureChinaCloud",
},
}
// PublicCloud is the default Azure public cloud environment.
var PublicCloud = cloudEnvironments["public"]
// GetCloudEnvironment returns the endpoint set for the given cloud name.
// Returns the "public" environment if name is empty. Unknown non-empty values
// are rejected by ValidateCloudEnvironment before calling this function.
func GetCloudEnvironment(name string) *CloudEnvironment {
if env, ok := cloudEnvironments[name]; ok {
return env
}
return PublicCloud
}
// KnownCloudEnvironments returns the names of all known cloud environments.
func KnownCloudEnvironments() []string {
names := make([]string, 0, len(cloudEnvironments))
for name := range cloudEnvironments {
names = append(names, name)
}
return names
}
// ValidateCloudEnvironment validates that a cloud environment name is known.
// Empty string is valid (defaults to "public"). Unknown non-empty values return an error.
func ValidateCloudEnvironment(name string) error {
if name == "" {
return nil // Empty defaults to public.
}
if _, ok := cloudEnvironments[name]; ok {
return nil
}
known := KnownCloudEnvironments()
sort.Strings(known)
return fmt.Errorf("%w: unknown cloud_environment %q; valid values are: %s", errUtils.ErrInvalidAuthConfig, name, strings.Join(known, ", "))
}