Skip to content

Commit 84c4258

Browse files
committed
refactor sending command
1 parent 9a2cc2c commit 84c4258

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,18 @@ export class Ec2Connecter implements vscode.Disposable {
300300
) {
301301
try {
302302
const deleteExistingKeyCommand = getRemoveLinesCommand(hintComment, hostOS, remoteAuthorizedKeysPath)
303-
await this.ssmClient.sendCommandAndWait(instanceId, 'AWS-RunShellScript', {
304-
commands: [deleteExistingKeyCommand],
305-
})
303+
await this.sendCommandAndWait(instanceId, deleteExistingKeyCommand)
306304
} catch (e) {
307305
getLogger().warn(`ec2: failed to clean keys: %O`, e)
308306
}
309307
}
310308

309+
private async sendCommandAndWait(instanceId: string, command: string) {
310+
return await this.ssmClient.sendCommandAndWait(instanceId, 'AWS-RunShellScript', {
311+
commands: [command],
312+
})
313+
}
314+
311315
public async sendSshKeyToInstance(
312316
selection: Ec2Selection,
313317
sshKeyPair: SshKeyPair,
@@ -322,9 +326,7 @@ export class Ec2Connecter implements vscode.Disposable {
322326
const writeKeyCommand = appendStr([sshPubKey.replace('\n', ''), hintComment].join(' '))
323327

324328
await this.attemptToCleanKeys(selection.instanceId, hintComment, remoteUser.os, remoteAuthorizedKeysPath)
325-
await this.ssmClient.sendCommandAndWait(selection.instanceId, 'AWS-RunShellScript', {
326-
commands: [writeKeyCommand],
327-
})
329+
await this.sendCommandAndWait(selection.instanceId, writeKeyCommand)
328330
}
329331

330332
public async getRemoteUser(instanceId: string): Promise<RemoteUser> {
@@ -342,7 +344,7 @@ export class Ec2Connecter implements vscode.Disposable {
342344
}
343345

344346
/**
345-
* Generate bash command (as string) to remove lines containing `hintComment`.
347+
* Generate bash command (as string) to remove lines containing `pattern`.
346348
* @param pattern pattern for deleted lines.
347349
* @param filepath filepath (as string) to target with the command.
348350
* @returns bash command to remove lines from file.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"type": "Bug Fix",
3-
"description": "EC2: avoid overwriting authorized_keys file"
3+
"description": "EC2: avoid overwriting authorized_keys file on remote"
44
}

0 commit comments

Comments
 (0)