From e62dc3b73736a4fdc0e35861a9c0efcab3a6472a Mon Sep 17 00:00:00 2001 From: Matt Boersma Date: Thu, 25 Apr 2024 15:49:00 -0600 Subject: [PATCH] Replace last usage of Azure/go-autorest --- azure/scope/clients.go | 14 +- azure/scope/cluster_test.go | 25 +- azure/scope/environments.go | 338 +++++++++++++++++++ azure/scope/environments_test.go | 305 +++++++++++++++++ azure/scope/machine_test.go | 96 +++--- azure/scope/machinepool_test.go | 52 ++- azure/scope/testdata/test_environment_1.json | 36 ++ go.mod | 6 +- go.sum | 12 - 9 files changed, 770 insertions(+), 114 deletions(-) create mode 100644 azure/scope/environments.go create mode 100644 azure/scope/environments_test.go create mode 100644 azure/scope/testdata/test_environment_1.json diff --git a/azure/scope/clients.go b/azure/scope/clients.go index 84d0830ccf1..b7932b5a37a 100644 --- a/azure/scope/clients.go +++ b/azure/scope/clients.go @@ -25,13 +25,11 @@ import ( "strings" "github.com/Azure/azure-sdk-for-go/sdk/azcore" - azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/azure/auth" ) // AzureClients contains all the Azure clients used by the scopes. type AzureClients struct { - auth.EnvironmentSettings + EnvironmentSettings TokenCredential azcore.TokenCredential ResourceManagerEndpoint string @@ -115,8 +113,8 @@ func (c *AzureClients) setCredentialsWithProvider(ctx context.Context, subscript return err } -func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s auth.EnvironmentSettings, err error) { - s = auth.EnvironmentSettings{ +func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s EnvironmentSettings, err error) { + s = EnvironmentSettings{ Values: map[string]string{}, } s.Values["AZURE_ENVIRONMENT"] = environmentName @@ -131,9 +129,9 @@ func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s aut setValue(s, "AZURE_PASSWORD") setValue(s, "AZURE_AD_RESOURCE") if v := s.Values["AZURE_ENVIRONMENT"]; v == "" { - s.Environment = azureautorest.PublicCloud + s.Environment = PublicCloud } else { - s.Environment, err = azureautorest.EnvironmentFromName(v) + s.Environment, err = EnvironmentFromName(v) } if s.Values["AZURE_AD_RESOURCE"] == "" { s.Values["AZURE_AD_RESOURCE"] = s.Environment.ResourceManagerEndpoint @@ -142,7 +140,7 @@ func (c *AzureClients) getSettingsFromEnvironment(environmentName string) (s aut } // setValue adds the specified environment variable value to the Values map if it exists. -func setValue(settings auth.EnvironmentSettings, key string) { +func setValue(settings EnvironmentSettings, key string) { if v := os.Getenv(key); v != "" { settings.Values[key] = v } diff --git a/azure/scope/cluster_test.go b/azure/scope/cluster_test.go index 8adf7235717..27edbfdb2c9 100644 --- a/azure/scope/cluster_test.go +++ b/azure/scope/cluster_test.go @@ -26,7 +26,6 @@ import ( asonetworkv1api20201101 "github.com/Azure/azure-service-operator/v2/api/network/v1api20201101" asonetworkv1api20220701 "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701" asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601" - "github.com/Azure/go-autorest/autorest/azure/auth" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" @@ -958,9 +957,9 @@ func TestNatGatewaySpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -1022,9 +1021,9 @@ func TestNatGatewaySpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -1104,9 +1103,9 @@ func TestNatGatewaySpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -1377,9 +1376,9 @@ func TestSubnetSpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -1456,9 +1455,9 @@ func TestSubnetSpecs(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -1719,9 +1718,9 @@ func TestAzureBastionSpec(t *testing.T) { }, }, AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, diff --git a/azure/scope/environments.go b/azure/scope/environments.go new file mode 100644 index 00000000000..f457e4b6f3c --- /dev/null +++ b/azure/scope/environments.go @@ -0,0 +1,338 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package scope + +import ( + "encoding/json" + "fmt" + "os" + "strings" +) + +const ( + // EnvironmentFilepathName captures the name of the environment variable containing the path to the file + // to be used while populating the Azure Environment. + EnvironmentFilepathName = "AZURE_ENVIRONMENT_FILEPATH" + + // NotAvailable is used for endpoints and resource IDs that are not available for a given cloud. + NotAvailable = "N/A" +) + +var environments = map[string]Environment{ + "AZURECHINACLOUD": ChinaCloud, + "AZUREGERMANCLOUD": GermanCloud, + "AZURECLOUD": PublicCloud, + "AZUREPUBLICCLOUD": PublicCloud, + "AZUREUSGOVERNMENT": USGovernmentCloud, + "AZUREUSGOVERNMENTCLOUD": USGovernmentCloud, // TODO: deprecate +} + +// ResourceIdentifier contains a set of Azure resource IDs. +type ResourceIdentifier struct { + Graph string `json:"graph"` + KeyVault string `json:"keyVault"` + Datalake string `json:"datalake"` + Batch string `json:"batch"` + OperationalInsights string `json:"operationalInsights"` + OSSRDBMS string `json:"ossRDBMS"` + Storage string `json:"storage"` + Synapse string `json:"synapse"` + ServiceBus string `json:"serviceBus"` + SQLDatabase string `json:"sqlDatabase"` + CosmosDB string `json:"cosmosDB"` + ManagedHSM string `json:"managedHSM"` + MicrosoftGraph string `json:"microsoftGraph"` +} + +// Environment represents a set of endpoints for each of Azure's Clouds. +type Environment struct { + Name string `json:"name"` + ManagementPortalURL string `json:"managementPortalURL"` + PublishSettingsURL string `json:"publishSettingsURL"` + ServiceManagementEndpoint string `json:"serviceManagementEndpoint"` + ResourceManagerEndpoint string `json:"resourceManagerEndpoint"` + ActiveDirectoryEndpoint string `json:"activeDirectoryEndpoint"` + GalleryEndpoint string `json:"galleryEndpoint"` + KeyVaultEndpoint string `json:"keyVaultEndpoint"` + ManagedHSMEndpoint string `json:"managedHSMEndpoint"` + GraphEndpoint string `json:"graphEndpoint"` + ServiceBusEndpoint string `json:"serviceBusEndpoint"` + BatchManagementEndpoint string `json:"batchManagementEndpoint"` + MicrosoftGraphEndpoint string `json:"microsoftGraphEndpoint"` + StorageEndpointSuffix string `json:"storageEndpointSuffix"` + CosmosDBDNSSuffix string `json:"cosmosDBDNSSuffix"` + MariaDBDNSSuffix string `json:"mariaDBDNSSuffix"` + MySQLDatabaseDNSSuffix string `json:"mySqlDatabaseDNSSuffix"` + PostgresqlDatabaseDNSSuffix string `json:"postgresqlDatabaseDNSSuffix"` + SQLDatabaseDNSSuffix string `json:"sqlDatabaseDNSSuffix"` + TrafficManagerDNSSuffix string `json:"trafficManagerDNSSuffix"` + KeyVaultDNSSuffix string `json:"keyVaultDNSSuffix"` + ManagedHSMDNSSuffix string `json:"managedHSMDNSSuffix"` + ServiceBusEndpointSuffix string `json:"serviceBusEndpointSuffix"` + ServiceManagementVMDNSSuffix string `json:"serviceManagementVMDNSSuffix"` + ResourceManagerVMDNSSuffix string `json:"resourceManagerVMDNSSuffix"` + ContainerRegistryDNSSuffix string `json:"containerRegistryDNSSuffix"` + TokenAudience string `json:"tokenAudience"` + APIManagementHostNameSuffix string `json:"apiManagementHostNameSuffix"` + SynapseEndpointSuffix string `json:"synapseEndpointSuffix"` + DatalakeSuffix string `json:"datalakeSuffix"` + ResourceIdentifiers ResourceIdentifier `json:"resourceIdentifiers"` +} + +var ( + // PublicCloud is the default public Azure cloud environment. + PublicCloud = Environment{ + Name: "AzurePublicCloud", + ManagementPortalURL: "https://manage.windowsazure.com/", + PublishSettingsURL: "https://manage.windowsazure.com/publishsettings/index", + ServiceManagementEndpoint: "https://management.core.windows.net/", + ResourceManagerEndpoint: "https://management.azure.com/", + ActiveDirectoryEndpoint: "https://login.microsoftonline.com/", + GalleryEndpoint: "https://gallery.azure.com/", + KeyVaultEndpoint: "https://vault.azure.net/", + ManagedHSMEndpoint: "https://managedhsm.azure.net/", + GraphEndpoint: "https://graph.windows.net/", + ServiceBusEndpoint: "https://servicebus.windows.net/", + BatchManagementEndpoint: "https://batch.core.windows.net/", + MicrosoftGraphEndpoint: "https://graph.microsoft.com/", + StorageEndpointSuffix: "core.windows.net", + CosmosDBDNSSuffix: "documents.azure.com", + MariaDBDNSSuffix: "mariadb.database.azure.com", + MySQLDatabaseDNSSuffix: "mysql.database.azure.com", + PostgresqlDatabaseDNSSuffix: "postgres.database.azure.com", + SQLDatabaseDNSSuffix: "database.windows.net", + TrafficManagerDNSSuffix: "trafficmanager.net", + KeyVaultDNSSuffix: "vault.azure.net", + ManagedHSMDNSSuffix: "managedhsm.azure.net", + ServiceBusEndpointSuffix: "servicebus.windows.net", + ServiceManagementVMDNSSuffix: "cloudapp.net", + ResourceManagerVMDNSSuffix: "cloudapp.azure.com", + ContainerRegistryDNSSuffix: "azurecr.io", + TokenAudience: "https://management.azure.com/", + APIManagementHostNameSuffix: "azure-api.net", + SynapseEndpointSuffix: "dev.azuresynapse.net", + DatalakeSuffix: "azuredatalakestore.net", + ResourceIdentifiers: ResourceIdentifier{ + Graph: "https://graph.windows.net/", + KeyVault: "https://vault.azure.net", + Datalake: "https://datalake.azure.net/", + Batch: "https://batch.core.windows.net/", + OperationalInsights: "https://api.loganalytics.io", + OSSRDBMS: "https://ossrdbms-aad.database.windows.net", + Storage: "https://storage.azure.com/", + Synapse: "https://dev.azuresynapse.net", + ServiceBus: "https://servicebus.azure.net/", + SQLDatabase: "https://database.windows.net/", + CosmosDB: "https://cosmos.azure.com", + ManagedHSM: "https://managedhsm.azure.net", + MicrosoftGraph: "https://graph.microsoft.com/", + }, + } + + // USGovernmentCloud is the cloud environment for the US Government. + USGovernmentCloud = Environment{ + Name: "AzureUSGovernmentCloud", + ManagementPortalURL: "https://manage.windowsazure.us/", + PublishSettingsURL: "https://manage.windowsazure.us/publishsettings/index", + ServiceManagementEndpoint: "https://management.core.usgovcloudapi.net/", + ResourceManagerEndpoint: "https://management.usgovcloudapi.net/", + ActiveDirectoryEndpoint: "https://login.microsoftonline.us/", + GalleryEndpoint: "https://gallery.usgovcloudapi.net/", + KeyVaultEndpoint: "https://vault.usgovcloudapi.net/", + ManagedHSMEndpoint: NotAvailable, + GraphEndpoint: "https://graph.windows.net/", + ServiceBusEndpoint: "https://servicebus.usgovcloudapi.net/", + BatchManagementEndpoint: "https://batch.core.usgovcloudapi.net/", + MicrosoftGraphEndpoint: "https://graph.microsoft.us/", + StorageEndpointSuffix: "core.usgovcloudapi.net", + CosmosDBDNSSuffix: "documents.azure.us", + MariaDBDNSSuffix: "mariadb.database.usgovcloudapi.net", + MySQLDatabaseDNSSuffix: "mysql.database.usgovcloudapi.net", + PostgresqlDatabaseDNSSuffix: "postgres.database.usgovcloudapi.net", + SQLDatabaseDNSSuffix: "database.usgovcloudapi.net", + TrafficManagerDNSSuffix: "usgovtrafficmanager.net", + KeyVaultDNSSuffix: "vault.usgovcloudapi.net", + ManagedHSMDNSSuffix: NotAvailable, + ServiceBusEndpointSuffix: "servicebus.usgovcloudapi.net", + ServiceManagementVMDNSSuffix: "usgovcloudapp.net", + ResourceManagerVMDNSSuffix: "cloudapp.usgovcloudapi.net", + ContainerRegistryDNSSuffix: "azurecr.us", + TokenAudience: "https://management.usgovcloudapi.net/", + APIManagementHostNameSuffix: "azure-api.us", + SynapseEndpointSuffix: "dev.azuresynapse.usgovcloudapi.net", + DatalakeSuffix: NotAvailable, + ResourceIdentifiers: ResourceIdentifier{ + Graph: "https://graph.windows.net/", + KeyVault: "https://vault.usgovcloudapi.net", + Datalake: NotAvailable, + Batch: "https://batch.core.usgovcloudapi.net/", + OperationalInsights: "https://api.loganalytics.us", + OSSRDBMS: "https://ossrdbms-aad.database.usgovcloudapi.net", + Storage: "https://storage.azure.com/", + Synapse: "https://dev.azuresynapse.usgovcloudapi.net", + ServiceBus: "https://servicebus.azure.net/", + SQLDatabase: "https://database.usgovcloudapi.net/", + CosmosDB: "https://cosmos.azure.com", + ManagedHSM: NotAvailable, + MicrosoftGraph: "https://graph.microsoft.us/", + }, + } + + // ChinaCloud is the cloud environment operated in China. + ChinaCloud = Environment{ + Name: "AzureChinaCloud", + ManagementPortalURL: "https://manage.chinacloudapi.com/", + PublishSettingsURL: "https://manage.chinacloudapi.com/publishsettings/index", + ServiceManagementEndpoint: "https://management.core.chinacloudapi.cn/", + ResourceManagerEndpoint: "https://management.chinacloudapi.cn/", + ActiveDirectoryEndpoint: "https://login.chinacloudapi.cn/", + GalleryEndpoint: "https://gallery.chinacloudapi.cn/", + KeyVaultEndpoint: "https://vault.azure.cn/", + ManagedHSMEndpoint: NotAvailable, + GraphEndpoint: "https://graph.chinacloudapi.cn/", + ServiceBusEndpoint: "https://servicebus.chinacloudapi.cn/", + BatchManagementEndpoint: "https://batch.chinacloudapi.cn/", + MicrosoftGraphEndpoint: "https://microsoftgraph.chinacloudapi.cn/", + StorageEndpointSuffix: "core.chinacloudapi.cn", + CosmosDBDNSSuffix: "documents.azure.cn", + MariaDBDNSSuffix: "mariadb.database.chinacloudapi.cn", + MySQLDatabaseDNSSuffix: "mysql.database.chinacloudapi.cn", + PostgresqlDatabaseDNSSuffix: "postgres.database.chinacloudapi.cn", + SQLDatabaseDNSSuffix: "database.chinacloudapi.cn", + TrafficManagerDNSSuffix: "trafficmanager.cn", + KeyVaultDNSSuffix: "vault.azure.cn", + ManagedHSMDNSSuffix: NotAvailable, + ServiceBusEndpointSuffix: "servicebus.chinacloudapi.cn", + ServiceManagementVMDNSSuffix: "chinacloudapp.cn", + ResourceManagerVMDNSSuffix: "cloudapp.chinacloudapi.cn", + ContainerRegistryDNSSuffix: "azurecr.cn", + TokenAudience: "https://management.chinacloudapi.cn/", + APIManagementHostNameSuffix: "azure-api.cn", + SynapseEndpointSuffix: "dev.azuresynapse.azure.cn", + DatalakeSuffix: NotAvailable, + ResourceIdentifiers: ResourceIdentifier{ + Graph: "https://graph.chinacloudapi.cn/", + KeyVault: "https://vault.azure.cn", + Datalake: NotAvailable, + Batch: "https://batch.chinacloudapi.cn/", + OperationalInsights: NotAvailable, + OSSRDBMS: "https://ossrdbms-aad.database.chinacloudapi.cn", + Storage: "https://storage.azure.com/", + Synapse: "https://dev.azuresynapse.net", + ServiceBus: "https://servicebus.azure.net/", + SQLDatabase: "https://database.chinacloudapi.cn/", + CosmosDB: "https://cosmos.azure.com", + ManagedHSM: NotAvailable, + MicrosoftGraph: "https://microsoftgraph.chinacloudapi.cn", + }, + } + + // GermanCloud is the cloud environment operated in Germany. + GermanCloud = Environment{ + Name: "AzureGermanCloud", + ManagementPortalURL: "http://portal.microsoftazure.de/", + PublishSettingsURL: "https://manage.microsoftazure.de/publishsettings/index", + ServiceManagementEndpoint: "https://management.core.cloudapi.de/", + ResourceManagerEndpoint: "https://management.microsoftazure.de/", + ActiveDirectoryEndpoint: "https://login.microsoftonline.de/", + GalleryEndpoint: "https://gallery.cloudapi.de/", + KeyVaultEndpoint: "https://vault.microsoftazure.de/", + ManagedHSMEndpoint: NotAvailable, + GraphEndpoint: "https://graph.cloudapi.de/", + ServiceBusEndpoint: "https://servicebus.cloudapi.de/", + BatchManagementEndpoint: "https://batch.cloudapi.de/", + MicrosoftGraphEndpoint: NotAvailable, + StorageEndpointSuffix: "core.cloudapi.de", + CosmosDBDNSSuffix: "documents.microsoftazure.de", + MariaDBDNSSuffix: "mariadb.database.cloudapi.de", + MySQLDatabaseDNSSuffix: "mysql.database.cloudapi.de", + PostgresqlDatabaseDNSSuffix: "postgres.database.cloudapi.de", + SQLDatabaseDNSSuffix: "database.cloudapi.de", + TrafficManagerDNSSuffix: "azuretrafficmanager.de", + KeyVaultDNSSuffix: "vault.microsoftazure.de", + ManagedHSMDNSSuffix: NotAvailable, + ServiceBusEndpointSuffix: "servicebus.cloudapi.de", + ServiceManagementVMDNSSuffix: "azurecloudapp.de", + ResourceManagerVMDNSSuffix: "cloudapp.microsoftazure.de", + ContainerRegistryDNSSuffix: NotAvailable, + TokenAudience: "https://management.microsoftazure.de/", + APIManagementHostNameSuffix: NotAvailable, + SynapseEndpointSuffix: NotAvailable, + DatalakeSuffix: NotAvailable, + ResourceIdentifiers: ResourceIdentifier{ + Graph: "https://graph.cloudapi.de/", + KeyVault: "https://vault.microsoftazure.de", + Datalake: NotAvailable, + Batch: "https://batch.cloudapi.de/", + OperationalInsights: NotAvailable, + OSSRDBMS: "https://ossrdbms-aad.database.cloudapi.de", + Storage: "https://storage.azure.com/", + Synapse: NotAvailable, + ServiceBus: "https://servicebus.azure.net/", + SQLDatabase: "https://database.cloudapi.de/", + CosmosDB: "https://cosmos.azure.com", + ManagedHSM: NotAvailable, + MicrosoftGraph: NotAvailable, + }, + } +) + +// EnvironmentFromName returns an Environment based on the common name specified. +func EnvironmentFromName(name string) (Environment, error) { + // IMPORTANT + // As per @radhikagupta5: + // This is technical debt, fundamentally here because Kubernetes is not currently accepting + // contributions to the providers. Once that is an option, the provider should be updated to + // directly call `EnvironmentFromFile`. Until then, we rely on dispatching Azure Stack environment creation + // from this method based on the name that is provided to us. + if strings.EqualFold(name, "AZURESTACKCLOUD") { + return EnvironmentFromFile(os.Getenv(EnvironmentFilepathName)) + } + + name = strings.ToUpper(name) + env, ok := environments[name] + if !ok { + return env, fmt.Errorf("no cloud environment matching the name %q", name) + } + + return env, nil +} + +// EnvironmentFromFile loads an Environment from a configuration file available on disk. +// This function is particularlyq useful in the Hybrid Cloud model, where one must define their own +// endpoints. +func EnvironmentFromFile(location string) (unmarshaled Environment, err error) { + fileContents, err := os.ReadFile(location) + if err != nil { + return + } + + err = json.Unmarshal(fileContents, &unmarshaled) + + return +} + +// EnvironmentSettings contains the available authentication settings. +type EnvironmentSettings struct { + Values map[string]string + Environment Environment +} + +// GetSubscriptionID returns the available subscription ID or an empty string. +func (settings EnvironmentSettings) GetSubscriptionID() string { + return settings.Values["AZURE_SUBSCRIPTION_ID"] +} diff --git a/azure/scope/environments_test.go b/azure/scope/environments_test.go new file mode 100644 index 00000000000..40f56597949 --- /dev/null +++ b/azure/scope/environments_test.go @@ -0,0 +1,305 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package scope + +import ( + "encoding/json" + "os" + "path" + "path/filepath" + "runtime" + "testing" +) + +const ( + batchResourceID = "--batch-resource-id--" + datalakeResourceID = "--datalake-resource-id--" + graphResourceID = "--graph-resource-id--" + keyvaultResourceID = "--keyvault-resource-id--" + opInsightsResourceID = "--operational-insights-resource-id--" + ossRDBMSResourceID = "--oss-rdbms-resource-id--" + cosmosDBResourceID = "--cosmosdb-resource-id--" + managedHSMResourceID = "--managed-hsm-resource-id--" +) + +// This correlates with the expected contents of ./testdata/test_environment_1.json +var testEnvironment1 = Environment{ + Name: "--unit-test--", + ManagementPortalURL: "--management-portal-url", + PublishSettingsURL: "--publish-settings-url--", + ServiceManagementEndpoint: "--service-management-endpoint--", + ResourceManagerEndpoint: "--resource-management-endpoint--", + ActiveDirectoryEndpoint: "--active-directory-endpoint--", + GalleryEndpoint: "--gallery-endpoint--", + KeyVaultEndpoint: "--key-vault--endpoint--", + ManagedHSMEndpoint: "--managed-hsm-endpoint--", + GraphEndpoint: "--graph-endpoint--", + StorageEndpointSuffix: "--storage-endpoint-suffix--", + CosmosDBDNSSuffix: "--cosmos-db-dns-suffix--", + MariaDBDNSSuffix: "--maria-db-dns-suffix--", + MySQLDatabaseDNSSuffix: "--mysql-database-dns-suffix--", + PostgresqlDatabaseDNSSuffix: "--postgresql-database-dns-suffix--", + SQLDatabaseDNSSuffix: "--sql-database-dns-suffix--", + TrafficManagerDNSSuffix: "--traffic-manager-dns-suffix--", + KeyVaultDNSSuffix: "--key-vault-dns-suffix--", + ManagedHSMDNSSuffix: "--managed-hsm-dns-suffix--", + ServiceBusEndpointSuffix: "--service-bus-endpoint-suffix--", + ServiceManagementVMDNSSuffix: "--asm-vm-dns-suffix--", + ResourceManagerVMDNSSuffix: "--arm-vm-dns-suffix--", + ContainerRegistryDNSSuffix: "--container-registry-dns-suffix--", + TokenAudience: "--token-audience", + ResourceIdentifiers: ResourceIdentifier{ + Batch: batchResourceID, + Datalake: datalakeResourceID, + Graph: graphResourceID, + KeyVault: keyvaultResourceID, + OperationalInsights: opInsightsResourceID, + OSSRDBMS: ossRDBMSResourceID, + CosmosDB: cosmosDBResourceID, + ManagedHSM: managedHSMResourceID, + }, +} + +func TestEnvironment_EnvironmentFromFile(t *testing.T) { + got, err := EnvironmentFromFile(filepath.Join("testdata", "test_environment_1.json")) + if err != nil { + t.Error(err) + } + + if got != testEnvironment1 { + t.Logf("got: %v want: %v", got, testEnvironment1) + t.Fail() + } +} + +func TestEnvironment_EnvironmentFromName_Stack(t *testing.T) { + _, currentFile, _, _ := runtime.Caller(0) + prevEnvFilepathValue := os.Getenv(EnvironmentFilepathName) + os.Setenv(EnvironmentFilepathName, filepath.Join(path.Dir(currentFile), "testdata", "test_environment_1.json")) + defer os.Setenv(EnvironmentFilepathName, prevEnvFilepathValue) + + got, err := EnvironmentFromName("AZURESTACKCLOUD") + if err != nil { + t.Error(err) + } + + if got != testEnvironment1 { + t.Logf("got: %v want: %v", got, testEnvironment1) + t.Fail() + } +} + +func TestEnvironmentFromName(t *testing.T) { + tests := map[string]*Environment{ + "azurechinacloud": &ChinaCloud, + "AzureChinaCloud": &ChinaCloud, + "azuregermancloud": &GermanCloud, + "AzureGermanCloud": &GermanCloud, + "AzureCloud": &PublicCloud, + "azurepubliccloud": &PublicCloud, + "AzurePublicCloud": &PublicCloud, + "azureusgovernmentcloud": &USGovernmentCloud, + "AzureUSGovernmentCloud": &USGovernmentCloud, + "azureusgovernment": &USGovernmentCloud, + "AzureUSGovernment": &USGovernmentCloud, + "thisisnotarealcloudenv": nil, + } + for name, v := range tests { + t.Run(name, func(t *testing.T) { + env, err := EnvironmentFromName(name) + if v != nil && env != *v { + t.Errorf("Expected %v, but got %v", *v, env) + } + if v == nil && err == nil { + t.Errorf("Expected an error for %q, but got none", name) + } + if v != nil && err != nil { + t.Errorf("Expected no error for %q, but got %v", name, err) + } + }) + } +} + +func TestDeserializeEnvironment(t *testing.T) { + env := `{ + "name": "--name--", + "ActiveDirectoryEndpoint": "--active-directory-endpoint--", + "galleryEndpoint": "--gallery-endpoint--", + "graphEndpoint": "--graph-endpoint--", + "serviceBusEndpoint": "--service-bus-endpoint--", + "keyVaultDNSSuffix": "--key-vault-dns-suffix--", + "keyVaultEndpoint": "--key-vault-endpoint--", + "managedHSMDNSSuffix": "--managed-hsm-dns-suffix--", + "managedHSMEndpoint": "--managed-hsm-endpoint--", + "managementPortalURL": "--management-portal-url--", + "publishSettingsURL": "--publish-settings-url--", + "resourceManagerEndpoint": "--resource-manager-endpoint--", + "serviceBusEndpointSuffix": "--service-bus-endpoint-suffix--", + "serviceManagementEndpoint": "--service-management-endpoint--", + "cosmosDBDNSSuffix": "--cosmos-db-dns-suffix--", + "mariaDBDNSSuffix": "--maria-db-dns-suffix--", + "mySqlDatabaseDNSSuffix": "--mysql-database-dns-suffix--", + "postgresqlDatabaseDNSSuffix": "--postgresql-database-dns-suffix--", + "sqlDatabaseDNSSuffix": "--sql-database-dns-suffix--", + "storageEndpointSuffix": "--storage-endpoint-suffix--", + "trafficManagerDNSSuffix": "--traffic-manager-dns-suffix--", + "serviceManagementVMDNSSuffix": "--asm-vm-dns-suffix--", + "resourceManagerVMDNSSuffix": "--arm-vm-dns-suffix--", + "containerRegistryDNSSuffix": "--container-registry-dns-suffix--", + "resourceIdentifiers": { + "batch": "` + batchResourceID + `", + "datalake": "` + datalakeResourceID + `", + "graph": "` + graphResourceID + `", + "keyVault": "` + keyvaultResourceID + `", + "operationalInsights": "` + opInsightsResourceID + `", + "ossRDBMS": "` + ossRDBMSResourceID + `", + "cosmosDB": "` + cosmosDBResourceID + `", + "managedHSM": "` + managedHSMResourceID + `" + } + }` + + testSubject := Environment{} + err := json.Unmarshal([]byte(env), &testSubject) + if err != nil { + t.Fatalf("failed to unmarshal: %s", err) + } + + checks := map[string]string{ + "--name--": testSubject.Name, + "--management-portal-url--": testSubject.ManagementPortalURL, + "--publish-settings-url--": testSubject.PublishSettingsURL, + "--service-management-endpoint--": testSubject.ServiceManagementEndpoint, + "--resource-manager-endpoint--": testSubject.ResourceManagerEndpoint, + "--active-directory-endpoint--": testSubject.ActiveDirectoryEndpoint, + "--gallery-endpoint--": testSubject.GalleryEndpoint, + "--key-vault-endpoint--": testSubject.KeyVaultEndpoint, + "--managed-hsm-endpoint--": testSubject.ManagedHSMEndpoint, + "--graph-endpoint--": testSubject.GraphEndpoint, + "--service-bus-endpoint--": testSubject.ServiceBusEndpoint, + "--storage-endpoint-suffix--": testSubject.StorageEndpointSuffix, + "--cosmos-db-dns-suffix--": testSubject.CosmosDBDNSSuffix, + "--maria-db-dns-suffix--": testSubject.MariaDBDNSSuffix, + "--mysql-database-dns-suffix--": testSubject.MySQLDatabaseDNSSuffix, + "--postgresql-database-dns-suffix--": testSubject.PostgresqlDatabaseDNSSuffix, + "--sql-database-dns-suffix--": testSubject.SQLDatabaseDNSSuffix, + "--key-vault-dns-suffix--": testSubject.KeyVaultDNSSuffix, + "--managed-hsm-dns-suffix--": testSubject.ManagedHSMDNSSuffix, + "--service-bus-endpoint-suffix--": testSubject.ServiceBusEndpointSuffix, + "--asm-vm-dns-suffix--": testSubject.ServiceManagementVMDNSSuffix, + "--arm-vm-dns-suffix--": testSubject.ResourceManagerVMDNSSuffix, + "--container-registry-dns-suffix--": testSubject.ContainerRegistryDNSSuffix, + batchResourceID: testSubject.ResourceIdentifiers.Batch, + datalakeResourceID: testSubject.ResourceIdentifiers.Datalake, + graphResourceID: testSubject.ResourceIdentifiers.Graph, + keyvaultResourceID: testSubject.ResourceIdentifiers.KeyVault, + opInsightsResourceID: testSubject.ResourceIdentifiers.OperationalInsights, + ossRDBMSResourceID: testSubject.ResourceIdentifiers.OSSRDBMS, + cosmosDBResourceID: testSubject.ResourceIdentifiers.CosmosDB, + managedHSMResourceID: testSubject.ResourceIdentifiers.ManagedHSM, + } + + for k, v := range checks { + if k != v { + t.Errorf("Expected %q, but got %q", k, v) + } + } +} + +func TestRoundTripSerialization(t *testing.T) { + env := Environment{ + Name: "--unit-test--", + ManagementPortalURL: "--management-portal-url", + PublishSettingsURL: "--publish-settings-url--", + ServiceManagementEndpoint: "--service-management-endpoint--", + ResourceManagerEndpoint: "--resource-management-endpoint--", + ActiveDirectoryEndpoint: "--active-directory-endpoint--", + GalleryEndpoint: "--gallery-endpoint--", + KeyVaultEndpoint: "--key-vault--endpoint--", + GraphEndpoint: "--graph-endpoint--", + ServiceBusEndpoint: "--service-bus-endpoint--", + StorageEndpointSuffix: "--storage-endpoint-suffix--", + CosmosDBDNSSuffix: "--cosmos-db-dns-suffix--", + MariaDBDNSSuffix: "--maria-db-dns-suffix--", + MySQLDatabaseDNSSuffix: "--mysql-database-dns-suffix--", + PostgresqlDatabaseDNSSuffix: "--postgresql-database-dns-suffix--", + SQLDatabaseDNSSuffix: "--sql-database-dns-suffix--", + TrafficManagerDNSSuffix: "--traffic-manager-dns-suffix--", + KeyVaultDNSSuffix: "--key-vault-dns-suffix--", + ServiceBusEndpointSuffix: "--service-bus-endpoint-suffix--", + ServiceManagementVMDNSSuffix: "--asm-vm-dns-suffix--", + ResourceManagerVMDNSSuffix: "--arm-vm-dns-suffix--", + ContainerRegistryDNSSuffix: "--container-registry-dns-suffix--", + ResourceIdentifiers: ResourceIdentifier{ + Batch: batchResourceID, + Datalake: datalakeResourceID, + Graph: graphResourceID, + KeyVault: keyvaultResourceID, + OperationalInsights: opInsightsResourceID, + OSSRDBMS: ossRDBMSResourceID, + CosmosDB: cosmosDBResourceID, + }, + } + + bytes, err := json.Marshal(env) + if err != nil { + t.Fatalf("failed to marshal: %s", err) + } + + testSubject := Environment{} + err = json.Unmarshal(bytes, &testSubject) + if err != nil { + t.Fatalf("failed to unmarshal: %s", err) + } + + checks := map[string]string{ + env.Name: testSubject.Name, + env.ManagementPortalURL: testSubject.ManagementPortalURL, + env.PublishSettingsURL: testSubject.PublishSettingsURL, + env.ServiceManagementEndpoint: testSubject.ServiceManagementEndpoint, + env.ResourceManagerEndpoint: testSubject.ResourceManagerEndpoint, + env.ActiveDirectoryEndpoint: testSubject.ActiveDirectoryEndpoint, + env.GalleryEndpoint: testSubject.GalleryEndpoint, + env.ServiceBusEndpoint: testSubject.ServiceBusEndpoint, + env.KeyVaultEndpoint: testSubject.KeyVaultEndpoint, + env.GraphEndpoint: testSubject.GraphEndpoint, + env.StorageEndpointSuffix: testSubject.StorageEndpointSuffix, + env.CosmosDBDNSSuffix: testSubject.CosmosDBDNSSuffix, + env.MariaDBDNSSuffix: testSubject.MariaDBDNSSuffix, + env.MySQLDatabaseDNSSuffix: testSubject.MySQLDatabaseDNSSuffix, + env.PostgresqlDatabaseDNSSuffix: testSubject.PostgresqlDatabaseDNSSuffix, + env.SQLDatabaseDNSSuffix: testSubject.SQLDatabaseDNSSuffix, + env.TrafficManagerDNSSuffix: testSubject.TrafficManagerDNSSuffix, + env.KeyVaultDNSSuffix: testSubject.KeyVaultDNSSuffix, + env.ServiceBusEndpointSuffix: testSubject.ServiceBusEndpointSuffix, + env.ServiceManagementVMDNSSuffix: testSubject.ServiceManagementVMDNSSuffix, + env.ResourceManagerVMDNSSuffix: testSubject.ResourceManagerVMDNSSuffix, + env.ContainerRegistryDNSSuffix: testSubject.ContainerRegistryDNSSuffix, + env.ResourceIdentifiers.Batch: testSubject.ResourceIdentifiers.Batch, + env.ResourceIdentifiers.Datalake: testSubject.ResourceIdentifiers.Datalake, + env.ResourceIdentifiers.Graph: testSubject.ResourceIdentifiers.Graph, + env.ResourceIdentifiers.KeyVault: testSubject.ResourceIdentifiers.KeyVault, + env.ResourceIdentifiers.OperationalInsights: testSubject.ResourceIdentifiers.OperationalInsights, + env.ResourceIdentifiers.OSSRDBMS: testSubject.ResourceIdentifiers.OSSRDBMS, + env.ResourceIdentifiers.CosmosDB: testSubject.ResourceIdentifiers.CosmosDB, + } + + for k, v := range checks { + if k != v { + t.Errorf("Expected %q, but got %q", k, v) + } + } +} diff --git a/azure/scope/machine_test.go b/azure/scope/machine_test.go index a482e9198ca..0e4b4dd0bd1 100644 --- a/azure/scope/machine_test.go +++ b/azure/scope/machine_test.go @@ -23,8 +23,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" - azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/azure/auth" "github.com/google/go-cmp/cmp" . "github.com/onsi/gomega" "go.uber.org/mock/gomock" @@ -374,9 +372,9 @@ func TestMachineScope_InboundNatSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -456,9 +454,9 @@ func TestMachineScope_RoleAssignmentSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -502,9 +500,9 @@ func TestMachineScope_RoleAssignmentSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -563,9 +561,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzurePublicCloud", }, }, }, @@ -614,9 +612,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzureUSGovernmentCloud", }, }, }, @@ -651,9 +649,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzurePublicCloud", }, }, }, @@ -702,9 +700,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzureUSGovernmentCloud", }, }, }, @@ -739,9 +737,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzurePublicCloud", }, }, }, @@ -776,9 +774,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzureUSGovernmentCloud", }, }, }, @@ -826,9 +824,9 @@ func TestMachineScope_VMExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzurePublicCloud", }, }, }, @@ -1732,9 +1730,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -1839,9 +1837,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -1953,9 +1951,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -2062,9 +2060,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -2167,9 +2165,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -2280,9 +2278,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -2390,9 +2388,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -2501,9 +2499,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -2641,9 +2639,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -2779,9 +2777,9 @@ func TestMachineScope_NICSpecs(t *testing.T) { machineScope: MachineScope{ ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, diff --git a/azure/scope/machinepool_test.go b/azure/scope/machinepool_test.go index 0f410516f8d..b539a1714bb 100644 --- a/azure/scope/machinepool_test.go +++ b/azure/scope/machinepool_test.go @@ -24,8 +24,6 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" - azureautorest "github.com/Azure/go-autorest/autorest/azure" - "github.com/Azure/go-autorest/autorest/azure/auth" . "github.com/onsi/gomega" "go.uber.org/mock/gomock" corev1 "k8s.io/api/core/v1" @@ -778,9 +776,9 @@ func TestMachinePoolScope_RoleAssignmentSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -824,9 +822,9 @@ func TestMachinePoolScope_RoleAssignmentSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ + EnvironmentSettings: EnvironmentSettings{ Values: map[string]string{ - auth.SubscriptionID: "123", + "AZURE_SUBSCRIPTION_ID": "123", }, }, }, @@ -887,9 +885,9 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzurePublicCloud", }, }, }, @@ -936,9 +934,9 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzureUSGovernmentCloud", }, }, }, @@ -973,9 +971,9 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzurePublicCloud", }, }, }, @@ -1023,9 +1021,9 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzureUSGovernmentCloud", }, }, }, @@ -1059,9 +1057,9 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzurePublicCloud", }, }, }, @@ -1095,9 +1093,9 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.USGovernmentCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzureUSGovernmentCloud", }, }, }, @@ -1144,9 +1142,9 @@ func TestMachinePoolScope_VMSSExtensionSpecs(t *testing.T) { }, ClusterScoper: &ClusterScope{ AzureClients: AzureClients{ - EnvironmentSettings: auth.EnvironmentSettings{ - Environment: azureautorest.Environment{ - Name: azureautorest.PublicCloud.Name, + EnvironmentSettings: EnvironmentSettings{ + Environment: Environment{ + Name: "AzurePublicCloud", }, }, }, diff --git a/azure/scope/testdata/test_environment_1.json b/azure/scope/testdata/test_environment_1.json new file mode 100644 index 00000000000..1a41f90c052 --- /dev/null +++ b/azure/scope/testdata/test_environment_1.json @@ -0,0 +1,36 @@ +{ + "name": "--unit-test--", + "managementPortalURL": "--management-portal-url", + "publishSettingsURL": "--publish-settings-url--", + "serviceManagementEndpoint": "--service-management-endpoint--", + "resourceManagerEndpoint": "--resource-management-endpoint--", + "activeDirectoryEndpoint": "--active-directory-endpoint--", + "galleryEndpoint": "--gallery-endpoint--", + "keyVaultEndpoint": "--key-vault--endpoint--", + "managedHSMEndpoint": "--managed-hsm-endpoint--", + "graphEndpoint": "--graph-endpoint--", + "storageEndpointSuffix": "--storage-endpoint-suffix--", + "cosmosDBDNSSuffix": "--cosmos-db-dns-suffix--", + "mariaDBDNSSuffix": "--maria-db-dns-suffix--", + "mySqlDatabaseDNSSuffix": "--mysql-database-dns-suffix--", + "postgresqlDatabaseDNSSuffix": "--postgresql-database-dns-suffix--", + "sqlDatabaseDNSSuffix": "--sql-database-dns-suffix--", + "trafficManagerDNSSuffix": "--traffic-manager-dns-suffix--", + "keyVaultDNSSuffix": "--key-vault-dns-suffix--", + "managedHSMDNSSuffix": "--managed-hsm-dns-suffix--", + "serviceBusEndpointSuffix": "--service-bus-endpoint-suffix--", + "serviceManagementVMDNSSuffix": "--asm-vm-dns-suffix--", + "resourceManagerVMDNSSuffix": "--arm-vm-dns-suffix--", + "containerRegistryDNSSuffix": "--container-registry-dns-suffix--", + "tokenAudience": "--token-audience", + "resourceIdentifiers": { + "batch": "--batch-resource-id--", + "datalake": "--datalake-resource-id--", + "graph": "--graph-resource-id--", + "keyVault": "--keyvault-resource-id--", + "operationalInsights": "--operational-insights-resource-id--", + "ossRDBMS": "--oss-rdbms-resource-id--", + "cosmosDB": "--cosmosdb-resource-id--", + "managedHSM": "--managed-hsm-resource-id--" + } +} diff --git a/go.mod b/go.mod index 8f0db5632c3..3c4baf84adc 100644 --- a/go.mod +++ b/go.mod @@ -16,8 +16,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcehealth/armresourcehealth v1.3.0 github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 github.com/Azure/azure-service-operator/v2 v2.6.0 - github.com/Azure/go-autorest/autorest v0.11.29 - github.com/Azure/go-autorest/autorest/azure/auth v0.5.12 github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/blang/semver v3.5.1+incompatible github.com/go-logr/logr v1.4.1 @@ -64,6 +62,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.4.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.5.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/Azure/go-autorest/autorest v0.11.29 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect @@ -77,7 +76,6 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/kubernetesconfiguration/armkubernetesconfiguration v1.1.1 github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/Azure/go-autorest/autorest/adal v0.9.23 // indirect - github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/autorest/mocks v0.4.2 // indirect github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect @@ -103,7 +101,6 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dimchansky/utfbom v1.1.1 // indirect github.com/distribution/reference v0.5.0 // indirect github.com/docker/docker v25.0.5+incompatible // indirect github.com/docker/go-connections v0.5.0 // indirect @@ -152,7 +149,6 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/moby/spdystream v0.2.0 // indirect diff --git a/go.sum b/go.sum index 5860eac8ce2..9c47242c040 100644 --- a/go.sum +++ b/go.sum @@ -69,17 +69,11 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= -github.com/Azure/go-autorest/autorest v0.11.24/go.mod h1:G6kyRlFnTuSbEYkQGawPfsCswgme4iYf6rfSKUDzbCc= github.com/Azure/go-autorest/autorest v0.11.29 h1:I4+HL/JDvErx2LjyzaVxllw2lRDB5/BT2Bm4g20iqYw= github.com/Azure/go-autorest/autorest v0.11.29/go.mod h1:ZtEzC4Jy2JDrZLxvWs8LrBWEBycl1hbT1eknI8MtfAs= -github.com/Azure/go-autorest/autorest/adal v0.9.18/go.mod h1:XVVeme+LZwABT8K5Lc3hA4nAe8LDBVle26gTrguhhPQ= github.com/Azure/go-autorest/autorest/adal v0.9.22/go.mod h1:XuAbAEUv2Tta//+voMI038TrJBqjKam0me7qR+L8Cmk= github.com/Azure/go-autorest/autorest/adal v0.9.23 h1:Yepx8CvFxwNKpH6ja7RZ+sKX+DWYNldbLiALMC3BTz8= github.com/Azure/go-autorest/autorest/adal v0.9.23/go.mod h1:5pcMqFkdPhviJdlEy3kC/v1ZLnQl0MH6XA5YCcMhy4c= -github.com/Azure/go-autorest/autorest/azure/auth v0.5.12 h1:wkAZRgT/pn8HhFyzfe9UnqOjJYqlembgCTi72Bm/xKk= -github.com/Azure/go-autorest/autorest/azure/auth v0.5.12/go.mod h1:84w/uV8E37feW2NCJ08uT9VBfjfUHpgLVnG2InYD6cg= -github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 h1:0W/yGmFdTIT77fvdlGZ0LMISoLHFJ7Tx4U0yeB+uFs4= -github.com/Azure/go-autorest/autorest/azure/cli v0.4.5/go.mod h1:ADQAXrkgm7acgWVUNamOgh8YNrv4p27l3Wc55oVfpzg= github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw= github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= @@ -164,8 +158,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= -github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= @@ -223,7 +215,6 @@ github.com/gobuffalo/flect v1.0.2/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnD github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= -github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= @@ -359,8 +350,6 @@ github.com/microsoft/go-mssqldb v1.6.0/go.mod h1:00mDtPbeQCRGC1HwOOR5K/gr30P1NcE github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= @@ -533,7 +522,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=