Skip to content

Commit

Permalink
Replace last usage of Azure/go-autorest
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Apr 25, 2024
1 parent 1d29cae commit e62dc3b
Show file tree
Hide file tree
Showing 9 changed files with 770 additions and 114 deletions.
14 changes: 6 additions & 8 deletions azure/scope/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand Down
25 changes: 12 additions & 13 deletions azure/scope/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down Expand Up @@ -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",
},
},
},
Expand Down
Loading

0 comments on commit e62dc3b

Please # to comment.