chore(vscode): update to 1.56.0
This commit is contained in:
@ -0,0 +1,73 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
import { getExperimentationService, IExperimentationService, IExperimentationTelemetry, TargetPopulation } from 'vscode-tas-client';
|
||||
|
||||
export class ExperimentationTelemetry implements IExperimentationTelemetry {
|
||||
private sharedProperties: Record<string, string> = {};
|
||||
|
||||
constructor(private baseReporter: TelemetryReporter) { }
|
||||
|
||||
sendTelemetryEvent(eventName: string, properties?: Record<string, string>, measurements?: Record<string, number>) {
|
||||
this.baseReporter.sendTelemetryEvent(
|
||||
eventName,
|
||||
{
|
||||
...this.sharedProperties,
|
||||
...properties,
|
||||
},
|
||||
measurements,
|
||||
);
|
||||
}
|
||||
|
||||
sendTelemetryErrorEvent(
|
||||
eventName: string,
|
||||
properties?: Record<string, string>,
|
||||
_measurements?: Record<string, number>,
|
||||
) {
|
||||
this.baseReporter.sendTelemetryErrorEvent(eventName, {
|
||||
...this.sharedProperties,
|
||||
...properties,
|
||||
});
|
||||
}
|
||||
|
||||
setSharedProperty(name: string, value: string): void {
|
||||
this.sharedProperties[name] = value;
|
||||
}
|
||||
|
||||
postEvent(eventName: string, props: Map<string, string>): void {
|
||||
const event: Record<string, string> = {};
|
||||
for (const [key, value] of props) {
|
||||
event[key] = value;
|
||||
}
|
||||
this.sendTelemetryEvent(eventName, event);
|
||||
}
|
||||
|
||||
dispose(): Promise<any> {
|
||||
return this.baseReporter.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function getTargetPopulation(): TargetPopulation {
|
||||
switch (vscode.env.uriScheme) {
|
||||
case 'vscode':
|
||||
return TargetPopulation.Public;
|
||||
case 'vscode-insiders':
|
||||
return TargetPopulation.Insiders;
|
||||
case 'vscode-exploration':
|
||||
return TargetPopulation.Internal;
|
||||
case 'code-oss':
|
||||
return TargetPopulation.Team;
|
||||
default:
|
||||
return TargetPopulation.Public;
|
||||
}
|
||||
}
|
||||
|
||||
export async function createExperimentationService(context: vscode.ExtensionContext, telemetry: ExperimentationTelemetry): Promise<IExperimentationService> {
|
||||
const id = context.extension.id;
|
||||
const version = context.extension.packageJSON.version;
|
||||
return getExperimentationService(id, version, getTargetPopulation(), telemetry, context.globalState);
|
||||
}
|
@ -8,10 +8,14 @@ import { GitHubAuthenticationProvider, onDidChangeSessions } from './github';
|
||||
import { uriHandler } from './githubServer';
|
||||
import Logger from './common/logger';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
import { createExperimentationService, ExperimentationTelemetry } from './experimentationService';
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
const { name, version, aiKey } = require('../package.json') as { name: string, version: string, aiKey: string };
|
||||
const telemetryReporter = new TelemetryReporter(name, version, aiKey);
|
||||
const telemetryReporter = new ExperimentationTelemetry(new TelemetryReporter(name, version, aiKey));
|
||||
|
||||
const experimentationService = await createExperimentationService(context, telemetryReporter);
|
||||
await experimentationService.initialFetch;
|
||||
|
||||
context.subscriptions.push(vscode.window.registerUriHandler(uriHandler));
|
||||
const loginService = new GitHubAuthenticationProvider(context, telemetryReporter);
|
||||
|
@ -9,7 +9,7 @@ import { Keychain } from './common/keychain';
|
||||
import { GitHubServer, NETWORK_ERROR } from './githubServer';
|
||||
import Logger from './common/logger';
|
||||
import { arrayEquals } from './common/utils';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
import { ExperimentationTelemetry } from './experimentationService';
|
||||
|
||||
export const onDidChangeSessions = new vscode.EventEmitter<vscode.AuthenticationProviderAuthenticationSessionsChangeEvent>();
|
||||
|
||||
@ -30,7 +30,7 @@ export class GitHubAuthenticationProvider {
|
||||
|
||||
private _keychain: Keychain;
|
||||
|
||||
constructor(context: vscode.ExtensionContext, telemetryReporter: TelemetryReporter) {
|
||||
constructor(context: vscode.ExtensionContext, telemetryReporter: ExperimentationTelemetry) {
|
||||
this._keychain = new Keychain(context);
|
||||
this._githubServer = new GitHubServer(telemetryReporter);
|
||||
}
|
||||
|
@ -9,12 +9,17 @@ import fetch, { Response } from 'node-fetch';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { PromiseAdapter, promiseFromEvent } from './common/utils';
|
||||
import Logger from './common/logger';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
import { ExperimentationTelemetry } from './experimentationService';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export const NETWORK_ERROR = 'network error';
|
||||
<<<<<<< HEAD
|
||||
const AUTH_RELAY_SERVER = 'auth.code-server.dev';
|
||||
=======
|
||||
const AUTH_RELAY_SERVER = 'vscode-auth.github.com';
|
||||
// const AUTH_RELAY_STAGING_SERVER = 'client-auth-staging-14a768b.herokuapp.com';
|
||||
>>>>>>> 58ce849223667f77dc0d6d7658870ca3f815e17f
|
||||
|
||||
class UriEventHandler extends vscode.EventEmitter<vscode.Uri> implements vscode.UriHandler {
|
||||
public handleUri(uri: vscode.Uri) {
|
||||
@ -42,10 +47,16 @@ export class GitHubServer {
|
||||
private _pendingStates = new Map<string, string[]>();
|
||||
private _codeExchangePromises = new Map<string, { promise: Promise<string>, cancel: vscode.EventEmitter<void> }>();
|
||||
|
||||
constructor(private readonly telemetryReporter: TelemetryReporter) { }
|
||||
constructor(private readonly telemetryReporter: ExperimentationTelemetry) { }
|
||||
|
||||
private isTestEnvironment(url: vscode.Uri): boolean {
|
||||
return url.authority === 'vscode-web-test-playground.azurewebsites.net' || url.authority.startsWith('localhost:');
|
||||
return /\.azurewebsites\.net$/.test(url.authority) || url.authority.startsWith('localhost:');
|
||||
}
|
||||
|
||||
// TODO@joaomoreno TODO@RMacfarlane
|
||||
private async isNoCorsEnvironment(): Promise<boolean> {
|
||||
const uri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate`));
|
||||
return uri.scheme === 'https' && /^vscode\./.test(uri.authority);
|
||||
}
|
||||
|
||||
public async login(scopes: string): Promise<string> {
|
||||
@ -53,7 +64,10 @@ export class GitHubServer {
|
||||
this.updateStatusBarItem(true);
|
||||
|
||||
const state = uuid();
|
||||
const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate`));
|
||||
|
||||
// TODO@joaomoreno TODO@RMacfarlane
|
||||
const nocors = await this.isNoCorsEnvironment();
|
||||
const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate${nocors ? '?nocors=true' : ''}`));
|
||||
|
||||
if (this.isTestEnvironment(callbackUri)) {
|
||||
const token = await vscode.window.showInputBox({ prompt: 'GitHub Personal Access Token', ignoreFocusOut: true });
|
||||
@ -80,7 +94,7 @@ export class GitHubServer {
|
||||
const existingStates = this._pendingStates.get(scopes) || [];
|
||||
this._pendingStates.set(scopes, [...existingStates, state]);
|
||||
|
||||
const uri = vscode.Uri.parse(`https://${AUTH_RELAY_SERVER}/authorize/?callbackUri=${encodeURIComponent(callbackUri.toString())}&scope=${scopes}&state=${state}&responseType=code&authServer=https://github.com`);
|
||||
const uri = vscode.Uri.parse(`https://${AUTH_RELAY_SERVER}/authorize/?callbackUri=${encodeURIComponent(callbackUri.toString())}&scope=${scopes}&state=${state}&responseType=code&authServer=https://github.com${nocors ? '&nocors=true' : ''}`);
|
||||
await vscode.env.openExternal(uri);
|
||||
}
|
||||
|
||||
@ -121,23 +135,36 @@ export class GitHubServer {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await fetch(`https://${AUTH_RELAY_SERVER}/token?code=${code}&state=${query.state}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
}
|
||||
});
|
||||
const url = `https://${AUTH_RELAY_SERVER}/token?code=${code}&state=${query.state}`;
|
||||
|
||||
if (result.ok) {
|
||||
const json = await result.json();
|
||||
// TODO@joao: remove
|
||||
if (query.nocors) {
|
||||
try {
|
||||
const json: any = await vscode.commands.executeCommand('_workbench.fetchJSON', url, 'POST');
|
||||
Logger.info('Token exchange success!');
|
||||
resolve(json.access_token);
|
||||
} else {
|
||||
reject(result.statusText);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const result = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
const json = await result.json();
|
||||
Logger.info('Token exchange success!');
|
||||
resolve(json.access_token);
|
||||
} else {
|
||||
reject(result.statusText);
|
||||
}
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
};
|
||||
|
||||
@ -222,6 +249,12 @@ export class GitHubServer {
|
||||
}
|
||||
|
||||
public async checkIsEdu(token: string): Promise<void> {
|
||||
const nocors = await this.isNoCorsEnvironment();
|
||||
|
||||
if (nocors) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await fetch('https://education.github.com/api/user', {
|
||||
headers: {
|
||||
|
Reference in New Issue
Block a user