Skip to content

Commit

Permalink
Use args based confirmation for log upload instead of using stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
mjbvz committed Feb 1, 2018
1 parent d272072 commit 1872949
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 56 deletions.
35 changes: 13 additions & 22 deletions src/vs/code/electron-main/logUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import * as os from 'os';
import * as cp from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as readline from 'readline';
import * as net from 'net';

import { localize } from 'vs/nls';
import { ILaunchChannel } from 'vs/code/electron-main/launch';
Expand Down Expand Up @@ -53,31 +51,24 @@ export async function uploadLogs(
const outZip = await zipLogs(logsPath);
const result = await postLogs(endpoint, outZip, requestService);
console.log(localize('didUploadLogs', 'Upload successful! Log file ID: {0}', result.blob_id));
} else {
console.log(localize('userDeniedUpload', 'Canceled upload'));
}
}

async function promptUserToConfirmLogUpload(
function promptUserToConfirmLogUpload(
logsPath: string,
environmentService: IEnvironmentService
): Promise<boolean> {
const message = localize('logUploadPromptHeader', 'Upload session logs to secure endpoint?')
+ '\n\n' + localize('logUploadPromptBody', 'Please review your log files here: \'{0}\'', logsPath)
+ '\n\n' + localize('logUploadPromptBodyDetails', 'Logs may contain personal information such as full paths and file contents.')
+ '\n\n' + localize('logUploadPromptKey', 'I have reviewed my logs (enter \'y\' to confirm upload)');

const rl = readline.createInterface({
input: net.connect(environmentService.args['upload-logs-stdin-pipe']),
output: process.stdout
});

return new TPromise<boolean>(resolve =>
rl.question(message,
(answer: string) => {
rl.close();
resolve(answer && answer.trim()[0].toLowerCase() === 'y');
}));
): boolean {
const confirmKey = 'iConfirmLogsUpload';
if ((environmentService.args['upload-logs'] || '').toLowerCase() === confirmKey.toLowerCase()) {
return true;
} else {
const message = localize('logUploadPromptHeader', 'Upload session logs to secure endpoint?')
+ '\n\n' + localize('logUploadPromptBody', 'Please review your log files here: \'{0}\'', logsPath)
+ '\n\n' + localize('logUploadPromptBodyDetails', 'Logs may contain personal information such as full paths and file contents.')
+ '\n\n' + localize('logUploadPromptKey', 'Once you have reviewed your logs, please run code with \'--upload-logs={0}\'', confirmKey);
console.log(message);
return false;
}
}

async function postLogs(
Expand Down
4 changes: 2 additions & 2 deletions src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
}

// Log uploader usage info
if (environmentService.args['upload-logs']) {
if (typeof environmentService.args['upload-logs'] !== 'undefined') {
logService.warn('Warning: The --upload-logs argument can only be used if Code is already running. Please run it again after Code has started.');
throw new ExpectedError('Terminating...');
}
Expand Down Expand Up @@ -201,7 +201,7 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
}

// Log uploader
if (environmentService.args['upload-logs']) {
if (typeof environmentService.args['upload-logs'] !== 'undefined') {
return uploadLogs(channel, requestService, environmentService)
.then(() => TPromise.wrapError(new ExpectedError()));
}
Expand Down
30 changes: 3 additions & 27 deletions src/vs/code/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function main(argv: string[]): TPromise<any> {

const processCallbacks: ((child: ChildProcess) => Thenable<any>)[] = [];

const verbose = args.verbose || args.status || args['upload-logs'];
const verbose = args.verbose || args.status || typeof args['upload-logs'] !== 'undefined';
if (verbose) {
env['ELECTRON_ENABLE_LOGGING'] = '1';

Expand Down Expand Up @@ -312,32 +312,8 @@ export async function main(argv: string[]): TPromise<any> {
env
};

if (args['upload-logs']) {
// Create a socket for writing
const pipeName = `code-stdin-${Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 3)}.sock`;
stdinFilePath = isWindows
? '\\\\.\\pipe\\' + pipeName
: paths.join(os.tmpdir(), pipeName);

// open tmp file for writing
let stdinFileError: Error;
try {
const stdErrServer = net.createServer(stream => {
process.stdin.pipe(stream);
});
stdErrServer.listen(stdinFilePath);
} catch (error) {
stdinFileError = error;
if (verbose) {
console.error(`Failed to create file to read via stdin: ${error.toString()}`);
}
}

if (!stdinFileError) {
argv = argv.concat('--upload-logs-stdin-pipe', stdinFilePath);
}

options['stdio'] = ['ignore', 'pipe', 'pipe'];
if (typeof args['upload-logs'] !== undefined) {
options['stdio'] = ['pipe', 'pipe', 'pipe'];
} else if (!verbose) {
options['stdio'] = 'ignore';
}
Expand Down
3 changes: 1 addition & 2 deletions src/vs/platform/environment/common/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export interface ParsedArgs {
'skip-add-to-recently-opened'?: boolean;
'file-write'?: boolean;
'file-chmod'?: boolean;
'upload-logs'?: boolean;
'upload-logs-stdin-pipe'?: string;
'upload-logs'?: string;
}

export const IEnvironmentService = createDecorator<IEnvironmentService>('environmentService');
Expand Down
5 changes: 2 additions & 3 deletions src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const options: minimist.Opts = {
'enable-proposed-api',
'export-default-configuration',
'install-source',
'upload-logs-stdin-pipe'
'upload-logs'
],
boolean: [
'help',
Expand Down Expand Up @@ -61,8 +61,7 @@ const options: minimist.Opts = {
'skip-add-to-recently-opened',
'status',
'file-write',
'file-chmod',
'upload-logs'
'file-chmod'
],
alias: {
add: 'a',
Expand Down

0 comments on commit 1872949

Please sign in to comment.