-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathTargetServiceRoleAssignmentItem.ts
More file actions
56 lines (47 loc) · 2.77 KB
/
TargetServiceRoleAssignmentItem.ts
File metadata and controls
56 lines (47 loc) · 2.77 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Identity } from "@azure/arm-msi";
import { createRoleDefinitionsItems } from "@microsoft/vscode-azext-azureutils";
import { callWithTelemetryAndErrorHandling, IActionContext, ISubscriptionContext, TreeElementBase } from "@microsoft/vscode-azext-utils";
import { AzureSubscription } from "@microsoft/vscode-azureresources-api";
import { l10n, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ext } from "../extensionVariables";
export class TargetServiceRoleAssignmentItem implements TreeElementBase {
public id: string;
public label: string = l10n.t('Target services');
private _cachedChildren: TreeElementBase[] = [];
private _loadedAllSubscriptions; // used to determine whether or not to load roles from all subs
public contextValue: string = 'targetServiceRoleAssignmentItem';
constructor(readonly subscription: AzureSubscription | ISubscriptionContext, readonly msi: Identity) {
this.id = `${msi.id}/${this.label}`;
this._loadedAllSubscriptions = false;
}
async getChildren(): Promise<TreeElementBase[]> {
return await callWithTelemetryAndErrorHandling('TargetServiceRoleAssignmentItem.getChildren', async (context: IActionContext) => {
const children = await createRoleDefinitionsItems(context, this.subscription, this.msi, this.subscription.subscriptionId);
if (this._loadedAllSubscriptions) {
// filter out this sub since it's already loaded
const subscriptions = (await (await ext.subscriptionProviderFactory()).getAvailableSubscriptions({ filter: false })).filter(s => s.subscriptionId !== this.subscription.subscriptionId);
await Promise.allSettled(subscriptions.map(async (subscription) => {
children.push(...await createRoleDefinitionsItems(context, subscription, this.msi, this.subscription.subscriptionId));
}));
}
this._cachedChildren = children;
return children;
}) || [];
}
getTreeItem(): TreeItem {
return {
label: this.label,
id: this.id,
contextValue: this.contextValue,
collapsibleState: this._cachedChildren.length < 10 ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed,
};
}
setAllSubscriptionsLoaded() {
this._loadedAllSubscriptions = true;
this.contextValue = this.contextValue + 'allLoaded';
}
}