-
Notifications
You must be signed in to change notification settings - Fork 733
refactor(sdkv3): migrate ssm client #6137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 37 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
f464309
move in main file
Hweinstock afc0a26
add test file
Hweinstock be3c42a
add more detail to telemetry emitted
Hweinstock 89ef745
add a default retry strategy
Hweinstock 4890f73
use class type instead of interface
Hweinstock ccfd462
give up type info so that it compiles
Hweinstock 0675afe
refactor types to have any middleware
Hweinstock 3e8caf6
remove interface
Hweinstock 67784e1
remove unused types
Hweinstock 1d29b18
simplify naming
Hweinstock 4500cdc
rename test file
Hweinstock 4e2dffe
change name to temp
Hweinstock 470e0f5
switch name to lower case
Hweinstock fb605f1
implement general wrapper
Hweinstock 239b597
add new ssm client
Hweinstock f02c897
migrate ssm use cases
Hweinstock 3b123af
try manually adjusting versions in the streaming client
Hweinstock 2ba6bf0
bump smithy-client version
Hweinstock 6fc31e5
Merge branch 'feature/sdkv3' into sdkv3/startMigration
Hweinstock 8512617
merge in upstream changes
Hweinstock a63255f
undo font char changes
Hweinstock 80efaa3
undo workaround
Hweinstock 6a04c98
add link to relevant issue
Hweinstock 58809be
move dep to core module
Hweinstock 3e3a01e
merge in upstream changes
Hweinstock 4880c16
improve middleware typing
Hweinstock c312676
merge in upstream changes
Hweinstock 6dc2405
remove redundant type
Hweinstock 9cd4afa
make types more specific
Hweinstock 35d1b36
Merge branch 'sdkv3/startMigration' into sdkv3/migrateSSM
Hweinstock 13f4d03
improve types further
Hweinstock 222ff04
improve typing
Hweinstock 32a7230
Merge branch 'sdkv3/startMigration' into sdkv3/migrateSSM
Hweinstock 3a37405
loosen type to fix error
Hweinstock 829ef71
merge: resolve conflicts
Hweinstock 1cdbd87
types: slightly improve types
Hweinstock 3b50424
refactor: small cleanup
Hweinstock 5904a28
refactor: rename wrappers to clients
Hweinstock efea2a2
refactor: improving typing constraints
Hweinstock 8f736e1
merge: resolve conflicts
Hweinstock c04f2f9
fix: avoid index.ts imports
Hweinstock c10dc63
merge: fix import conflict
Hweinstock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,120 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { | ||
| SSMClient, | ||
| Session, | ||
| StartSessionCommand, | ||
| TerminateSessionCommand, | ||
| TerminateSessionResponse, | ||
| StartSessionCommandOutput, | ||
| DescribeInstanceInformationCommand, | ||
| DescribeInstanceInformationCommandInput, | ||
| InstanceInformation, | ||
| SendCommandCommand, | ||
| SendCommandCommandOutput, | ||
| waitUntilCommandExecuted, | ||
| SessionState, | ||
| DescribeSessionsCommand, | ||
| } from '@aws-sdk/client-ssm' | ||
| import { WaiterState } from '@smithy/util-waiter' | ||
| import { ToolkitError } from '../errors' | ||
| import { ClientWrapper } from './wrapper' | ||
|
|
||
| export class SSMWrapper extends ClientWrapper<SSMClient> { | ||
| public constructor(public override readonly regionCode: string) { | ||
| super(regionCode, SSMClient) | ||
| } | ||
|
|
||
| public async terminateSession(session: Session): Promise<TerminateSessionResponse> { | ||
| const sessionId = session.SessionId! | ||
| return await this.terminateSessionFromId(sessionId) | ||
| } | ||
|
|
||
| public async terminateSessionFromId(sessionId: string): Promise<TerminateSessionResponse> { | ||
| return await this.makeRequest(TerminateSessionCommand, { SessionId: sessionId }) | ||
| } | ||
|
|
||
| public async startSession( | ||
| target: string, | ||
| document?: string, | ||
| reason?: string, | ||
| parameters?: Record<string, string[]> | ||
| ): Promise<StartSessionCommandOutput> { | ||
| return await this.makeRequest(StartSessionCommand, { | ||
| Target: target, | ||
| DocumentName: document, | ||
| Reason: reason, | ||
| Parameters: parameters, | ||
| }) | ||
| } | ||
|
|
||
| public async describeInstance(target: string): Promise<InstanceInformation> { | ||
| const response = this.makePaginatedRequest( | ||
| DescribeInstanceInformationCommand, | ||
| { | ||
| InstanceInformationFilterList: [ | ||
| { | ||
| key: 'InstanceIds', | ||
| valueSet: [target], | ||
| }, | ||
| ], | ||
| } as DescribeInstanceInformationCommandInput, | ||
| 'InstanceIds' | ||
| ) | ||
| const resolvedResponse = await response.flatten().flatten().promise() | ||
| return resolvedResponse[0]! | ||
| } | ||
|
|
||
| public async getTargetPlatformName(target: string): Promise<string> { | ||
| const instanceInformation = await this.describeInstance(target) | ||
| return instanceInformation.PlatformName! | ||
| } | ||
|
|
||
| public async sendCommand( | ||
| target: string, | ||
| documentName: string, | ||
| parameters: Record<string, string[]> | ||
| ): Promise<SendCommandCommandOutput> { | ||
| return await this.makeRequest(SendCommandCommand, { | ||
| InstanceIds: [target], | ||
| DocumentName: documentName, | ||
| Parameters: parameters, | ||
| }) | ||
| } | ||
|
|
||
| private async waitForCommand(commandId: string, target: string) { | ||
| const result = await waitUntilCommandExecuted( | ||
| { client: await this.getClient(), maxWaitTime: 30 }, | ||
| { CommandId: commandId, InstanceId: target } | ||
| ) | ||
| if (result.state !== WaiterState.SUCCESS) { | ||
| throw new ToolkitError(`Command ${commandId} failed to execute on target ${target}`) | ||
| } | ||
| } | ||
|
|
||
| public async sendCommandAndWait( | ||
| target: string, | ||
| documentName: string, | ||
| parameters: Record<string, string[]> | ||
| ): Promise<SendCommandCommandOutput> { | ||
| const response = await this.sendCommand(target, documentName, parameters) | ||
| try { | ||
| await this.waitForCommand(response.Command!.CommandId!, target) | ||
| return response | ||
| } catch (err) { | ||
| throw new ToolkitError(`Failed in sending command to target ${target}`, { cause: err as Error }) | ||
| } | ||
| } | ||
|
|
||
| public async getInstanceAgentPingStatus(target: string): Promise<string> { | ||
| const instanceInformation = await this.describeInstance(target) | ||
| return instanceInformation ? instanceInformation.PingStatus! : 'Inactive' | ||
| } | ||
|
|
||
| public async describeSessions(state: SessionState) { | ||
| return await this.makePaginatedRequest(DescribeSessionsCommand, { State: state }, 'Sessions').promise() | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.