-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathMockAzureSubscriptionProvider.ts
More file actions
72 lines (62 loc) · 2.56 KB
/
MockAzureSubscriptionProvider.ts
File metadata and controls
72 lines (62 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { AzureAccount, AzureSubscription, AzureSubscriptionProvider, AzureTenant, TenantIdAndAccount } from '@microsoft/vscode-azext-azureauth';
import { getConfiguredAzureEnv } from '@microsoft/vscode-azext-azureauth';
import type * as vscode from 'vscode';
import type { MockResources } from './mockServiceFactory';
export class MockAzureSubscriptionProvider implements AzureSubscriptionProvider {
public constructor(private readonly resources: MockResources) { }
public onRefreshSuggested(): vscode.Disposable {
return {
dispose: () => { /* no-op */ },
};
}
public async getUnauthenticatedTenantsForAccount(): Promise<AzureTenant[]> {
return [];
}
public async getAvailableSubscriptions(): Promise<AzureSubscription[]> {
const subscriptions: AzureSubscription[] = [];
for (const acc of await this.getAccounts()) {
for (const tenant of await this.getTenantsForAccount(acc)) {
subscriptions.push(...await this.getSubscriptionsForTenant(tenant));
}
}
return subscriptions;
}
public async signIn(): Promise<boolean> {
return true;
}
public async getAccounts(): Promise<AzureAccount[]> {
return [{
id: 'accountId',
label: 'Mock Account',
environment: getConfiguredAzureEnv(),
}];
}
public async getTenantsForAccount(account: AzureAccount): Promise<AzureTenant[]> {
return [{
account,
tenantId: 'tenantId',
displayName: 'Mock Tenant',
}];
}
public async getSubscriptionsForTenant(tenant: TenantIdAndAccount): Promise<AzureSubscription[]> {
return this.resources.subscriptions.map((subscription) => ({
authentication: {
getSession: () => {
return undefined;
}
},
environment: {
portalUrl: 'portalUrl',
},
isCustomCloud: false,
name: subscription.name,
tenantId: tenant.tenantId,
account: tenant.account,
subscriptionId: subscription.subscriptionId,
} as unknown as AzureSubscription));
}
}