Skip to content

Commit 11af7ec

Browse files
Merge master into feature/q-utg
2 parents 5442909 + 2c0b4a5 commit 11af7ec

File tree

18 files changed

+8402
-3188
lines changed

18 files changed

+8402
-3188
lines changed

package-lock.json

Lines changed: 7905 additions & 2775 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@
504504
"@aws-sdk/client-ec2": "<3.696.0",
505505
"@aws-sdk/client-iam": "<3.696.0",
506506
"@aws-sdk/client-s3": "<3.696.0",
507+
"@aws-sdk/client-api-gateway": "<3.696.0",
507508
"@aws-sdk/lib-storage": "<3.696.0",
508509
"@aws-sdk/client-lambda": "<3.696.0",
509510
"@aws-sdk/client-ssm": "<3.696.0",
@@ -516,6 +517,7 @@
516517
"@aws-sdk/protocol-http": "<3.696.0",
517518
"@aws-sdk/smithy-client": "<3.696.0",
518519
"@aws-sdk/util-arn-parser": "<3.696.0",
520+
"@aws-sdk/client-codecatalyst": "<3.696.0",
519521
"@aws-sdk/s3-request-presigner": "<3.696.0",
520522
"@aws/mynah-ui": "^4.23.1",
521523
"@gerhobbelt/gitignore-parser": "^0.2.0-9",

packages/core/src/auth/sso/sdkV2Compat.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

packages/core/src/awsService/apigateway/commands/copyUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as vscode from 'vscode'
1212
import { ProgressLocation } from 'vscode'
1313

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

3030
let stages: Stage[]
3131
try {

packages/core/src/awsService/apigateway/explorer/apiGatewayNodes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as vscode from 'vscode'
1111
import { AWSTreeNodeBase } from '../../../shared/treeview/nodes/awsTreeNodeBase'
1212
import { PlaceholderNode } from '../../../shared/treeview/nodes/placeholderNode'
1313
import { compareTreeItems, makeChildrenNodes } from '../../../shared/treeview/utils'
14-
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
14+
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
1515
import { RestApi } from 'aws-sdk/clients/apigateway'
1616
import { toArrayAsync, toMap, updateInPlace } from '../../../shared/utilities/collectionUtils'
1717
import { RestApiNode } from './apiNodes'
@@ -25,7 +25,7 @@ export class ApiGatewayNode extends AWSTreeNodeBase {
2525
public constructor(
2626
private readonly partitionId: string,
2727
public override readonly regionCode: string,
28-
private readonly client = new DefaultApiGatewayClient(regionCode)
28+
private readonly client = new ApiGatewayClient(regionCode)
2929
) {
3030
super('API Gateway', vscode.TreeItemCollapsibleState.Collapsed)
3131
this.apiNodes = new Map<string, RestApiNode>()

packages/core/src/awsService/apigateway/vue/invokeRemoteRestApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { localize } from '../../../shared/utilities/vsCodeUtils'
1313
import { Result } from '../../../shared/telemetry/telemetry'
1414
import { VueWebview } from '../../../webviews/main'
1515
import { ExtContext } from '../../../shared/extensions'
16-
import { DefaultApiGatewayClient } from '../../../shared/clients/apiGatewayClient'
16+
import { ApiGatewayClient } from '../../../shared/clients/apiGateway'
1717
import { telemetry } from '../../../shared/telemetry/telemetry'
1818

1919
interface InvokeApiMessage {
@@ -50,7 +50,7 @@ export class RemoteRestInvokeWebview extends VueWebview {
5050
public constructor(
5151
private readonly data: InvokeRemoteRestApiInitialData,
5252
private readonly channel: vscode.OutputChannel,
53-
private readonly client = new DefaultApiGatewayClient(data.Region)
53+
private readonly client = new ApiGatewayClient(data.Region)
5454
) {
5555
super(RemoteRestInvokeWebview.sourcePath)
5656
}
@@ -115,7 +115,7 @@ export async function invokeRemoteRestApi(
115115
const logger: Logger = getLogger()
116116

117117
try {
118-
const client = new DefaultApiGatewayClient(params.apiNode.regionCode)
118+
const client = new ApiGatewayClient(params.apiNode.regionCode)
119119
logger.info(`Loading API Resources for API ${params.apiNode.name} (id: ${params.apiNode.id})`)
120120
const resources = (await toArrayAsync(client.getResourcesForApi(params.apiNode.id)))
121121
.sort((a, b) => a.path!.localeCompare(b.path!))

packages/core/src/codecatalyst/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import { ToolkitError, errorCode } from '../shared/errors'
2222
import { telemetry } from '../shared/telemetry/telemetry'
2323
import { showConfirmationMessage } from '../shared/utilities/messages'
2424
import { AccountStatus } from '../shared/telemetry/telemetryClient'
25-
import { CreateDevEnvironmentRequest, UpdateDevEnvironmentRequest } from 'aws-sdk/clients/codecatalyst'
2625
import { SsoConnection } from '../auth/connection'
2726
import { isInDevEnv, isRemoteWorkspace } from '../shared/vscode/env'
2827
import { commandPalette } from '../codewhisperer/commands/types'
28+
import { CreateDevEnvironmentRequest, UpdateDevEnvironmentRequest } from '@aws-sdk/client-codecatalyst'
2929

3030
/** "List CodeCatalyst Commands" command. */
3131
export async function listCommands(): Promise<void> {

packages/core/src/shared/awsClientBuilderV3.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
import { CredentialsShim } from '../auth/deprecated/loginManager'
77
import { AwsContext } from './awsContext'
8-
import { AwsCredentialIdentityProvider, Logger, RetryStrategyV2 } from '@smithy/types'
8+
import {
9+
AwsCredentialIdentityProvider,
10+
Logger,
11+
RetryStrategyV2,
12+
TokenIdentity,
13+
TokenIdentityProvider,
14+
} from '@smithy/types'
915
import { getUserAgent } from './telemetry/util'
1016
import { DevSettings } from './settings'
1117
import {
@@ -38,7 +44,7 @@ import { once } from './utilities/functionUtils'
3844
import { isWeb } from './extensionGlobals'
3945

4046
export type AwsClientConstructor<C> = new (o: AwsClientOptions) => C
41-
export type AwsCommandConstructor<CommandInput extends object, Command extends AwsCommand> = new (
47+
export type AwsCommandConstructor<CommandInput extends object, Command extends AwsCommand<CommandInput, object>> = new (
4248
o: CommandInput
4349
) => Command
4450

@@ -48,12 +54,15 @@ export interface AwsClient {
4854
middlewareStack: {
4955
add: MiddlewareStack<any, MetadataBearer>['add']
5056
}
51-
send: (command: AwsCommand, options?: any) => Promise<any>
57+
send<InputType extends object, OutputType extends object>(
58+
command: AwsCommand<InputType, OutputType>,
59+
options?: any
60+
): Promise<OutputType>
5261
destroy: () => void
5362
}
5463

55-
export interface AwsCommand {
56-
input: object
64+
export interface AwsCommand<InputType extends object, OutputType extends object> {
65+
input: InputType
5766
middlewareStack: any
5867
resolveMiddleware: (stack: any, configuration: any, options: any) => Handler<any, any>
5968
}
@@ -71,6 +80,7 @@ export interface AwsClientOptions {
7180
endpoint: string
7281
retryStrategy: RetryStrategy | RetryStrategyV2
7382
logger: Logger
83+
token: TokenIdentity | TokenIdentityProvider
7484
}
7585

7686
interface AwsServiceOptions<C extends AwsClient> {
@@ -132,7 +142,6 @@ export class AWSClientBuilderV3 {
132142
}
133143

134144
public createAwsService<C extends AwsClient>(serviceOptions: AwsServiceOptions<C>): C {
135-
const shim = this.getShim()
136145
const opt = (serviceOptions.clientOptions ?? {}) as AwsClientOptions
137146
const userAgent = serviceOptions.userAgent ?? true
138147
const keepAlive = serviceOptions.keepAlive ?? true
@@ -153,13 +162,16 @@ export class AWSClientBuilderV3 {
153162
if (!opt.requestHandler) {
154163
opt.requestHandler = this.getHttpHandler()
155164
}
156-
// TODO: add tests for refresh logic.
157-
opt.credentials = async () => {
158-
const creds = await shim.get()
159-
if (creds.expiration && creds.expiration.getTime() < Date.now()) {
160-
return shim.refresh()
165+
166+
if (!opt.credentials && !opt.token) {
167+
const shim = this.getShim()
168+
opt.credentials = async () => {
169+
const creds = await shim.get()
170+
if (creds.expiration && creds.expiration.getTime() < Date.now()) {
171+
return shim.refresh()
172+
}
173+
return creds
161174
}
162-
return creds
163175
}
164176

165177
const service = new serviceOptions.serviceClient(opt)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { ClientWrapper } from './clientWrapper'
6+
import {
7+
APIGatewayClient as ApiGatewayClientSDK,
8+
GetResourcesCommand,
9+
GetResourcesRequest,
10+
GetRestApisCommand,
11+
GetRestApisRequest,
12+
GetStagesCommand,
13+
Resource,
14+
Resources,
15+
RestApi,
16+
RestApis,
17+
Stages,
18+
TestInvokeMethodCommand,
19+
TestInvokeMethodRequest,
20+
TestInvokeMethodResponse,
21+
} from '@aws-sdk/client-api-gateway'
22+
23+
export class ApiGatewayClient extends ClientWrapper<ApiGatewayClientSDK> {
24+
public constructor(regionCode: string) {
25+
super(regionCode, ApiGatewayClientSDK)
26+
}
27+
28+
public async *getResourcesForApi(apiId: string): AsyncIterableIterator<Resource> {
29+
const request: GetResourcesRequest = {
30+
restApiId: apiId,
31+
}
32+
33+
do {
34+
const response: Resources = await this.makeRequest(GetResourcesCommand, request)
35+
36+
if (response.items !== undefined && response.items.length > 0) {
37+
yield* response.items
38+
}
39+
40+
request.position = response.position
41+
} while (request.position !== undefined)
42+
}
43+
44+
public async getStages(apiId: string): Promise<Stages> {
45+
return this.makeRequest(GetStagesCommand, {
46+
restApiId: apiId,
47+
})
48+
}
49+
50+
public async *listApis(): AsyncIterableIterator<RestApi> {
51+
const request: GetRestApisRequest = {}
52+
53+
do {
54+
const response: RestApis = await this.makeRequest(GetRestApisCommand, request)
55+
56+
if (response.items !== undefined && response.items.length > 0) {
57+
yield* response.items
58+
}
59+
60+
request.position = response.position
61+
} while (request.position !== undefined)
62+
}
63+
64+
public async testInvokeMethod(
65+
apiId: string,
66+
resourceId: string,
67+
method: string,
68+
body: string,
69+
pathWithQueryString: string | undefined
70+
): Promise<TestInvokeMethodResponse> {
71+
const request: TestInvokeMethodRequest = {
72+
restApiId: apiId,
73+
resourceId: resourceId,
74+
httpMethod: method,
75+
body: body,
76+
}
77+
if (pathWithQueryString) {
78+
request.pathWithQueryString = pathWithQueryString
79+
}
80+
81+
return this.makeRequest(TestInvokeMethodCommand, request)
82+
}
83+
}

packages/core/src/shared/clients/apiGatewayClient.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)