From 53a2781d80213421a679d43fe833c9355da0bda0 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Tue, 23 Jan 2018 15:49:41 +0100 Subject: [PATCH] add extensions control url --- package.json | 4 +- .../common/extensionManagement.ts | 7 +++ .../node/extensionGalleryService.ts | 44 ++++++++++++++++++- src/vs/platform/node/product.ts | 1 + 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index dc5b1d8acfc..744c612172f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "code-oss-dev", "version": "1.20.0", - "distro": "2478cca5311e147817eef29cb81c0995a3517842", + "distro": "e14a5a3afaae557ff651b344462ed39e776435a2", "author": { "name": "Microsoft Corporation" }, @@ -129,4 +129,4 @@ "windows-mutex": "^0.2.0", "windows-process-tree": "0.1.6" } -} +} \ No newline at end of file diff --git a/src/vs/platform/extensionManagement/common/extensionManagement.ts b/src/vs/platform/extensionManagement/common/extensionManagement.ts index 8ae29d3f01c..6512e977822 100644 --- a/src/vs/platform/extensionManagement/common/extensionManagement.ts +++ b/src/vs/platform/extensionManagement/common/extensionManagement.ts @@ -229,6 +229,12 @@ export enum StatisticType { Uninstall = 'uninstall' } +export interface IReportedExtension { + id: IExtensionIdentifier; + malicious: boolean; + slow: boolean; +} + export interface IExtensionGalleryService { _serviceBrand: any; isEnabled(): boolean; @@ -240,6 +246,7 @@ export interface IExtensionGalleryService { getChangelog(extension: IGalleryExtension): TPromise; loadCompatibleVersion(extension: IGalleryExtension): TPromise; loadAllDependencies(dependencies: IExtensionIdentifier[]): TPromise; + getExtensionsReport(): TPromise; } export interface InstallExtensionEvent { diff --git a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts index e79adfe2cbc..ae9aa3ca924 100644 --- a/src/vs/platform/extensionManagement/node/extensionGalleryService.ts +++ b/src/vs/platform/extensionManagement/node/extensionGalleryService.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import { TPromise } from 'vs/base/common/winjs.base'; import { distinct } from 'vs/base/common/arrays'; import { getErrorMessage, isPromiseCanceledError } from 'vs/base/common/errors'; -import { StatisticType, IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionManifest, IExtensionIdentifier } from 'vs/platform/extensionManagement/common/extensionManagement'; +import { StatisticType, IGalleryExtension, IExtensionGalleryService, IGalleryExtensionAsset, IQueryOptions, SortBy, SortOrder, IExtensionManifest, IExtensionIdentifier, IReportedExtension } from 'vs/platform/extensionManagement/common/extensionManagement'; import { getGalleryExtensionId, getGalleryExtensionTelemetryData, adoptToGalleryExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil'; import { assign, getOrDefault } from 'vs/base/common/objects'; import { IRequestService } from 'vs/platform/request/node/request'; @@ -23,6 +23,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' import { readFile } from 'vs/base/node/pfs'; import { writeFileAndFlushSync } from 'vs/base/node/extfs'; import { generateUuid, isUUID } from 'vs/base/common/uuid'; +import { values } from 'vs/base/common/map'; interface IRawGalleryExtensionFile { assetType: string; @@ -309,11 +310,17 @@ function toExtension(galleryExtension: IRawGalleryExtension, extensionsGalleryUr }; } +interface IRawExtensionsReport { + malicious: string[]; + slow: string[]; +} + export class ExtensionGalleryService implements IExtensionGalleryService { _serviceBrand: any; private extensionsGalleryUrl: string; + private extensionsControlUrl: string; private readonly commonHeadersPromise: TPromise<{ [key: string]: string; }>; @@ -324,6 +331,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService { ) { const config = product.extensionsGallery; this.extensionsGalleryUrl = config && config.serviceUrl; + this.extensionsControlUrl = config && config.controlUrl; this.commonHeadersPromise = resolveMarketplaceHeaders(this.environmentService); } @@ -711,6 +719,40 @@ export class ExtensionGalleryService implements IExtensionGalleryService { } return false; } + + getExtensionsReport(): TPromise { + if (!this.isEnabled()) { + return TPromise.wrapError(new Error('No extension gallery service configured.')); + } + + if (!this.extensionsControlUrl) { + return TPromise.as([]); + } + + return this.requestService.request({ type: 'GET', url: this.extensionsControlUrl }).then(context => { + if (context.res.statusCode !== 200) { + return TPromise.wrapError(new Error('Could not get extensions report.')); + } + + return asJson(context).then(result => { + const map = new Map(); + + for (const id of result.malicious) { + const ext = map.get(id) || { id: { id }, malicious: true, slow: false }; + ext.malicious = true; + map.set(id, ext); + } + + for (const id of result.slow) { + const ext = map.get(id) || { id: { id }, malicious: false, slow: true }; + ext.slow = true; + map.set(id, ext); + } + + return TPromise.as(values(map)); + }); + }); + } } export function resolveMarketplaceHeaders(environmentService: IEnvironmentService): TPromise<{ [key: string]: string; }> { diff --git a/src/vs/platform/node/product.ts b/src/vs/platform/node/product.ts index 00a76d6fc38..ebd1d8e22a4 100644 --- a/src/vs/platform/node/product.ts +++ b/src/vs/platform/node/product.ts @@ -25,6 +25,7 @@ export interface IProductConfiguration { extensionsGallery: { serviceUrl: string; itemUrl: string; + controlUrl: string; }; extensionTips: { [id: string]: string; }; extensionImportantTips: { [id: string]: { name: string; pattern: string; }; }; -- GitLab