File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
packages/core/src/awsService/ec2 Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export class SshKeyPair {
1717 private deleted : boolean = false
1818
1919 private constructor (
20- private keyPath : string ,
20+ private readonly keyPath : string ,
2121 lifetime : number
2222 ) {
2323 this . publicKeyPath = `${ keyPath } .pub`
@@ -30,9 +30,9 @@ export class SshKeyPair {
3030
3131 public static async getSshKeyPair ( keyPath : string , lifetime : number ) {
3232 // Overwrite key if already exists
33- if ( await fs . existsFile ( keyPath ) ) {
34- await fs . delete ( keyPath )
35- }
33+ await fs . delete ( keyPath , { force : true } )
34+ await fs . delete ( ` ${ keyPath } .pub` , { force : true } )
35+
3636 await SshKeyPair . generateSshKeyPair ( keyPath )
3737 return new SshKeyPair ( keyPath , lifetime )
3838 }
@@ -72,6 +72,10 @@ export class SshKeyPair {
7272 }
7373
7474 public async delete ( ) : Promise < void > {
75+ if ( await fs . existsDir ( this . keyPath ) ) {
76+ throw new Error ( 'ec2: key path points to directory, not file' )
77+ }
78+
7579 await fs . delete ( this . keyPath )
7680 await fs . delete ( this . publicKeyPath )
7781
You can’t perform that action at this time.
0 commit comments