apply unique filter to getLocations api's (#17454)

* apply unique filter to getLocations api's

* filter resource locations to distinct list

* simplify location filter
This commit is contained in:
brian-harris
2021-10-22 16:00:07 -07:00
committed by GitHub
parent 6200a61382
commit 70f6eebc5a
2 changed files with 24 additions and 24 deletions

View File

@@ -153,27 +153,27 @@ export async function getLocations(appContext: AppContext, account?: AzureAccoun
result.errors.push(error); result.errors.push(error);
return result; return result;
} }
await Promise.all(account.properties.tenants.map(async (tenant: { id: string; }) => {
try { try {
const path = `/subscriptions/${subscription.id}/locations?api-version=2020-01-01`; const path = `/subscriptions/${subscription.id}/locations?api-version=2020-01-01`;
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors); const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.GET, undefined, ignoreErrors);
result.locations.push(...response.response.data.value); result.locations.push(...response.response.data.value);
result.errors.push(...response.errors); result.errors.push(...response.errors);
} catch (err) { } catch (err) {
const error = new Error(localize('azure.accounts.getLocations.queryError', "Error fetching locations for account {0} ({1}) subscription {2} ({3}) tenant {4} : {5}", 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.displayName,
account.displayInfo.userId, account.displayInfo.userId,
subscription.id, subscription.id,
subscription.name, subscription.name,
tenant.id, account.properties.tenants[0].id,
err instanceof Error ? err.message : err)); err instanceof Error ? err.message : err));
console.warn(error); console.warn(error);
if (!ignoreErrors) { if (!ignoreErrors) {
throw error; throw error;
}
result.errors.push(error);
} }
})); result.errors.push(error);
}
return result; return result;
} }

View File

@@ -38,11 +38,11 @@ export async function getLocations(account: azdata.Account, subscription: Subscr
if (response.errors.length > 0) { if (response.errors.length > 0) {
throw new Error(response.errors.toString()); throw new Error(response.errors.toString());
} }
sortResourceArrayByName(response.locations);
const filteredLocations = response.locations.filter(loc => { const filteredLocations = response.locations
return sqlMigrationResourceLocations.includes(loc.displayName); .filter(loc => sqlMigrationResourceLocations.includes(loc.displayName));
});
sortResourceArrayByName(filteredLocations);
return filteredLocations; return filteredLocations;
} }