Skip to content

Commit f5e3aeb

Browse files
committed
bug: ISSUE-7452: Fix EC2 Remove Workspace Connect for Any OS
1 parent d8d08e2 commit f5e3aeb

File tree

1 file changed

+11
-10
lines changed
  • packages/core/src/awsService/ec2

1 file changed

+11
-10
lines changed

packages/core/src/awsService/ec2/model.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ export interface Ec2RemoteEnv extends VscodeRemoteConnection {
4343
ssmSession: StartSessionResponse
4444
}
4545

46-
export type Ec2OS = 'Amazon Linux' | 'Ubuntu' | 'macOS'
4746
interface RemoteUser {
48-
os: Ec2OS
47+
os: string
4948
name: string
5049
}
5150

@@ -301,7 +300,7 @@ export class Ec2Connecter implements vscode.Disposable {
301300
public async tryCleanKeys(
302301
instanceId: string,
303302
hintComment: string,
304-
hostOS: Ec2OS,
303+
hostOS: string,
305304
remoteAuthorizedKeysPath: string
306305
) {
307306
try {
@@ -345,6 +344,13 @@ export class Ec2Connecter implements vscode.Disposable {
345344
return { name: 'ubuntu', os }
346345
}
347346

347+
const input = await vscode.window.showInputBox({
348+
prompt: `Unrecognized OS "${os}". Please enter the username to use for instance ${instanceId}:`,
349+
})
350+
if (input) {
351+
return { name: input, os }
352+
}
353+
348354
throw new ToolkitError(`Unrecognized OS name ${os} on instance ${instanceId}`, { code: 'UnknownEc2OS' })
349355
}
350356
}
@@ -355,14 +361,9 @@ export class Ec2Connecter implements vscode.Disposable {
355361
* @param filepath filepath (as string) to target with the command.
356362
* @returns bash command to remove lines from file.
357363
*/
358-
export function getRemoveLinesCommand(pattern: string, hostOS: Ec2OS, filepath: string): string {
364+
export function getRemoveLinesCommand(pattern: string, hostOS: string, filepath: string): string {
359365
if (pattern.includes('/')) {
360366
throw new ToolkitError(`ec2: cannot match pattern containing '/', given: ${pattern}`)
361367
}
362-
// Linux allows not passing extension to -i, whereas macOS requires zero length extension.
363-
return `sed -i${isLinux(hostOS) ? '' : " ''"} /${pattern}/d ${filepath}`
364-
}
365-
366-
function isLinux(os: Ec2OS): boolean {
367-
return os === 'Amazon Linux' || os === 'Ubuntu'
368+
return `sed -i.bak '/${pattern}/d' ${filepath} && rm ${filepath}.bak`
368369
}

0 commit comments

Comments
 (0)