Skip to content

Commit c86daa3

Browse files
committed
add option to not overwrite the keys
1 parent 92efb95 commit c86daa3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ export class SshKeyPair {
2828
})
2929
}
3030

31-
public static async getSshKeyPair(keyPath: string, lifetime: number) {
31+
public static async getSshKeyPair(keyPath: string, lifetime: number, overwrite: boolean = true) {
3232
// Overwrite key if already exists
33-
await fs.delete(keyPath, { force: true })
34-
await fs.delete(`${keyPath}.pub`, { force: true })
33+
if (overwrite) {
34+
await fs.delete(keyPath, { force: true })
35+
await fs.delete(`${keyPath}.pub`, { force: true })
36+
}
3537

3638
await SshKeyPair.generateSshKeyPair(keyPath)
3739
return new SshKeyPair(keyPath, lifetime)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ describe('Ec2ConnectClient', function () {
139139
instanceId: 'test-id',
140140
region: 'test-region',
141141
}
142-
const mockKeys = await SshKeyPair.getSshKeyPair('', 30000)
143-
await client.sendSshKeyToInstance(testSelection, mockKeys, '')
142+
const mockKeys = await SshKeyPair.getSshKeyPair('fakeDir', 30000, false)
143+
await client.sendSshKeyToInstance(testSelection, mockKeys, 'test-user')
144144
sinon.assert.calledWith(sendCommandStub, testSelection.instanceId, 'AWS-RunShellScript')
145145
sinon.restore()
146146
})

0 commit comments

Comments
 (0)