Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/policies/basePolicy.ts
4772 views
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 { renderADMLString } from './render.ts';
7
import type { Category, LanguageTranslations, NlsString, Policy, PolicyType } from './types.ts';
8
9
export abstract class BasePolicy implements Policy {
10
readonly type: PolicyType;
11
readonly name: string;
12
readonly category: Category;
13
readonly minimumVersion: string;
14
protected description: NlsString;
15
protected moduleName: string;
16
17
constructor(
18
type: PolicyType,
19
name: string,
20
category: Category,
21
minimumVersion: string,
22
description: NlsString,
23
moduleName: string,
24
) {
25
this.type = type;
26
this.name = name;
27
this.category = category;
28
this.minimumVersion = minimumVersion;
29
this.description = description;
30
this.moduleName = moduleName;
31
}
32
33
protected renderADMLString(nlsString: NlsString, translations?: LanguageTranslations): string {
34
return renderADMLString(this.name, this.moduleName, nlsString, translations);
35
}
36
37
renderADMX(regKey: string) {
38
return [
39
`<policy name="${this.name}" class="Both" displayName="$(string.${this.name})" explainText="$(string.${this.name}_${this.description.nlsKey.replace(/\./g, '_')})" key="Software\\Policies\\Microsoft\\${regKey}" presentation="$(presentation.${this.name})">`,
40
` <parentCategory ref="${this.category.name.nlsKey}" />`,
41
` <supportedOn ref="Supported_${this.minimumVersion.replace(/\./g, '_')}" />`,
42
` <elements>`,
43
...this.renderADMXElements(),
44
` </elements>`,
45
`</policy>`
46
];
47
}
48
49
protected abstract renderADMXElements(): string[];
50
51
renderADMLStrings(translations?: LanguageTranslations) {
52
return [
53
`<string id="${this.name}">${this.name}</string>`,
54
this.renderADMLString(this.description, translations)
55
];
56
}
57
58
renderADMLPresentation(): string {
59
return `<presentation id="${this.name}">${this.renderADMLPresentationContents()}</presentation>`;
60
}
61
62
protected abstract renderADMLPresentationContents(): string;
63
64
renderProfile() {
65
return [`<key>${this.name}</key>`, this.renderProfileValue()];
66
}
67
68
renderProfileManifest(translations?: LanguageTranslations): string {
69
return `<dict>
70
${this.renderProfileManifestValue(translations)}
71
</dict>`;
72
}
73
74
abstract renderJsonValue(): string | number | boolean | object | null;
75
abstract renderProfileValue(): string;
76
abstract renderProfileManifestValue(translations?: LanguageTranslations): string;
77
}
78
79