forked from microsoft/agent-governance-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoliciesView.ts
More file actions
71 lines (60 loc) · 2.47 KB
/
policiesView.ts
File metadata and controls
71 lines (60 loc) · 2.47 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* Policies Tree View Provider
*
* Displays active policies in the sidebar.
*/
import * as vscode from 'vscode';
import { PolicyEngine } from '../policyEngine';
export class PoliciesProvider implements vscode.TreeDataProvider<PolicyItem> {
private _onDidChangeTreeData: vscode.EventEmitter<PolicyItem | undefined | null | void> = new vscode.EventEmitter<PolicyItem | undefined | null | void>();
readonly onDidChangeTreeData: vscode.Event<PolicyItem | undefined | null | void> = this._onDidChangeTreeData.event;
constructor(private policyEngine: PolicyEngine) {}
refresh(): void {
this._onDidChangeTreeData.fire();
}
getTreeItem(element: PolicyItem): vscode.TreeItem {
return element;
}
getChildren(element?: PolicyItem): Thenable<PolicyItem[]> {
if (!element) {
const policies = this.policyEngine.getActivePolicies();
return Promise.resolve(policies.map(p => new PolicyItem(p.name, p.enabled, p.severity)));
}
return Promise.resolve([]);
}
}
class PolicyItem extends vscode.TreeItem {
constructor(
public readonly name: string,
public readonly enabled: boolean,
public readonly severity: string
) {
super(name, vscode.TreeItemCollapsibleState.None);
this.description = enabled ? `${severity}` : 'disabled';
this.tooltip = `${name}\nSeverity: ${severity}\nStatus: ${enabled ? 'Enabled' : 'Disabled'}`;
if (enabled) {
this.iconPath = this.getSeverityIcon(severity);
} else {
this.iconPath = new vscode.ThemeIcon('circle-slash', new vscode.ThemeColor('disabledForeground'));
}
this.command = {
command: 'workbench.action.openSettings',
title: 'Configure',
arguments: [`agentOS.policies`]
};
}
private getSeverityIcon(severity: string): vscode.ThemeIcon {
switch (severity) {
case 'critical':
return new vscode.ThemeIcon('shield', new vscode.ThemeColor('errorForeground'));
case 'high':
return new vscode.ThemeIcon('shield', new vscode.ThemeColor('list.warningForeground'));
case 'medium':
return new vscode.ThemeIcon('shield', new vscode.ThemeColor('editorInfo.foreground'));
default:
return new vscode.ThemeIcon('shield');
}
}
}