Skip to content

Commit

Permalink
Enable scoping selectSubscriptions command by account (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweininger authored Dec 6, 2024
1 parent c0fff05 commit c416dd6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/commands/accounts/selectSubscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import { settingUtils } from "../../utils/settingUtils";

export interface SelectSubscriptionOptions {
/**
* If provided, only subscriptions in this tenant will be shown in the picker. Only subscriptions shown in the picker will be removed or added to the selected subscriptions setting.
* If provided, only subscriptions in this tenant will be shown in the picker.
*
* Only subscriptions shown in the picker will be removed or added to the selected subscriptions setting.
*/
tenantId?: string;
/**
* TODO: implement filtering at the account level
* If provided, only subscriptions from this account will be shown in the picker.
*
* Only subscriptions shown in the picker will be removed or added to the selected subscriptions setting.
*/
account?: vscode.AuthenticationSessionAccountInformation;
}
Expand All @@ -33,13 +37,18 @@ export async function selectSubscriptions(context: IActionContext, options?: Sel

const subscriptionQuickPickItems: () => Promise<IAzureQuickPickItem<AzureSubscription>[]> = async () => {
// If there are no tenants selected by default all subscriptions will be shown.
const allSubscriptions = await provider.getSubscriptions(false);
const subscriptionsFilteredByTenant = options?.tenantId ? allSubscriptions.filter(subscription => subscription.tenantId === options.tenantId) : allSubscriptions;
const duplicates = getDuplicateSubscriptions(allSubscriptions);
let subscriptions = await provider.getSubscriptions(false);
if (options?.account) {
subscriptions = subscriptions.filter(subscription => subscription.account.id === options.account?.id);
}
if (options?.tenantId) {
subscriptions = subscriptions.filter(subscription => subscription.tenantId === options.tenantId);
}
const duplicates = getDuplicateSubscriptions(subscriptions);

subscriptionsShownInPicker = subscriptionsFilteredByTenant.map(sub => `${sub.tenantId}/${sub.subscriptionId}`);
return subscriptionsFilteredByTenant
.map(subscription => ({
subscriptionsShownInPicker = subscriptions.map(sub => `${sub.tenantId}/${sub.subscriptionId}`);
return subscriptions
.map(subscription => (<IAzureQuickPickItem<AzureSubscription>>{
label: duplicates.includes(subscription) ? subscription.name + ` (${subscription.account?.label})` : subscription.name,
description: subscription.subscriptionId,
data: subscription
Expand Down

0 comments on commit c416dd6

Please sign in to comment.