Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: Display account name on duplicate tenant picks #1862

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading