mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Remote CLI fixes (#15117)
* fixes from vscode * update distro * fix distro * fix hygiene * reorder hygiene * Update distro Co-authored-by: chgagnon <chgagnon@microsoft.com>
This commit is contained in:
@@ -33,13 +33,8 @@ export interface StatusPipeArgs {
|
||||
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 {
|
||||
executeCommand<T>(id: string, ...args: any[]): Promise<T>;
|
||||
@@ -91,10 +86,6 @@ export class CLIServerBase {
|
||||
case 'status':
|
||||
this.getStatus(data, res);
|
||||
break;
|
||||
case 'command':
|
||||
this.runCommand(data, res)
|
||||
.catch(this.logService.error);
|
||||
break;
|
||||
default:
|
||||
res.writeHead(404);
|
||||
res.write(`Unknown message type: ${data.type}`, err => {
|
||||
@@ -137,7 +128,7 @@ export class CLIServerBase {
|
||||
const waitMarkerFileURI = waitMarkerFilePath ? URI.file(waitMarkerFilePath) : undefined;
|
||||
const preferNewWindow = !forceReuseWindow && !waitMarkerFileURI && !addMode;
|
||||
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.end();
|
||||
@@ -153,7 +144,7 @@ export class CLIServerBase {
|
||||
|
||||
private async getStatus(data: StatusPipeArgs, res: http.ServerResponse) {
|
||||
try {
|
||||
const status = await this._commands.executeCommand('_issues.getSystemStatus');
|
||||
const status = await this._commands.executeCommand('_remoteCLI.getSystemStatus');
|
||||
res.writeHead(200);
|
||||
res.write(status);
|
||||
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 {
|
||||
this._server.close();
|
||||
|
||||
|
||||
@@ -255,6 +255,12 @@ export class RemoteTerminalProcess extends Disposable implements ITerminalChildP
|
||||
|
||||
private async _execCommand(event: IRemoteTerminalProcessExecCommandEvent): Promise<void> {
|
||||
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));
|
||||
try {
|
||||
const result = await this._commandService.executeCommand(event.commandId, ...commandArgs);
|
||||
|
||||
Reference in New Issue
Block a user