Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata fixes #960

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions sdk/environments/azure_china.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,27 @@ func AzureChina() *Environment {
LoginEndpoint: "https://login.chinacloudapi.cn",
Tenant: "common",
}
env.ResourceManager = ResourceManagerAPI("https://management.chinacloudapi.cn").withResourceIdentifier("https://management.chinacloudapi.cn")
env.MicrosoftGraph = MicrosoftGraphAPI("https://microsoftgraph.chinacloudapi.cn").withResourceIdentifier("https://microsoftgraph.chinacloudapi.cn")
env.ResourceManager = ResourceManagerAPI("https://management.chinacloudapi.cn")
env.MicrosoftGraph = MicrosoftGraphAPI("https://microsoftgraph.chinacloudapi.cn")

// DataLake, ManagedHSM and OperationalInsights are not available
env.ApiManagement = ApiManagementAPI("azure-api.cn")
env.AppConfiguration = AppConfigurationAPI("azconfig.azure.cn")
env.Batch = BatchAPI("https://batch.chinacloudapi.cn").withResourceIdentifier("https://batch.chinacloudapi.cn")
env.Batch = BatchAPI("https://batch.chinacloudapi.cn")
env.ContainerRegistry = ContainerRegistryAPI("azurecr.cn")
env.CosmosDB = CosmosDBAPI("documents.azure.cn")
env.KeyVault = KeyVaultAPI("vault.azure.cn").withResourceIdentifier("https://vault.azure.cn")
env.MariaDB = MariaDBAPI("mariadb.database.chinacloudapi.cn").withResourceIdentifier("https://ossrdbms-aad.database.chinacloudapi.cn")
env.MySql = MySqlAPI("mysql.database.chinacloudapi.cn").withResourceIdentifier("https://ossrdbms-aad.database.chinacloudapi.cn")
env.OperationalInsights = OperationalInsightsAPI().withResourceIdentifier("https://api.loganalytics.azure.cn")
env.Postgresql = PostgresqlAPI("postgres.database.chinacloudapi.cn").withResourceIdentifier("https://ossrdbms-aad.database.chinacloudapi.cn")
env.ServiceBus = ServiceBusAPI("https://servicebus.chinacloudapi.cn", "servicebus.chinacloudapi.cn")
env.Sql = SqlAPI("database.chinacloudapi.cn").withResourceIdentifier("https://database.chinacloudapi.cn")
env.Storage = StorageAPI("core.chinacloudapi.cn").withResourceIdentifier("https://storage.azure.com")
env.Synapse = SynapseAPI("dev.azuresynapse.azure.cn")
env.KeyVault = KeyVaultAPI("vault.azure.cn").WithResourceIdentifier("https://vault.azure.cn")
env.ManagedHSM = ManagedHSMAPI("https://managedhsm.azure.cn", "managedhsm.azure.cn")
env.MariaDB = MariaDBAPI("mariadb.database.chinacloudapi.cn").WithResourceIdentifier("https://ossrdbms-aad.database.chinacloudapi.cn")
env.MySql = MySqlAPI("mysql.database.chinacloudapi.cn").WithResourceIdentifier("https://ossrdbms-aad.database.chinacloudapi.cn")
env.OperationalInsights = OperationalInsightsAPI().WithResourceIdentifier("https://api.loganalytics.azure.cn")
env.Postgresql = PostgresqlAPI("postgres.database.chinacloudapi.cn").WithResourceIdentifier("https://ossrdbms-aad.database.chinacloudapi.cn")
env.ServiceBus = ServiceBusAPI("https://servicebus.chinacloudapi.cn", "servicebus.chinacloudapi.cn").WithResourceIdentifier("https://servicebus.chinacloudapi.cn")
env.Sql = SqlAPI("database.chinacloudapi.cn").WithResourceIdentifier("https://database.chinacloudapi.cn")
env.Storage = StorageAPI("core.chinacloudapi.cn").WithResourceIdentifier("https://storage.azure.com")
env.Synapse = SynapseAPI("dev.azuresynapse.azure.cn").WithResourceIdentifier("https://dev.azuresynapse.azure.cn")
env.TrafficManager = TrafficManagerAPI("trafficmanager.cn")

// @tombuildsstuff: DataLake doesn't appear to be available?

// Managed HSM expected "H2 2023" per:
// https://azure.microsoft.com/en-gb/explore/global-infrastructure/products-by-region/?regions=china-non-regional,china-east,china-east-2,china-east-3,china-north,china-north-2,china-north-3&products=all
// presumably this'll be
// env.ManagedHSM = ManagedHSMAPI("https://managedhsm.azure.cn", "managedhsm.azure.cn")
// Services not currently available: Attestation, CDNFrontDoor, DataLake, IOTCentral

return &env
}
25 changes: 12 additions & 13 deletions sdk/environments/azure_gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,27 @@ func AzureUSGovernment() *Environment {
LoginEndpoint: "https://login.microsoftonline.us",
Tenant: "common",
}
env.ResourceManager = ResourceManagerAPI("https://management.usgovcloudapi.net").withResourceIdentifier("https://management.usgovcloudapi.net")
env.MicrosoftGraph = MicrosoftGraphAPI("https://graph.microsoft.us").withResourceIdentifier("https://graph.microsoft.us")
env.ResourceManager = ResourceManagerAPI("https://management.usgovcloudapi.net")
env.MicrosoftGraph = MicrosoftGraphAPI("https://graph.microsoft.us")

env.ApiManagement = ApiManagementAPI("azure-api.us")
env.AppConfiguration = AppConfigurationAPI("azconfig.azure.us")
env.Batch = BatchAPI("https://batch.core.usgovcloudapi.net").withResourceIdentifier("https://batch.core.usgovcloudapi.net")
env.Batch = BatchAPI("https://batch.core.usgovcloudapi.net")
env.ContainerRegistry = ContainerRegistryAPI("azurecr.us")
env.CosmosDB = CosmosDBAPI("documents.azure.us")
env.KeyVault = KeyVaultAPI("vault.usgovcloudapi.net").withResourceIdentifier("https://vault.usgovcloudapi.net")
env.KeyVault = KeyVaultAPI("vault.usgovcloudapi.net").WithResourceIdentifier("https://vault.usgovcloudapi.net")
env.ManagedHSM = ManagedHSMAPI("https://managedhsm.usgovcloudapi.net", "managedhsm.usgovcloudapi.net")
env.MariaDB = MariaDBAPI("mariadb.database.usgovcloudapi.net").withResourceIdentifier("https://ossrdbms-aad.database.usgovcloudapi.net")
env.MySql = MySqlAPI("mysql.database.usgovcloudapi.net").withResourceIdentifier("https://ossrdbms-aad.database.usgovcloudapi.net")
env.OperationalInsights = OperationalInsightsAPI().withResourceIdentifier("https://api.loganalytics.us")
env.Postgresql = PostgresqlAPI("postgres.database.usgovcloudapi.net").withResourceIdentifier("https://ossrdbms-aad.database.usgovcloudapi.net")
env.ServiceBus = ServiceBusAPI("https://servicebus.usgovcloudapi.net", "servicebus.usgovcloudapi.net")
env.Sql = SqlAPI("database.usgovcloudapi.net").withResourceIdentifier("https://database.usgovcloudapi.net")
env.MariaDB = MariaDBAPI("mariadb.database.usgovcloudapi.net").WithResourceIdentifier("https://ossrdbms-aad.database.usgovcloudapi.net")
env.MySql = MySqlAPI("mysql.database.usgovcloudapi.net").WithResourceIdentifier("https://ossrdbms-aad.database.usgovcloudapi.net")
env.OperationalInsights = OperationalInsightsAPI().WithResourceIdentifier("https://api.loganalytics.us")
env.Postgresql = PostgresqlAPI("postgres.database.usgovcloudapi.net").WithResourceIdentifier("https://ossrdbms-aad.database.usgovcloudapi.net")
env.ServiceBus = ServiceBusAPI("https://servicebus.usgovcloudapi.net", "servicebus.usgovcloudapi.net").WithResourceIdentifier("https://servicebus.usgovcloudapi.net")
env.Sql = SqlAPI("database.usgovcloudapi.net").WithResourceIdentifier("https://database.usgovcloudapi.net")
env.Storage = StorageAPI("core.usgovcloudapi.net")
env.Synapse = SynapseAPI("dev.azuresynapse.usgovcloudapi.net").withResourceIdentifier("https://dev.azuresynapse.usgovcloudapi.net")
env.Synapse = SynapseAPI("dev.azuresynapse.usgovcloudapi.net").WithResourceIdentifier("https://dev.azuresynapse.usgovcloudapi.net")
env.TrafficManager = TrafficManagerAPI("usgovtrafficmanager.net")

// CDNFrontDoor doesn't appear to be available
// DataLake doesn't appear to be available
// Services not currently available: Attestation, CDNFrontDoor, DataLake, IOTCentral

return &env
}
Expand Down
24 changes: 12 additions & 12 deletions sdk/environments/azure_public.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ func AzurePublic() *Environment {

env.ApiManagement = ApiManagementAPI("azure-api.net")
env.AppConfiguration = AppConfigurationAPI("azconfig.io")
env.Attestation = AttestationAPI("https://attest.azure.net")
env.Attestation = AttestationAPI("https://attest.azure.net", "attest.azure.net")
env.Batch = BatchAPI("https://batch.core.windows.net")
env.CDNFrontDoor = CDNFrontDoorAPI("azurefd.net")
env.ContainerRegistry = ContainerRegistryAPI("azurecr.io")
env.CosmosDB = CosmosDBAPI("documents.azure.com")
env.DataLake = DataLakeAPI("azuredatalakestore.net")
env.IoTCentral = IoTCentral("azureiotcentral.com")
env.KeyVault = KeyVaultAPI("vault.azure.net")
env.CosmosDB = CosmosDBAPI("documents.azure.com").WithResourceIdentifier("https://cosmos.azure.com")
env.DataLake = DataLakeAPI("azuredatalakestore.net").WithResourceIdentifier("https://datalake.azure.net")
env.IoTCentral = IoTCentral("azureiotcentral.com").WithResourceIdentifier("https://apps.azureiotcentral.com")
env.KeyVault = KeyVaultAPI("vault.azure.net").WithResourceIdentifier("https://vault.azure.net")
env.ManagedHSM = ManagedHSMAPI("https://managedhsm.azure.net", "managedhsm.azure.net")
env.MariaDB = MariaDBAPI("mariadb.database.azure.com")
env.MySql = MySqlAPI("mysql.database.azure.com")
env.OperationalInsights = OperationalInsightsAPI()
env.Postgresql = PostgresqlAPI("postgres.database.azure.com")
env.ServiceBus = ServiceBusAPI("https://servicebus.windows.net", "servicebus.windows.net")
env.Sql = SqlAPI("database.windows.net")
env.MariaDB = MariaDBAPI("mariadb.database.azure.com").WithResourceIdentifier("https://ossrdbms-aad.database.windows.net")
env.MySql = MySqlAPI("mysql.database.azure.com").WithResourceIdentifier("https://ossrdbms-aad.database.windows.net")
env.OperationalInsights = OperationalInsightsAPI().WithResourceIdentifier("https://api.loganalytics.io")
env.Postgresql = PostgresqlAPI("postgres.database.azure.com").WithResourceIdentifier("https://ossrdbms-aad.database.windows.net")
env.ServiceBus = ServiceBusAPI("https://servicebus.windows.net", "servicebus.windows.net").WithResourceIdentifier("https://servicebus.azure.net")
env.Sql = SqlAPI("database.windows.net").WithResourceIdentifier("https://database.windows.net")
env.Storage = StorageAPI("core.windows.net")
env.Synapse = SynapseAPI("dev.azuresynapse.net")
env.Synapse = SynapseAPI("dev.azuresynapse.net").WithResourceIdentifier("https://dev.azuresynapse.net")
env.TrafficManager = TrafficManagerAPI("trafficmanager.net")

return &env
Expand Down
2 changes: 1 addition & 1 deletion sdk/environments/azure_public_canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ func AzurePublicCanary() *Environment {
// Canary is Azure Public with a different Microsoft Graph endpoint
env := AzurePublic()
env.Name = "Canary"
env.MicrosoftGraph = MicrosoftGraphAPI("https://canary.graph.microsoft.com").withResourceIdentifier("https://canary.graph.microsoft.com")
env.MicrosoftGraph = MicrosoftGraphAPI("https://canary.graph.microsoft.com").WithResourceIdentifier("https://canary.graph.microsoft.com")
return env
}
63 changes: 44 additions & 19 deletions sdk/environments/endpoint_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (e *Environment) RefreshMetaDataFromEndpoint(ctx context.Context) error {
}

client := metadata.NewClientWithEndpoint(*endpoint)
config, err := client.GetMetaData(ctx, e.Name)
config, err := client.GetMetaData(ctx)
if err != nil {
return fmt.Errorf("retrieving MetaData from endpoint: %+v", err)
}
Expand All @@ -30,7 +30,14 @@ func (e *Environment) RefreshMetaDataFromEndpoint(ctx context.Context) error {
}

func (e *Environment) updateFromMetaData(config *metadata.MetaData) error {
// Auth Endpoints
// The following supported services are missing from metadata and cannot be configured:
// - API Management (domain suffix is missing)
// - App Configuration (domain suffix and resource identifier are missing)
// - CosmosDB (domain suffix is missing)
// - IOT Central (domain suffix and resource identifier are missing)
// - Service Bus (domain suffix and resource identifier are missing)
// - Traffic Manager (domain suffix is missing)

if e.Authorization == nil {
e.Authorization = &Authorization{}
}
Expand All @@ -46,43 +53,61 @@ func (e *Environment) updateFromMetaData(config *metadata.MetaData) error {
if config.Authentication.Tenant != "" {
e.Authorization.Tenant = config.Authentication.Tenant
}
if config.ResourceManagerEndpoint != "" {
e.ResourceManager = ResourceManagerAPI(config.ResourceManagerEndpoint)

if config.DnsSuffixes.Attestation != "" && config.ResourceIdentifiers.Attestation != "" {
e.Attestation = AttestationAPI(config.ResourceIdentifiers.Attestation, config.DnsSuffixes.Attestation)
}
if config.ResourceIdentifiers.MicrosoftGraph != "" {
e.MicrosoftGraph = MicrosoftGraphAPI(config.ResourceIdentifiers.MicrosoftGraph)
if config.ResourceIdentifiers.Batch != "" {
e.Batch = BatchAPI(config.ResourceIdentifiers.Batch)
}

// Dns Suffixes
if config.DnsSuffixes.FrontDoor != "" {
e.CDNFrontDoor = CDNFrontDoorAPI(config.DnsSuffixes.FrontDoor)
}
if config.DnsSuffixes.ContainerRegistry != "" {
e.ContainerRegistry = ContainerRegistryAPI(config.DnsSuffixes.ContainerRegistry)
}
if config.DnsSuffixes.DataLakeStore != "" && config.ResourceIdentifiers.DataLake != "" {
e.DataLake = DataLakeAPI(config.DnsSuffixes.DataLakeStore).WithResourceIdentifier(config.ResourceIdentifiers.DataLake)
}
if config.DnsSuffixes.KeyVault != "" {
e.KeyVault = KeyVaultAPI(config.DnsSuffixes.KeyVault)
// Key Vault resource ID is missing in metadata, so make a best-effort guess from the domain suffix
e.KeyVault = KeyVaultAPI(config.DnsSuffixes.KeyVault).WithResourceIdentifier(fmt.Sprintf("https://%s", config.DnsSuffixes.KeyVault))
}
if config.DnsSuffixes.ManagedHSM != "" {
e.ManagedHSM = ManagedHSMAPI(fmt.Sprintf("https://%s", config.DnsSuffixes.ManagedHSM), config.DnsSuffixes.ManagedHSM)
// Managed HSM resource ID is missing in metadata, so make a best-effort guess from the domain suffix
mHsmEndpoint := fmt.Sprintf("https://%s", config.DnsSuffixes.ManagedHSM)
e.ManagedHSM = ManagedHSMAPI(mHsmEndpoint, config.DnsSuffixes.ManagedHSM).WithResourceIdentifier(mHsmEndpoint)
}
if config.DnsSuffixes.MariaDB != "" && config.ResourceIdentifiers.OSSRDBMS != "" {
e.MariaDB = MariaDBAPI(config.DnsSuffixes.MariaDB).WithResourceIdentifier(config.ResourceIdentifiers.OSSRDBMS)
}
if config.ResourceIdentifiers.MicrosoftGraph != "" {
e.MicrosoftGraph = MicrosoftGraphAPI(config.ResourceIdentifiers.MicrosoftGraph)
}
if config.DnsSuffixes.MySql != "" && config.ResourceIdentifiers.OSSRDBMS != "" {
e.MySql = MySqlAPI(config.DnsSuffixes.MySql).WithResourceIdentifier(config.ResourceIdentifiers.OSSRDBMS)
}
if config.DnsSuffixes.MariaDB != "" {
e.MariaDB = MariaDBAPI(config.DnsSuffixes.MariaDB)
if config.ResourceIdentifiers.LogAnalytics != "" {
e.OperationalInsights = OperationalInsightsAPI().WithResourceIdentifier(config.ResourceIdentifiers.LogAnalytics)
}
if config.DnsSuffixes.MySql != "" {
e.MySql = MySqlAPI(config.DnsSuffixes.MySql)
if config.DnsSuffixes.Postgresql != "" && config.ResourceIdentifiers.OSSRDBMS != "" {
e.Postgresql = PostgresqlAPI(config.DnsSuffixes.Postgresql).WithResourceIdentifier(config.ResourceIdentifiers.OSSRDBMS)
}
if config.DnsSuffixes.Postgresql != "" {
e.Postgresql = PostgresqlAPI(config.DnsSuffixes.Postgresql)
if config.ResourceManagerEndpoint != "" {
e.ResourceManager = ResourceManagerAPI(config.ResourceManagerEndpoint)
}
if config.DnsSuffixes.SqlServer != "" {
e.Sql = SqlAPI(config.DnsSuffixes.SqlServer)
// SQL resource ID is missing in metadata, so make a best-effort guess from the domain suffix
e.Sql = SqlAPI(config.DnsSuffixes.SqlServer).WithResourceIdentifier(fmt.Sprintf("https://%s", config.DnsSuffixes.SqlServer))
}
if config.DnsSuffixes.Storage != "" {
e.Storage = StorageAPI(config.DnsSuffixes.Storage)
}
if config.DnsSuffixes.StorageSync != "" {
e.StorageSync = StorageSyncAPI(config.DnsSuffixes.StorageSync)
}
if config.DnsSuffixes.Synapse != "" {
e.Synapse = SynapseAPI(config.DnsSuffixes.Synapse)
if config.DnsSuffixes.Synapse != "" && config.ResourceIdentifiers.Synapse != "" {
e.Synapse = SynapseAPI(config.DnsSuffixes.Synapse).WithResourceIdentifier(config.ResourceIdentifiers.Synapse)
}

return nil
Expand Down
7 changes: 4 additions & 3 deletions sdk/environments/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ func NewApiEndpoint(name, endpoint string, appId *string) *ApiEndpoint {
}
}

func (e *ApiEndpoint) withResourceIdentifier(identifier string) *ApiEndpoint {
e.resourceIdentifier = pointer.To(identifier)
return e
func (e *ApiEndpoint) WithResourceIdentifier(identifier string) Api {
newApi := *e
newApi.resourceIdentifier = pointer.To(identifier)
return &newApi
}

func (e *ApiEndpoint) Available() bool {
Expand Down
6 changes: 3 additions & 3 deletions sdk/environments/from_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
)

// FromEndpoint attempts to load an environment from the given Endpoint.
func FromEndpoint(ctx context.Context, endpoint, name string) (*Environment, error) {
func FromEndpoint(ctx context.Context, endpoint string) (*Environment, error) {
env := baseEnvironmentWithName("FromEnvironment")

client := metadata.NewClientWithEndpoint(endpoint)
config, err := client.GetMetaData(ctx, name)
config, err := client.GetMetaData(ctx)
if err != nil {
return nil, fmt.Errorf("retrieving metadata from endpoint %q: %+v", endpoint, err)
}
Expand All @@ -35,7 +35,7 @@ func FromEndpoint(ctx context.Context, endpoint, name string) (*Environment, err
}
env.MicrosoftGraph = MicrosoftGraphAPI(config.ResourceIdentifiers.MicrosoftGraph)

if err := env.updateFromMetaData(config); err != nil {
if err = env.updateFromMetaData(config); err != nil {
return nil, fmt.Errorf("updating Environment from MetaData: %+v", err)
}

Expand Down
10 changes: 4 additions & 6 deletions sdk/environments/from_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestFromEndpoint_Public(t *testing.T) {
actual, err := FromEndpoint(context.Background(), "https://management.azure.com", "")
actual, err := FromEndpoint(context.Background(), "https://management.azure.com")
if err != nil {
t.Fatalf("loading from endpoint: %+v", err)
}
Expand All @@ -20,14 +20,12 @@ func TestFromEndpoint_Public(t *testing.T) {
}

func TestFromEndpoint_USGovernment(t *testing.T) {
t.Skip("Skipping because USGovernment ARM metadata service has reverted to older schema 2019-05-01 (manicminer, 2023-02-02)")

actual, err := FromEndpoint(context.Background(), "https://management.usgovcloudapi.net", "AzureUSGovernment")
actual, err := FromEndpoint(context.Background(), "https://management.usgovcloudapi.net")
if err != nil {
t.Fatalf("loading from endpoint: %+v", err)
}

if actual.Name != "AzureCloud" {
t.Fatalf("expected the Environment name to be `AzureCloud` but got %q", actual.Name)
if actual.Name != "AzureUSGovernment" {
t.Fatalf("expected the Environment name to be `AzureUSGovernment` but got %q", actual.Name)
}
}
Loading
Loading