Skip to content
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

refactor(codecatalyst): migrate client to sdkv3 #6734

Merged
merged 32 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
49ddc84
Merge master into feature/sdkv3
aws-toolkit-automation Mar 5, 2025
1814a28
Merge master into feature/sdkv3
aws-toolkit-automation Mar 5, 2025
596f395
Merge master into feature/sdkv3
aws-toolkit-automation Mar 5, 2025
9f614b0
Merge master into feature/sdkv3
aws-toolkit-automation Mar 5, 2025
2b84748
Merge master into feature/sdkv3
aws-toolkit-automation Mar 5, 2025
50645a7
Merge master into feature/sdkv3
aws-toolkit-automation Mar 5, 2025
b07678e
deps: install new client
Hweinstock Mar 6, 2025
a823e64
feat: add token support in client config options
Hweinstock Mar 6, 2025
f3c84e4
refactor: remove retryOptions since default strategy exists in v3
Hweinstock Mar 6, 2025
d120eea
types: enhance types to be more specific
Hweinstock Mar 6, 2025
6c396e1
refactor: duplicate core functions for v3 temporarily
Hweinstock Mar 6, 2025
5ffe5d2
refactor: migrate first api call
Hweinstock Mar 6, 2025
514ee86
fix: add back retry logic so that tests can run
Hweinstock Mar 6, 2025
53a4676
merge: resolve conflicts
Hweinstock Mar 6, 2025
30dbd59
refactor: migrate more requests
Hweinstock Mar 6, 2025
01ec7f5
fix: support tokens by not overwriting with shim
Hweinstock Mar 6, 2025
39ac5c6
refactor: avoid getting shim until needed
Hweinstock Mar 7, 2025
5be837c
refactor: use the same token provider for both clients
Hweinstock Mar 7, 2025
2d51a23
temp: only test cc in e2e tests
Hweinstock Mar 7, 2025
8abdea8
refactor: move more functions over to v3
Hweinstock Mar 7, 2025
655af91
refactor: tighten typing constraints
Hweinstock Mar 7, 2025
2093e06
refactor: make types more precise
Hweinstock Mar 8, 2025
e12b87e
fix: rework error handling to work with different error shapes
Hweinstock Mar 10, 2025
4b2a28a
refactor: migrate more api calls
Hweinstock Mar 10, 2025
c42a56f
fix: implement new token provider to work with v3
Hweinstock Mar 10, 2025
0bc81d9
refactor: fully remove sdkv2 imports
Hweinstock Mar 10, 2025
d15ee2e
refactor: cleanup minor problems
Hweinstock Mar 10, 2025
f0c3e31
types: refactor types to be less redundant
Hweinstock Mar 10, 2025
79e1de1
refactor: remove v3 suffix
Hweinstock Mar 10, 2025
6cb2deb
merge: resolve package-lock conflicts
Hweinstock Mar 11, 2025
11d6cf5
test: avoid unnecessary churn
Hweinstock Mar 11, 2025
e6c875f
refactor: remove v2 workaround, document v3 impl
Hweinstock Mar 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,828 changes: 6,709 additions & 2,119 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@
"@aws-sdk/protocol-http": "<3.696.0",
"@aws-sdk/smithy-client": "<3.696.0",
"@aws-sdk/util-arn-parser": "<3.696.0",
"@aws-sdk/client-codecatalyst": "<3.696.0",
"@aws-sdk/s3-request-presigner": "<3.696.0",
"@aws/mynah-ui": "^4.23.1",
"@gerhobbelt/gitignore-parser": "^0.2.0-9",
Expand Down
57 changes: 0 additions & 57 deletions packages/core/src/auth/sso/sdkV2Compat.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/codecatalyst/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { ToolkitError, errorCode } from '../shared/errors'
import { telemetry } from '../shared/telemetry/telemetry'
import { showConfirmationMessage } from '../shared/utilities/messages'
import { AccountStatus } from '../shared/telemetry/telemetryClient'
import { CreateDevEnvironmentRequest, UpdateDevEnvironmentRequest } from 'aws-sdk/clients/codecatalyst'
import { SsoConnection } from '../auth/connection'
import { isInDevEnv, isRemoteWorkspace } from '../shared/vscode/env'
import { commandPalette } from '../codewhisperer/commands/types'
import { CreateDevEnvironmentRequest, UpdateDevEnvironmentRequest } from '@aws-sdk/client-codecatalyst'

/** "List CodeCatalyst Commands" command. */
export async function listCommands(): Promise<void> {
Expand Down
36 changes: 24 additions & 12 deletions packages/core/src/shared/awsClientBuilderV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

import { CredentialsShim } from '../auth/deprecated/loginManager'
import { AwsContext } from './awsContext'
import { AwsCredentialIdentityProvider, Logger, RetryStrategyV2 } from '@smithy/types'
import {
AwsCredentialIdentityProvider,
Logger,
RetryStrategyV2,
TokenIdentity,
TokenIdentityProvider,
} from '@smithy/types'
import { getUserAgent } from './telemetry/util'
import { DevSettings } from './settings'
import {
Expand Down Expand Up @@ -38,7 +44,7 @@ import { once } from './utilities/functionUtils'
import { isWeb } from './extensionGlobals'

export type AwsClientConstructor<C> = new (o: AwsClientOptions) => C
export type AwsCommandConstructor<CommandInput extends object, Command extends AwsCommand> = new (
export type AwsCommandConstructor<CommandInput extends object, Command extends AwsCommand<CommandInput, object>> = new (
o: CommandInput
) => Command

Expand All @@ -48,12 +54,15 @@ export interface AwsClient {
middlewareStack: {
add: MiddlewareStack<any, MetadataBearer>['add']
}
send: (command: AwsCommand, options?: any) => Promise<any>
send<InputType extends object, OutputType extends object>(
command: AwsCommand<InputType, OutputType>,
options?: any
): Promise<OutputType>
destroy: () => void
}

export interface AwsCommand {
input: object
export interface AwsCommand<InputType extends object, OutputType extends object> {
input: InputType
middlewareStack: any
resolveMiddleware: (stack: any, configuration: any, options: any) => Handler<any, any>
}
Expand All @@ -71,6 +80,7 @@ export interface AwsClientOptions {
endpoint: string
retryStrategy: RetryStrategy | RetryStrategyV2
logger: Logger
token: TokenIdentity | TokenIdentityProvider
}

interface AwsServiceOptions<C extends AwsClient> {
Expand Down Expand Up @@ -132,7 +142,6 @@ export class AWSClientBuilderV3 {
}

public createAwsService<C extends AwsClient>(serviceOptions: AwsServiceOptions<C>): C {
const shim = this.getShim()
const opt = (serviceOptions.clientOptions ?? {}) as AwsClientOptions
const userAgent = serviceOptions.userAgent ?? true
const keepAlive = serviceOptions.keepAlive ?? true
Expand All @@ -153,13 +162,16 @@ export class AWSClientBuilderV3 {
if (!opt.requestHandler) {
opt.requestHandler = this.getHttpHandler()
}
// TODO: add tests for refresh logic.
opt.credentials = async () => {
const creds = await shim.get()
if (creds.expiration && creds.expiration.getTime() < Date.now()) {
return shim.refresh()

if (!opt.credentials && !opt.token) {
const shim = this.getShim()
opt.credentials = async () => {
const creds = await shim.get()
if (creds.expiration && creds.expiration.getTime() < Date.now()) {
return shim.refresh()
}
return creds
}
return creds
}

const service = new serviceOptions.serviceClient(opt)
Expand Down
15 changes: 7 additions & 8 deletions packages/core/src/shared/clients/clientWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import globals from '../extensionGlobals'
import { AwsClient, AwsClientConstructor, AwsCommand, AwsCommandConstructor } from '../awsClientBuilderV3'
import { PaginationConfiguration, Paginator } from '@aws-sdk/types'
import { AsyncCollection, toCollection } from '../utilities/asyncCollection'
import { isDefined } from '../utilities/tsUtils'

type SDKPaginator<C, CommandInput extends object, CommandOutput extends object> = (
config: Omit<PaginationConfiguration, 'client'> & { client: C },
Expand All @@ -28,10 +29,12 @@ export abstract class ClientWrapper<C extends AwsClient> implements vscode.Dispo
: globals.sdkClientBuilderV3.getAwsService(args)
}

protected async makeRequest<CommandInput extends object, CommandOutput extends object, Command extends AwsCommand>(
command: AwsCommandConstructor<CommandInput, Command>,
commandOptions: CommandInput
): Promise<CommandOutput> {
protected async makeRequest<
CommandInput extends object,
CommandOutput extends object,
CommandOptions extends CommandInput,
Command extends AwsCommand<CommandInput, CommandOutput>,
>(command: AwsCommandConstructor<CommandInput, Command>, commandOptions: CommandOptions): Promise<CommandOutput> {
return await this.getClient().send(new command(commandOptions))
}

Expand All @@ -47,10 +50,6 @@ export abstract class ClientWrapper<C extends AwsClient> implements vscode.Dispo
.map((o) => o.filter(isDefined))

return collection

function isDefined<T>(i: T | undefined): i is T {
return i !== undefined
}
}

protected async getFirst<CommandInput extends object, CommandOutput extends object, Output extends object>(
Expand Down
Loading
Loading