Skip to content

Commit ee00808

Browse files
auth: Create AzureTenant interface which includes account (#1849)
1 parent 3961bc0 commit ee00808

5 files changed

+26
-10
lines changed

auth/src/AzureDevOpsSubscriptionProvider.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import type { SubscriptionClient, TenantIdDescription } from '@azure/arm-resources-subscriptions';
6+
import type { SubscriptionClient } from '@azure/arm-resources-subscriptions';
77
import type { TokenCredential } from '@azure/core-auth'; // Keep this as `import type` to avoid actually loading the package (at all, this one is dev-only)
88
import type { PipelineRequest } from '@azure/core-rest-pipeline';
99
import { Disposable, Event } from 'vscode';
1010
import { AzureAuthentication } from './AzureAuthentication';
1111
import { AzureSubscription } from './AzureSubscription';
1212
import { AzureSubscriptionProvider } from './AzureSubscriptionProvider';
1313
import { getConfiguredAzureEnv } from './utils/configuredAzureEnv';
14+
import { AzureTenant } from './AzureTenant';
1415

1516
export interface AzureDevOpsSubscriptionProviderInitializer {
1617
/**
@@ -102,9 +103,13 @@ export class AzureDevOpsSubscriptionProvider implements AzureSubscriptionProvide
102103
this._tokenCredential = undefined;
103104
}
104105

105-
public async getTenants(): Promise<TenantIdDescription[]> {
106+
public async getTenants(): Promise<AzureTenant[]> {
106107
return [{
107108
tenantId: this._tokenCredential?.tenantId,
109+
account: {
110+
id: "test-account-id",
111+
label: "test-account",
112+
}
108113
}];
109114
}
110115

auth/src/AzureSubscriptionProvider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import type { TenantIdDescription } from '@azure/arm-resources-subscriptions';
76
import type * as vscode from 'vscode';
87
import type { AzureSubscription } from './AzureSubscription';
8+
import type { AzureTenant } from './AzureTenant';
99

1010
/**
1111
* An interface for obtaining Azure subscription information
@@ -19,7 +19,7 @@ export interface AzureSubscriptionProvider {
1919
*
2020
* @returns A list of tenants.
2121
*/
22-
getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<TenantIdDescription[]>;
22+
getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<AzureTenant[]>;
2323

2424
/**
2525
* Gets a list of Azure subscriptions available to the user.

auth/src/AzureTenant.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { TenantIdDescription } from "@azure/arm-resources-subscriptions";
7+
import * as vscode from 'vscode';
8+
9+
export interface AzureTenant extends TenantIdDescription {
10+
account: vscode.AuthenticationSessionAccountInformation;
11+
}

auth/src/VSCodeAzureSubscriptionProvider.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import type { SubscriptionClient, TenantIdDescription } from '@azure/arm-resources-subscriptions'; // Keep this as `import type` to avoid actually loading the package before necessary
6+
import type { SubscriptionClient } from '@azure/arm-resources-subscriptions'; // Keep this as `import type` to avoid actually loading the package before necessary
77
import type { TokenCredential } from '@azure/core-auth'; // Keep this as `import type` to avoid actually loading the package (at all, this one is dev-only)
88
import * as vscode from 'vscode';
99
import { AzureAuthentication } from './AzureAuthentication';
@@ -12,6 +12,7 @@ import { AzureSubscriptionProvider } from './AzureSubscriptionProvider';
1212
import { getSessionFromVSCode } from './getSessionFromVSCode';
1313
import { NotSignedInError } from './NotSignedInError';
1414
import { getConfiguredAuthProviderId, getConfiguredAzureEnv } from './utils/configuredAzureEnv';
15+
import { AzureTenant } from './AzureTenant';
1516

1617
const EventDebounce = 5 * 1000; // 5 seconds
1718

@@ -60,17 +61,16 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
6061
*
6162
* @returns A list of tenants.
6263
*/
63-
public async getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<TenantIdDescription[]> {
64-
const results: TenantIdDescription[] = [];
65-
64+
public async getTenants(account?: vscode.AuthenticationSessionAccountInformation): Promise<AzureTenant[]> {
65+
const results: AzureTenant[] = [];
6666
for await (account of account ? [account] : await vscode.authentication.getAccounts(getConfiguredAuthProviderId())) {
6767
// Added check. Without this the getSubscriptionClient function throws the NotSignedInError
6868
if (await this.isSignedIn(undefined, account)) {
6969

7070
const { client } = await this.getSubscriptionClient(account, undefined, undefined);
7171

7272
for await (const tenant of client.tenants.list()) {
73-
results.push(tenant);
73+
results.push({ ...tenant, account });
7474
}
7575
}
7676
}

auth/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
export * from './AzureAuthentication';
77
export * from './AzureDevOpsSubscriptionProvider';
8+
export * from './AzureTenant';
89
export * from './AzureSubscription';
910
export * from './AzureSubscriptionProvider';
1011
export * from './NotSignedInError';
1112
export * from './signInToTenant';
1213
export * from './utils/configuredAzureEnv';
1314
export * from './utils/getUnauthenticatedTenants';
1415
export * from './VSCodeAzureSubscriptionProvider';
15-

0 commit comments

Comments
 (0)