Skip to content

Commit

Permalink
Merge master into feature/q-utg
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-toolkit-automation authored Mar 11, 2025
2 parents 5442909 + 2c0b4a5 commit 11af7ec
Show file tree
Hide file tree
Showing 18 changed files with 8,402 additions and 3,188 deletions.
10,680 changes: 7,905 additions & 2,775 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@
"@aws-sdk/client-ec2": "<3.696.0",
"@aws-sdk/client-iam": "<3.696.0",
"@aws-sdk/client-s3": "<3.696.0",
"@aws-sdk/client-api-gateway": "<3.696.0",
"@aws-sdk/lib-storage": "<3.696.0",
"@aws-sdk/client-lambda": "<3.696.0",
"@aws-sdk/client-ssm": "<3.696.0",
Expand All @@ -516,6 +517,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.

4 changes: 2 additions & 2 deletions packages/core/src/awsService/apigateway/commands/copyUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as vscode from 'vscode'
import { ProgressLocation } from 'vscode'

import { Stage } from 'aws-sdk/clients/apigateway'
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
import { defaultDnsSuffix, RegionProvider } from '../../../shared/regions/regionProvider'
import { getLogger } from '../../../shared/logger/logger'
import { telemetry } from '../../../shared/telemetry/telemetry'
Expand All @@ -25,7 +25,7 @@ interface StageInvokeUrlQuickPick extends vscode.QuickPickItem {
export async function copyUrlCommand(node: RestApiNode, regionProvider: RegionProvider): Promise<void> {
const region = node.regionCode
const dnsSuffix = regionProvider.getDnsSuffixForRegion(region) || defaultDnsSuffix
const client = new DefaultApiGatewayClient(region)
const client = new ApiGatewayClient(region)

let stages: Stage[]
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as vscode from 'vscode'
import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
import { PlaceholderNode } from '../../../shared/treeview/nodes/placeholderNode'
import { compareTreeItems, makeChildrenNodes } from '../../../shared/treeview/utils'
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
import { RestApi } from 'aws-sdk/clients/apigateway'
import { toArrayAsync, toMap, updateInPlace } from '../../../shared/utilities/collectionUtils'
import { RestApiNode } from './apiNodes'
Expand All @@ -25,7 +25,7 @@ export class ApiGatewayNode extends AWSTreeNodeBase {
public constructor(
private readonly partitionId: string,
public override readonly regionCode: string,
private readonly client = new DefaultApiGatewayClient(regionCode)
private readonly client = new ApiGatewayClient(regionCode)
) {
super('API Gateway', vscode.TreeItemCollapsibleState.Collapsed)
this.apiNodes = new Map<string, RestApiNode>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { localize } from '../../../shared/utilities/vsCodeUtils'
import { Result } from '../../../shared/telemetry/telemetry'
import { VueWebview } from '../../../webviews/main'
import { ExtContext } from '../../../shared/extensions'
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
import { telemetry } from '../../../shared/telemetry/telemetry'

interface InvokeApiMessage {
Expand Down Expand Up @@ -50,7 +50,7 @@ export class RemoteRestInvokeWebview extends VueWebview {
public constructor(
private readonly data: InvokeRemoteRestApiInitialData,
private readonly channel: vscode.OutputChannel,
private readonly client = new DefaultApiGatewayClient(data.Region)
private readonly client = new ApiGatewayClient(data.Region)
) {
super(RemoteRestInvokeWebview.sourcePath)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ export async function invokeRemoteRestApi(
const logger: Logger = getLogger()

try {
const client = new DefaultApiGatewayClient(params.apiNode.regionCode)
const client = new ApiGatewayClient(params.apiNode.regionCode)
logger.info(`Loading API Resources for API ${params.apiNode.name} (id: ${params.apiNode.id})`)
const resources = (await toArrayAsync(client.getResourcesForApi(params.apiNode.id)))
.sort((a, b) => a.path!.localeCompare(b.path!))
Expand Down
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
83 changes: 83 additions & 0 deletions packages/core/src/shared/clients/apiGateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { ClientWrapper } from './clientWrapper'
import {
APIGatewayClient as ApiGatewayClientSDK,
GetResourcesCommand,
GetResourcesRequest,
GetRestApisCommand,
GetRestApisRequest,
GetStagesCommand,
Resource,
Resources,
RestApi,
RestApis,
Stages,
TestInvokeMethodCommand,
TestInvokeMethodRequest,
TestInvokeMethodResponse,
} from '@aws-sdk/client-api-gateway'

export class ApiGatewayClient extends ClientWrapper<ApiGatewayClientSDK> {
public constructor(regionCode: string) {
super(regionCode, ApiGatewayClientSDK)
}

public async *getResourcesForApi(apiId: string): AsyncIterableIterator<Resource> {
const request: GetResourcesRequest = {
restApiId: apiId,
}

do {
const response: Resources = await this.makeRequest(GetResourcesCommand, request)

if (response.items !== undefined && response.items.length > 0) {
yield* response.items
}

request.position = response.position
} while (request.position !== undefined)
}

public async getStages(apiId: string): Promise<Stages> {
return this.makeRequest(GetStagesCommand, {
restApiId: apiId,
})
}

public async *listApis(): AsyncIterableIterator<RestApi> {
const request: GetRestApisRequest = {}

do {
const response: RestApis = await this.makeRequest(GetRestApisCommand, request)

if (response.items !== undefined && response.items.length > 0) {
yield* response.items
}

request.position = response.position
} while (request.position !== undefined)
}

public async testInvokeMethod(
apiId: string,
resourceId: string,
method: string,
body: string,
pathWithQueryString: string | undefined
): Promise<TestInvokeMethodResponse> {
const request: TestInvokeMethodRequest = {
restApiId: apiId,
resourceId: resourceId,
httpMethod: method,
body: body,
}
if (pathWithQueryString) {
request.pathWithQueryString = pathWithQueryString
}

return this.makeRequest(TestInvokeMethodCommand, request)
}
}
83 changes: 0 additions & 83 deletions packages/core/src/shared/clients/apiGatewayClient.ts

This file was deleted.

Loading

0 comments on commit 11af7ec

Please sign in to comment.