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

Azure gov client changes #1249

Merged
merged 3 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions pkg/blockstorage/azure/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func (s *AdStorage) SnapshotRestoreTargets(ctx context.Context, snapshot *blocks

// dynamicRegionMapAzure derives a mapping from Regions to zones for Azure. Depends on subscriptionID
func (s *AdStorage) dynamicRegionMapAzure(ctx context.Context) (map[string][]string, error) {
subscriptionsCLient := subscriptions.NewClient()
subscriptionsCLient := subscriptions.NewClientWithBaseURI(s.azCli.BaseURI)
subscriptionsCLient.Authorizer = s.azCli.Authorizer
llResp, err := subscriptionsCLient.ListLocations(ctx, s.azCli.SubscriptionID)
if err != nil {
Expand All @@ -664,7 +664,7 @@ func (s *AdStorage) dynamicRegionMapAzure(ctx context.Context) (map[string][]str
regionMap[*location.Name] = make(map[string]struct{})
}

skuClient := skus.NewResourceSkusClient(s.azCli.SubscriptionID)
skuClient := skus.NewResourceSkusClientWithBaseURI(s.azCli.BaseURI, s.azCli.SubscriptionID)
skuClient.Authorizer = s.azCli.Authorizer
skuResults, err := skuClient.ListComplete(ctx)
if err != nil {
Expand Down
16 changes: 7 additions & 9 deletions pkg/blockstorage/azure/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,14 @@ func NewClient(ctx context.Context, config map[string]string) (*Client, error) {

baseURI, ok = config[blockstorage.AzureResurceMgrEndpoint]
if !ok {
baseURI = compute.DefaultBaseURI
baseURI = env.ResourceManagerEndpoint
}

disksClient := compute.NewDisksClient(subscriptionID)
disksClient := compute.NewDisksClientWithBaseURI(baseURI, subscriptionID)
disksClient.Authorizer = authorizer
disksClient.BaseURI = baseURI

snapshotsClient := compute.NewSnapshotsClient(subscriptionID)
snapshotsClient := compute.NewSnapshotsClientWithBaseURI(baseURI, subscriptionID)
snapshotsClient.Authorizer = authorizer
snapshotsClient.BaseURI = baseURI

return &Client{
BaseURI: baseURI,
Expand Down Expand Up @@ -118,12 +116,12 @@ func getAuthorizer(env azure.Environment, config map[string]string) (*autorest.B
}

credConfig := auth.NewClientCredentialsConfig(clientID, clientSecret, tenantID)
if aDDEndpoint, ok := config[blockstorage.AzureActiveDirEndpoint]; ok {
credConfig.AADEndpoint = aDDEndpoint
if credConfig.AADEndpoint, ok = config[blockstorage.AzureActiveDirEndpoint]; !ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add unit tests to verify this logic where we default to env.Something if ok is false, and verify that we use the config passed in config[some field] when ok is true ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I'm trying to find a way to unit test this

credConfig.AADEndpoint = env.ActiveDirectoryEndpoint
}

if aDDResourceID, ok := config[blockstorage.AzureActiveDirResourceID]; ok {
credConfig.Resource = aDDResourceID
if credConfig.Resource, ok = config[blockstorage.AzureActiveDirResourceID]; !ok {
credConfig.Resource = env.ResourceManagerEndpoint
}

a, err := credConfig.Authorizer()
Expand Down