mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-22 12:50:29 -04:00
Fix error when getting subscriptions for all tenants (#16837)
This commit is contained in:
@@ -14,6 +14,7 @@ import { AzureSubscriptionError } from '../errors';
|
||||
import { AzureResourceErrorMessageUtil } from '../utils';
|
||||
|
||||
import * as nls from 'vscode-nls';
|
||||
import { AzureAccount } from 'azurecore';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export class AzureResourceSubscriptionService implements IAzureResourceSubscriptionService {
|
||||
@@ -21,29 +22,29 @@ export class AzureResourceSubscriptionService implements IAzureResourceSubscript
|
||||
* Gets subscriptions for the given account. Any errors that occur while fetching the subscriptions for each tenant
|
||||
* will be displayed to the user, but this function will only throw an error if it's unable to fetch any subscriptions.
|
||||
* @param account The account to get the subscriptions for
|
||||
* @param tenants The list of tenants to get subscriptions for - if undefined then subscriptions for all tenants will be retrieved
|
||||
* @param tenantIds The list of tenants to get subscriptions for - if undefined then subscriptions for all tenants will be retrieved
|
||||
* @returns The list of all subscriptions on this account that were able to be retrieved
|
||||
*/
|
||||
public async getSubscriptions(account: azdata.Account, tenants?: string[]): Promise<azureResource.AzureResourceSubscription[]> {
|
||||
public async getSubscriptions(account: AzureAccount, tenantIds?: string[]): Promise<azureResource.AzureResourceSubscription[]> {
|
||||
const subscriptions: azureResource.AzureResourceSubscription[] = [];
|
||||
let gotSubscriptions = false;
|
||||
const errors: Error[] = [];
|
||||
|
||||
for (const tenant of tenants ?? account.properties.tenants) {
|
||||
for (const tenantId of tenantIds ?? account.properties.tenants.map(t => t.id)) {
|
||||
try {
|
||||
const token = await azdata.accounts.getAccountSecurityToken(account, tenant.id, azdata.AzureResource.ResourceManagement);
|
||||
const token = await azdata.accounts.getAccountSecurityToken(account, tenantId, azdata.AzureResource.ResourceManagement);
|
||||
const subClient = new SubscriptionClient(new TokenCredentials(token.token, token.tokenType), { baseUri: account.properties.providerSettings.settings.armResource.endpoint });
|
||||
const newSubs = await subClient.subscriptions.list();
|
||||
subscriptions.push(...newSubs.map(newSub => {
|
||||
return {
|
||||
id: newSub.subscriptionId,
|
||||
name: newSub.displayName,
|
||||
tenant: tenant.id
|
||||
tenant: tenantId
|
||||
};
|
||||
}));
|
||||
gotSubscriptions = true;
|
||||
} catch (error) {
|
||||
const errorMsg = localize('azure.resource.tenantSubscriptionsError', "Failed to get subscriptions for account {0} (tenant '{1}'). {2}", account.key.accountId, tenant.id, AzureResourceErrorMessageUtil.getErrorMessage(error));
|
||||
const errorMsg = localize('azure.resource.tenantSubscriptionsError', "Failed to get subscriptions for account {0} (tenant '{1}'). {2}", account.key.accountId, tenantId, AzureResourceErrorMessageUtil.getErrorMessage(error));
|
||||
console.warn(errorMsg);
|
||||
errors.push(error);
|
||||
vscode.window.showWarningMessage(errorMsg);
|
||||
|
||||
Reference in New Issue
Block a user