Remote CLI fixes (#15117) (#15125)

* fixes from vscode

* update distro

* fix distro

* fix hygiene

* reorder hygiene

* Update distro

Co-authored-by: chgagnon <chgagnon@microsoft.com>
(cherry picked from commit 1b78008258)
This commit is contained in:
Aditya Bist
2021-04-13 21:15:22 -07:00
committed by GitHub
parent d4e25f4d89
commit ebe835ec99
5 changed files with 27 additions and 49 deletions

View File

@@ -114,6 +114,8 @@ const indentationFilter = [
'!extensions/big-data-cluster/src/bigDataCluster/controller/apiGenerated.ts', '!extensions/big-data-cluster/src/bigDataCluster/controller/apiGenerated.ts',
'!extensions/big-data-cluster/src/bigDataCluster/controller/clusterApiGenerated2.ts', '!extensions/big-data-cluster/src/bigDataCluster/controller/clusterApiGenerated2.ts',
'!resources/linux/snap/electron-launch', '!resources/linux/snap/electron-launch',
'!extensions/markdown-language-features/media/*.js',
'!extensions/simple-browser/media/*.js',
'!resources/xlf/LocProject.json', // {{SQL CARBON EDIT}} '!resources/xlf/LocProject.json', // {{SQL CARBON EDIT}}
'!build/**/*' // {{SQL CARBON EDIT}} '!build/**/*' // {{SQL CARBON EDIT}}
]; ];

View File

@@ -11,20 +11,21 @@ export async function deactivate(): Promise<any> {
} }
export async function activate(context: ExtensionContext): Promise<void> { export async function activate(context: ExtensionContext): Promise<void> {
context.subscriptions.push(commands.registerCommand('git.credential', async (data: any) => { context.subscriptions.push(commands.registerCommand('git.credential', async (_data: any) => {
try { return { stdout: '', stderr: '', code: 0 };
const { stdout, stderr } = await exec(`git credential ${data.command}`, { // try {
stdin: data.stdin, // const { stdout, stderr } = await exec(`git credential ${data.command}`, {
env: Object.assign(process.env, { GIT_TERMINAL_PROMPT: '0' }) // stdin: data.stdin,
}); // env: Object.assign(process.env, { GIT_TERMINAL_PROMPT: '0' })
return { stdout, stderr, code: 0 }; // });
} catch ({ stdout, stderr, error }) { // return { stdout, stderr, code: 0 };
const code = error.code || 0; // } catch ({ stdout, stderr, error }) {
if (stderr.indexOf('terminal prompts disabled') !== -1) { // const code = error.code || 0;
stderr = ''; // if (stderr.indexOf('terminal prompts disabled') !== -1) {
} // stderr = '';
return { stdout, stderr, code }; // }
} // return { stdout, stderr, code };
// }
})); }));
} }

View File

@@ -1,7 +1,7 @@
{ {
"name": "azuredatastudio", "name": "azuredatastudio",
"version": "1.28.0", "version": "1.28.0",
"distro": "4462480cd081b5729600b15921dbb445b46b0de9", "distro": "0de18a407aaa6294c15918753b6032c7bb919aaf",
"author": { "author": {
"name": "Microsoft Corporation" "name": "Microsoft Corporation"
}, },

View File

@@ -33,13 +33,8 @@ export interface StatusPipeArgs {
type: 'status'; type: 'status';
} }
export interface RunCommandPipeArgs {
type: 'command';
command: string;
args: any[];
}
export type PipeCommand = OpenCommandPipeArgs | StatusPipeArgs | RunCommandPipeArgs | OpenExternalCommandPipeArgs; export type PipeCommand = OpenCommandPipeArgs | StatusPipeArgs | OpenExternalCommandPipeArgs;
export interface ICommandsExecuter { export interface ICommandsExecuter {
executeCommand<T>(id: string, ...args: any[]): Promise<T>; executeCommand<T>(id: string, ...args: any[]): Promise<T>;
@@ -91,10 +86,6 @@ export class CLIServerBase {
case 'status': case 'status':
this.getStatus(data, res); this.getStatus(data, res);
break; break;
case 'command':
this.runCommand(data, res)
.catch(this.logService.error);
break;
default: default:
res.writeHead(404); res.writeHead(404);
res.write(`Unknown message type: ${data.type}`, err => { res.write(`Unknown message type: ${data.type}`, err => {
@@ -137,7 +128,7 @@ export class CLIServerBase {
const waitMarkerFileURI = waitMarkerFilePath ? URI.file(waitMarkerFilePath) : undefined; const waitMarkerFileURI = waitMarkerFilePath ? URI.file(waitMarkerFilePath) : undefined;
const preferNewWindow = !forceReuseWindow && !waitMarkerFileURI && !addMode; const preferNewWindow = !forceReuseWindow && !waitMarkerFileURI && !addMode;
const windowOpenArgs: IOpenWindowOptions = { forceNewWindow, diffMode, addMode, gotoLineMode, forceReuseWindow, preferNewWindow, waitMarkerFileURI }; const windowOpenArgs: IOpenWindowOptions = { forceNewWindow, diffMode, addMode, gotoLineMode, forceReuseWindow, preferNewWindow, waitMarkerFileURI };
this._commands.executeCommand('_files.windowOpen', urisToOpen, windowOpenArgs); this._commands.executeCommand('_remoteCLI.windowOpen', urisToOpen, windowOpenArgs);
} }
res.writeHead(200); res.writeHead(200);
res.end(); res.end();
@@ -153,7 +144,7 @@ export class CLIServerBase {
private async getStatus(data: StatusPipeArgs, res: http.ServerResponse) { private async getStatus(data: StatusPipeArgs, res: http.ServerResponse) {
try { try {
const status = await this._commands.executeCommand('_issues.getSystemStatus'); const status = await this._commands.executeCommand('_remoteCLI.getSystemStatus');
res.writeHead(200); res.writeHead(200);
res.write(status); res.write(status);
res.end(); res.end();
@@ -168,28 +159,6 @@ export class CLIServerBase {
} }
} }
private async runCommand(data: RunCommandPipeArgs, res: http.ServerResponse) {
try {
const { command, args } = data;
const result = await this._commands.executeCommand(command, ...args);
res.writeHead(200);
res.write(JSON.stringify(result), err => {
if (err) {
this.logService.error(err);
}
});
res.end();
} catch (err) {
res.writeHead(500);
res.write(String(err), err => {
if (err) {
this.logService.error(err);
}
});
res.end();
}
}
dispose(): void { dispose(): void {
this._server.close(); this._server.close();

View File

@@ -255,6 +255,12 @@ export class RemoteTerminalProcess extends Disposable implements ITerminalChildP
private async _execCommand(event: IRemoteTerminalProcessExecCommandEvent): Promise<void> { private async _execCommand(event: IRemoteTerminalProcessExecCommandEvent): Promise<void> {
const reqId = event.reqId; const reqId = event.reqId;
const commandId = event.commandId;
const allowedCommands = ['_remoteCLI.openExternal', '_remoteCLI.windowOpen', '_remoteCLI.getSystemStatus', '_remoteCLI.manageExtensions'];
if (!allowedCommands.includes(commandId)) {
this._remoteTerminalChannel.sendCommandResultToTerminalProcess(this._remoteTerminalId, reqId, true, 'Invalid remote cli command: ' + commandId);
return;
}
const commandArgs = event.commandArgs.map(arg => revive(arg)); const commandArgs = event.commandArgs.map(arg => revive(arg));
try { try {
const result = await this._commandService.executeCommand(event.commandId, ...commandArgs); const result = await this._commandService.executeCommand(event.commandId, ...commandArgs);