Skip to content

Commit

Permalink
auth: Display account name on duplicate tenant picks (#1862)
Browse files Browse the repository at this point in the history
* Display account on duplicate tenants

* Bump version

* Update changelog
  • Loading branch information
alexweininger authored Dec 20, 2024
1 parent 64f08cd commit dd33af7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
3 changes: 3 additions & 0 deletions auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 4.0.3 - 2024-12-20
* [#1862](https://github.com/microsoft/vscode-azuretools/pull/1862) Display account name on duplicate tenant picks

## 4.0.2 - 2024-12-19

* [#1861](https://github.com/microsoft/vscode-azuretools/pull/1861) Remove unecessary if statement
Expand Down
4 changes: 2 additions & 2 deletions auth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion auth/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@microsoft/vscode-azext-azureauth",
"author": "Microsoft Corporation",
"version": "4.0.2",
"version": "4.0.3",
"description": "Azure authentication helpers for Visual Studio Code",
"tags": [
"azure",
Expand Down
10 changes: 9 additions & 1 deletion auth/src/signInToTenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,20 @@ interface TenantQuickPickItem extends vscode.QuickPickItem {

async function getPicks(subscriptionProvider: AzureSubscriptionProvider): Promise<TenantQuickPickItem[]> {
const unauthenticatedTenants = await getUnauthenticatedTenants(subscriptionProvider);
const duplicateTenants: Set<string | undefined> = new Set(
unauthenticatedTenants
.filter((tenant, index, self) => index !== self.findIndex(t => t.tenantId === tenant.tenantId))
.map(tenant => tenant.tenantId)
);
const isDuplicate = (tenantId: string) => duplicateTenants.has(tenantId);

const picks: TenantQuickPickItem[] = unauthenticatedTenants
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.sort((a, b) => (a.displayName!).localeCompare(b.displayName!))
.map(tenant => ({
label: tenant.displayName ?? '',
description: tenant.tenantId ?? '',
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
description: `${tenant.tenantId!}${isDuplicate(tenant.tenantId!) ? ` (${tenant.account.label})` : ''}`,
detail: tenant.defaultDomain ?? '',
tenant,
}));
Expand Down
6 changes: 3 additions & 3 deletions auth/src/utils/getUnauthenticatedTenants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { TenantIdDescription } from "@azure/arm-resources-subscriptions";
import type { AzureSubscriptionProvider } from "../AzureSubscriptionProvider";
import type { AzureTenant } from "../AzureTenant";

/**
* @returns list of tenants that VS Code doesn't have sessions for
*/
export async function getUnauthenticatedTenants(subscriptionProvider: AzureSubscriptionProvider): Promise<TenantIdDescription[]> {
export async function getUnauthenticatedTenants(subscriptionProvider: AzureSubscriptionProvider): Promise<AzureTenant[]> {
const tenants = await subscriptionProvider.getTenants();
const unauthenticatedTenants: TenantIdDescription[] = [];
const unauthenticatedTenants: AzureTenant[] = [];
for await (const tenant of tenants) {
if (!await subscriptionProvider.isSignedIn(tenant.tenantId, tenant.account)) {
unauthenticatedTenants.push(tenant);
Expand Down

0 comments on commit dd33af7

Please sign in to comment.