Skip to content

Commit

Permalink
auth: Refactor getSubscriptions by filtering subs later (#1621)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexweininger authored Nov 7, 2023
1 parent b75c13c commit 2ea142c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
const tenantIds = await this.getTenantFilters();
const shouldFilterTenants = filter && !!tenantIds.length; // If the list is empty it is treated as "no filter"

const subscriptionIds = await this.getSubscriptionFilters();
const shouldFilterSubscriptions = filter && !!subscriptionIds.length; // If the list is empty it is treated as "no filter"

const results: AzureSubscription[] = [];

try {
Expand All @@ -107,20 +104,23 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
}

// For each tenant, get the list of subscriptions
for (const subscription of await this.getSubscriptionsForTenant(tenantId)) {
// If filtering is enabled, and the current subscription is not in that list, then skip it
if (shouldFilterSubscriptions && !subscriptionIds.includes(subscription.subscriptionId)) {
continue;
}

results.push(subscription);
}
results.push(...await this.getSubscriptionsForTenant(tenantId));
}
} finally {
this.suppressSignInEvents = false;
}

return results.sort((a, b) => a.name.localeCompare(b.name));
const sortSubscriptions = (subscriptions: AzureSubscription[]): AzureSubscription[] =>
subscriptions.sort((a, b) => a.name.localeCompare(b.name));

const subscriptionIds = await this.getSubscriptionFilters();
if (filter && !!subscriptionIds.length) { // If the list is empty it is treated as "no filter"
return sortSubscriptions(
results.filter(sub => subscriptionIds.includes(sub.subscriptionId))
);
}

return sortSubscriptions(results);
}

/**
Expand Down

0 comments on commit 2ea142c

Please sign in to comment.