From f5e3aeb8775660cb1fba50c1372a06c66b0d75dd Mon Sep 17 00:00:00 2001 From: William Anton Date: Mon, 9 Jun 2025 14:46:01 -0700 Subject: [PATCH 1/2] bug: ISSUE-7452: Fix EC2 Remove Workspace Connect for Any OS --- packages/core/src/awsService/ec2/model.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/core/src/awsService/ec2/model.ts b/packages/core/src/awsService/ec2/model.ts index ad37357fe89..a2785499d3f 100644 --- a/packages/core/src/awsService/ec2/model.ts +++ b/packages/core/src/awsService/ec2/model.ts @@ -43,9 +43,8 @@ export interface Ec2RemoteEnv extends VscodeRemoteConnection { ssmSession: StartSessionResponse } -export type Ec2OS = 'Amazon Linux' | 'Ubuntu' | 'macOS' interface RemoteUser { - os: Ec2OS + os: string name: string } @@ -301,7 +300,7 @@ export class Ec2Connecter implements vscode.Disposable { public async tryCleanKeys( instanceId: string, hintComment: string, - hostOS: Ec2OS, + hostOS: string, remoteAuthorizedKeysPath: string ) { try { @@ -345,6 +344,13 @@ export class Ec2Connecter implements vscode.Disposable { return { name: 'ubuntu', os } } + const input = await vscode.window.showInputBox({ + prompt: `Unrecognized OS "${os}". Please enter the username to use for instance ${instanceId}:`, + }) + if (input) { + return { name: input, os } + } + throw new ToolkitError(`Unrecognized OS name ${os} on instance ${instanceId}`, { code: 'UnknownEc2OS' }) } } @@ -355,14 +361,9 @@ export class Ec2Connecter implements vscode.Disposable { * @param filepath filepath (as string) to target with the command. * @returns bash command to remove lines from file. */ -export function getRemoveLinesCommand(pattern: string, hostOS: Ec2OS, filepath: string): string { +export function getRemoveLinesCommand(pattern: string, hostOS: string, filepath: string): string { if (pattern.includes('/')) { throw new ToolkitError(`ec2: cannot match pattern containing '/', given: ${pattern}`) } - // Linux allows not passing extension to -i, whereas macOS requires zero length extension. - return `sed -i${isLinux(hostOS) ? '' : " ''"} /${pattern}/d ${filepath}` -} - -function isLinux(os: Ec2OS): boolean { - return os === 'Amazon Linux' || os === 'Ubuntu' + return `sed -i.bak '/${pattern}/d' ${filepath} && rm ${filepath}.bak` } From 140abe6eac9a9a073f035b783879c2fc71086a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armin=20Anton=E2=80=9D=20=E2=88=B4?= Date: Mon, 9 Jun 2025 17:09:29 -0700 Subject: [PATCH 2/2] Update packages/core/src/awsService/ec2/model.ts Co-authored-by: Justin M. Keyes --- packages/core/src/awsService/ec2/model.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/awsService/ec2/model.ts b/packages/core/src/awsService/ec2/model.ts index a2785499d3f..b7f5aa2dd90 100644 --- a/packages/core/src/awsService/ec2/model.ts +++ b/packages/core/src/awsService/ec2/model.ts @@ -345,7 +345,7 @@ export class Ec2Connecter implements vscode.Disposable { } const input = await vscode.window.showInputBox({ - prompt: `Unrecognized OS "${os}". Please enter the username to use for instance ${instanceId}:`, + prompt: `Unrecognized OS "${os}". Enter the username for instance ${instanceId}:`, }) if (input) { return { name: input, os }