Merge from vscode 2e5312cd61ff99c570299ecc122c52584265eda2

This commit is contained in:
ADS Merger
2020-04-23 02:50:35 +00:00
committed by Anthony Dresser
parent 3603f55d97
commit 7f1d8fc32f
659 changed files with 22709 additions and 12497 deletions

View File

@@ -20,8 +20,9 @@ import { FormattingOptions } from 'vs/base/common/jsonFormatter';
import { URI } from 'vs/base/common/uri';
import { joinPath, isEqualOrParent } from 'vs/base/common/resources';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IProductService } from 'vs/platform/product/common/productService';
import { IProductService, ConfigurationSyncStore } from 'vs/platform/product/common/productService';
import { distinct } from 'vs/base/common/arrays';
import { isArray, isString, isObject } from 'vs/base/common/types';
export const CONFIGURATION_SYNC_STORE_KEY = 'configurationSync.store';
@@ -119,17 +120,33 @@ export interface IUserData {
content: string | null;
}
export type IAuthenticationProvider = { id: string, scopes: string[] };
export interface IUserDataSyncStore {
url: URI;
authenticationProviderId: string;
authenticationProviders: IAuthenticationProvider[];
}
export function isAuthenticationProvider(thing: any): thing is IAuthenticationProvider {
return thing
&& isObject(thing)
&& isString(thing.id)
&& isArray(thing.scopes);
}
export function getUserDataSyncStore(productService: IProductService, configurationService: IConfigurationService): IUserDataSyncStore | undefined {
const value = configurationService.getValue<{ url: string, authenticationProviderId: string }>(CONFIGURATION_SYNC_STORE_KEY) || productService[CONFIGURATION_SYNC_STORE_KEY];
if (value && value.url && value.authenticationProviderId) {
const value = configurationService.getValue<ConfigurationSyncStore>(CONFIGURATION_SYNC_STORE_KEY) || productService[CONFIGURATION_SYNC_STORE_KEY];
if (value
&& isString(value.url)
&& isObject(value.authenticationProviders)
&& Object.keys(value.authenticationProviders).every(authenticationProviderId => isArray(value.authenticationProviders[authenticationProviderId].scopes))
) {
return {
url: joinPath(URI.parse(value.url), 'v1'),
authenticationProviderId: value.authenticationProviderId
authenticationProviders: Object.keys(value.authenticationProviders).reduce<IAuthenticationProvider[]>((result, id) => {
result.push({ id, scopes: value.authenticationProviders[id].scopes });
return result;
}, [])
};
}
return undefined;
@@ -299,6 +316,7 @@ export interface IUserDataSyncEnablementService {
isEnabled(): boolean;
setEnablement(enabled: boolean): void;
canToggleEnablement(): boolean;
isResourceEnabled(resource: SyncResource): boolean;
setResourceEnablement(resource: SyncResource, enabled: boolean): void;

View File

@@ -30,22 +30,24 @@ export class UserDataSyncEnablementService extends Disposable implements IUserDa
constructor(
@IStorageService private readonly storageService: IStorageService,
@ITelemetryService private readonly telemetryService: ITelemetryService,
@IEnvironmentService environmentService: IEnvironmentService,
@IEnvironmentService private readonly environmentService: IEnvironmentService,
) {
super();
switch (environmentService.sync) {
case 'on':
this.setEnablement(true);
break;
case 'off':
this.setEnablement(false);
break;
}
this._register(storageService.onDidChangeStorage(e => this.onDidStorageChange(e)));
}
canToggleEnablement(): boolean {
return this.environmentService.sync === undefined;
}
isEnabled(): boolean {
return this.storageService.getBoolean(enablementKey, StorageScope.GLOBAL, false);
switch (this.environmentService.sync) {
case 'on':
return true;
case 'off':
return false;
}
return this.storageService.getBoolean(enablementKey, StorageScope.GLOBAL, this.environmentService.enableSyncByDefault);
}
setEnablement(enabled: boolean): void {

View File

@@ -195,7 +195,8 @@ export class UserDataSyncStoreService extends Disposable implements IUserDataSyn
const commonHeaders = await this.commonHeadersPromise;
options.headers = assign(options.headers || {}, commonHeaders, {
'authorization': `Bearer ${authToken}`,
'X-Account-Type': authToken.authenticationProviderId,
'authorization': `Bearer ${authToken.token}`,
});
this.logService.trace('Sending request to server', { url: options.url, type: options.type, headers: { ...options.headers, ...{ authorization: undefined } } });

View File

@@ -32,7 +32,7 @@ import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFil
import { ConfigurationService } from 'vs/platform/configuration/common/configurationService';
import { Disposable } from 'vs/base/common/lifecycle';
import { Emitter } from 'vs/base/common/event';
import { IAuthenticationTokenService } from 'vs/platform/authentication/common/authentication';
import { IAuthenticationTokenService, IUserDataSyncAuthToken } from 'vs/platform/authentication/common/authentication';
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
import { UserDataSyncBackupStoreService } from 'vs/platform/userDataSync/common/userDataSyncBackupStoreService';
@@ -65,7 +65,7 @@ export class UserDataSyncClient extends Disposable {
_serviceBrand: undefined, ...product, ...{
'configurationSync.store': {
url: this.testServer.url,
authenticationProviderId: 'test'
authenticationProviders: { 'test': { scopes: [] } }
}
}
});
@@ -82,8 +82,8 @@ export class UserDataSyncClient extends Disposable {
this.instantiationService.stub(IRequestService, this.testServer);
this.instantiationService.stub(IAuthenticationTokenService, <Partial<IAuthenticationTokenService>>{
onDidChangeToken: new Emitter<string | undefined>().event,
async getToken() { return 'token'; }
onDidChangeToken: new Emitter<IUserDataSyncAuthToken | undefined>().event,
async getToken() { return { authenticationProviderId: 'id', token: 'token' }; }
});
this.instantiationService.stub(IUserDataSyncLogService, logService);