src/vs/platform/extensionManagement/common/allowedExtensionsService.ts
144 LOC · 143 covered · 1 uncovered · 47 ranges · 33 concepts · 30 introducers · 29 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
allowedExtensionsService.ts ×7
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Disposable } from '../../../base/common/lifecycle.js';
import * as nls from '../../../nls.js';
import { IGalleryExtension, AllowedExtensionsConfigKey, IAllowedExtensionsService, AllowedExtensionsConfigValueType } from './extensionManagement.js';
import { ExtensionType, IExtension, TargetPlatform } from '../../extensions/common/extensions.js';
import { IProductService } from '../../product/common/productService.js';
import { createCommandUri, IMarkdownString, MarkdownString } from '../../../base/common/htmlContent.js';
import { IConfigurationService } from '../../configuration/common/configuration.js';
import { isBoolean, isObject, isUndefined } from '../../../base/common/types.js';
import { Emitter } from '../../../base/common/event.js';
function isGalleryExtension(extension: unknown): extension is IGalleryExtension {
allowedExtensionsService.ts ×4
return (extension as IGalleryExtension).type === 'gallery';
}
function isIExtension(extension: unknown): extension is IExtension {
allowedExtensionsService.ts ×2
return (extension as IExtension).type === ExtensionType.User || (extension as IExtension).type === ExtensionType.System;
}
const VersionRegex = /^(?<version>\d+\.\d+\.\d+(-.*)?)(@(?<platform>.+))?$/;
export class AllowedExtensionsService extends Disposable implements IAllowedExtensionsService {
_serviceBrand: undefined;
private readonly publisherOrgs: string[];
private _allowedExtensionsConfigValue: AllowedExtensionsConfigValueType | undefined;
get allowedExtensionsConfigValue(): AllowedExtensionsConfigValueType | undefined {
return this._allowedExtensionsConfigValue;
}
private _onDidChangeAllowedExtensions = this._register(new Emitter<void>());
readonly onDidChangeAllowedExtensionsConfigValue = this._onDidChangeAllowedExtensions.event;
constructor(
@IProductService productService: IProductService,
@IConfigurationService protected readonly configurationService: IConfigurationService
) {
super();
this.publisherOrgs = productService.extensionPublisherOrgs?.map(p => p.toLowerCase()) ?? [];
this._allowedExtensionsConfigValue = this.getAllowedExtensionsValue();
this._register(this.configurationService.onDidChangeConfiguration(e => {
this._allowedExtensionsConfigValue = this.getAllowedExtensionsValue();
this._onDidChangeAllowedExtensions.fire();
}
}
private getAllowedExtensionsValue(): AllowedExtensionsConfigValueType | undefined {
const value = this.configurationService.getValue<AllowedExtensionsConfigValueType | undefined>(AllowedExtensionsConfigKey);
if (!isObject(value) || Array.isArray(value)) {
}
const entries = Object.entries(value).map(([key, value]) => [key.toLowerCase(), value]);
allowedExtensionsService.ts ×1
if (entries.length === 1 && entries[0][0] === '*' && entries[0][1] === true) {
allowedExtensionsService.ts ×7
}
isAllowed(extension: IGalleryExtension | IExtension | { id: string; publisherDisplayName: string | undefined; version?: string; prerelease?: boolean; targetPlatform?: TargetPlatform }): true | IMarkdownString {
}
let id: string, version: string, targetPlatform: TargetPlatform, prerelease: boolean, publisher: string, publisherDisplayName: string | undefined;
if (isGalleryExtension(extension)) {
version = extension.version;
prerelease = extension.properties.isPreReleaseVersion;
publisher = extension.publisher.toLowerCase();
publisherDisplayName = extension.publisherDisplayName.toLowerCase();
targetPlatform = extension.properties.targetPlatform;
version = extension.manifest.version;
prerelease = extension.preRelease;
publisher = extension.manifest.publisher.toLowerCase();
publisherDisplayName = extension.publisherDisplayName?.toLowerCase();
targetPlatform = extension.targetPlatform;
version = extension.version ?? '*';
targetPlatform = extension.targetPlatform ?? TargetPlatform.UNIVERSAL;
prerelease = extension.prerelease ?? false;
publisher = extension.id.substring(0, extension.id.indexOf('.')).toLowerCase();
publisherDisplayName = extension.publisherDisplayName?.toLowerCase();
}
const settingsCommandLink = createCommandUri('workbench.action.openSettings', { query: `@id:${AllowedExtensionsConfigKey}` }).toString();
const extensionValue = this._allowedExtensionsConfigValue[id];
const extensionReason = new MarkdownString(nls.localize('specific extension not allowed', "it is not in the [allowed list]({0})", settingsCommandLink));
if (!isUndefined(extensionValue)) {
}
return new MarkdownString(nls.localize('extension prerelease not allowed', "the pre-release versions of this extension are not in the [allowed list]({0})", settingsCommandLink));
allowedExtensionsService.ts ×1
}
if (version !== '*' && Array.isArray(extensionValue) && !extensionValue.some(v => {
allowedExtensionsService.ts ×4
if (match && match.groups) {
const { platform: p, version: v } = match.groups;
if (v !== version) {
}
if (targetPlatform !== TargetPlatform.UNIVERSAL && p && targetPlatform !== p) {
allowedExtensionsService.ts ×2
}
}
return false;
return new MarkdownString(nls.localize('specific version of extension not allowed', "the version {0} of this extension is not in the [allowed list]({1})", version, settingsCommandLink));
allowedExtensionsService.ts ×1
}
}
const publisherKey = publisherDisplayName && this.publisherOrgs.includes(publisherDisplayName) ? publisherDisplayName : publisher;
allowedExtensionsService.ts ×3
const publisherValue = this._allowedExtensionsConfigValue[publisherKey];
if (!isUndefined(publisherValue)) {
return publisherValue ? true : new MarkdownString(nls.localize('publisher not allowed', "the extensions from this publisher are not in the [allowed list]({1})", publisherKey, settingsCommandLink));
allowedExtensionsService.ts ×1
}
return new MarkdownString(nls.localize('prerelease versions from this publisher not allowed', "the pre-release versions from this publisher are not in the [allowed list]({1})", publisherKey, settingsCommandLink));
allowedExtensionsService.ts ×1
}
}
if (this._allowedExtensionsConfigValue['*'] === true) {
}
return extensionReason;