Skip to content

Commit

Permalink
apply unique filter to getLocations api's (#17454) (#17473)
Browse files Browse the repository at this point in the history
* apply unique filter to getLocations api's

* filter resource locations to distinct list

* simplify location filter
  • Loading branch information
brian-harris committed Oct 26, 2021
1 parent d7283a6 commit ccbc2f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
40 changes: 20 additions & 20 deletions extensions/azurecore/src/azureResource/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,27 +153,27 @@ export async function getLocations(appContext: AppContext, account?: AzureAccoun
result.errors.push(error);
return result;
}
await Promise.all(account.properties.tenants.map(async (tenant: { id: string; }) => {
try {
const path = `/subscriptions/${subscription.id}/locations?api-version=2020-01-01`;
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors);
result.locations.push(...response.response.data.value);
result.errors.push(...response.errors);
} catch (err) {
const error = new Error(localize('azure.accounts.getLocations.queryError', "Error fetching locations for account {0} ({1}) subscription {2} ({3}) tenant {4} : {5}",
account.displayInfo.displayName,
account.displayInfo.userId,
subscription.id,
subscription.name,
tenant.id,
err instanceof Error ? err.message : err));
console.warn(error);
if (!ignoreErrors) {
throw error;
}
result.errors.push(error);

try {
const path = `/subscriptions/${subscription.id}/locations?api-version=2020-01-01`;
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors);
result.locations.push(...response.response.data.value);
result.errors.push(...response.errors);
} catch (err) {
const error = new Error(localize('azure.accounts.getLocations.queryError', "Error fetching locations for account {0} ({1}) subscription {2} ({3}) tenant {4} : {5}",
account.displayInfo.displayName,
account.displayInfo.userId,
subscription.id,
subscription.name,
account.properties.tenants[0].id,
err instanceof Error ? err.message : err));
console.warn(error);
if (!ignoreErrors) {
throw error;
}
}));
result.errors.push(error);
}

return result;
}

Expand Down
8 changes: 4 additions & 4 deletions extensions/sql-migration/src/api/azure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export async function getLocations(account: azdata.Account, subscription: Subscr
if (response.errors.length > 0) {
throw new Error(response.errors.toString());
}
sortResourceArrayByName(response.locations);

const filteredLocations = response.locations.filter(loc => {
return sqlMigrationResourceLocations.includes(loc.displayName);
});
const filteredLocations = response.locations
.filter(loc => sqlMigrationResourceLocations.includes(loc.displayName));

sortResourceArrayByName(filteredLocations);

return filteredLocations;
}
Expand Down

0 comments on commit ccbc2f7

Please sign in to comment.