-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into lint/noCopyPaste2
- Loading branch information
Showing
18 changed files
with
491 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { getLogger } from '../../shared' | ||
import { Ec2Connecter } from './model' | ||
|
||
export class Ec2ConnecterMap extends Map<string, Ec2Connecter> { | ||
private static warnSize: number = 25 | ||
|
||
public getOrInit(regionCode: string) { | ||
return this.has(regionCode) ? this.get(regionCode)! : this.initManager(regionCode) | ||
} | ||
|
||
private initManager(regionCode: string): Ec2Connecter { | ||
if (this.size >= Ec2ConnecterMap.warnSize) { | ||
getLogger().warn( | ||
`Connection manager exceeded threshold of ${Ec2ConnecterMap.warnSize} with ${this.size} active connections` | ||
) | ||
} | ||
const newConnectionManager = new Ec2Connecter(regionCode) | ||
this.set(regionCode, newConnectionManager) | ||
return newConnectionManager | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { EC2, SSM } from 'aws-sdk' | ||
import { SsmClient } from '../../shared/clients/ssmClient' | ||
import { Disposable } from 'vscode' | ||
|
||
export class Ec2SessionTracker extends Map<EC2.InstanceId, SSM.SessionId> implements Disposable { | ||
public constructor( | ||
readonly regionCode: string, | ||
protected ssmClient: SsmClient | ||
) { | ||
super() | ||
} | ||
|
||
public async addSession(instanceId: EC2.InstanceId, sessionId: SSM.SessionId): Promise<void> { | ||
if (this.isConnectedTo(instanceId)) { | ||
const existingSessionId = this.get(instanceId)! | ||
await this.ssmClient.terminateSessionFromId(existingSessionId) | ||
this.set(instanceId, sessionId) | ||
} else { | ||
this.set(instanceId, sessionId) | ||
} | ||
} | ||
|
||
private async disconnectEnv(instanceId: EC2.InstanceId): Promise<void> { | ||
await this.ssmClient.terminateSessionFromId(this.get(instanceId)!) | ||
this.delete(instanceId) | ||
} | ||
|
||
public async dispose(): Promise<void> { | ||
this.forEach(async (_sessionId, instanceId) => await this.disconnectEnv(instanceId)) | ||
} | ||
|
||
public isConnectedTo(instanceId: EC2.InstanceId): boolean { | ||
return this.has(instanceId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.