|
3 | 3 | * SPDX-License-Identifier: Apache-2.0 |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { STS } from 'aws-sdk' |
7 | | -import { Credentials } from '@aws-sdk/types' |
| 6 | +import { STSClient, AssumeRoleCommand, GetCallerIdentityCommand } from '@aws-sdk/client-sts' |
| 7 | +import type { AssumeRoleRequest, AssumeRoleResponse, GetCallerIdentityResponse } from '@aws-sdk/client-sts' |
| 8 | +import { AwsCredentialIdentityProvider } from '@smithy/types' |
8 | 9 | import globals from '../extensionGlobals' |
9 | 10 | import { ClassToInterfaceType } from '../utilities/tsUtils' |
10 | 11 |
|
11 | | -export type GetCallerIdentityResponse = STS.GetCallerIdentityResponse |
| 12 | +export type { GetCallerIdentityResponse } |
12 | 13 | export type StsClient = ClassToInterfaceType<DefaultStsClient> |
13 | 14 | export class DefaultStsClient { |
14 | 15 | public constructor( |
15 | 16 | public readonly regionCode: string, |
16 | | - private readonly credentials?: Credentials, |
| 17 | + private readonly credentials?: AwsCredentialIdentityProvider, |
17 | 18 | private readonly endpointUrl?: string |
18 | 19 | ) {} |
19 | 20 |
|
20 | | - public async assumeRole(request: STS.AssumeRoleRequest): Promise<STS.AssumeRoleResponse> { |
21 | | - const sdkClient = await this.createSdkClient() |
22 | | - const response = await sdkClient.assumeRole(request).promise() |
| 21 | + public async assumeRole(request: AssumeRoleRequest): Promise<AssumeRoleResponse> { |
| 22 | + const sdkClient = this.createSdkClient() |
| 23 | + const response = await sdkClient.send(new AssumeRoleCommand(request)) |
23 | 24 | return response |
24 | 25 | } |
25 | 26 |
|
26 | | - public async getCallerIdentity(): Promise<STS.GetCallerIdentityResponse> { |
27 | | - const sdkClient = await this.createSdkClient() |
28 | | - const response = await sdkClient.getCallerIdentity().promise() |
| 27 | + public async getCallerIdentity(): Promise<GetCallerIdentityResponse> { |
| 28 | + const sdkClient = this.createSdkClient() |
| 29 | + const response = await sdkClient.send(new GetCallerIdentityCommand({})) |
29 | 30 | return response |
30 | 31 | } |
31 | 32 |
|
32 | | - private async createSdkClient(): Promise<STS> { |
33 | | - return await globals.sdkClientBuilder.createAwsService( |
34 | | - STS, |
35 | | - { |
| 33 | + private createSdkClient(): STSClient { |
| 34 | + return globals.sdkClientBuilderV3.createAwsService({ |
| 35 | + serviceClient: STSClient, |
| 36 | + clientOptions: { |
| 37 | + region: this.regionCode, |
36 | 38 | credentials: this.credentials, |
37 | | - stsRegionalEndpoints: 'regional', |
38 | 39 | endpoint: this.endpointUrl, |
39 | 40 | }, |
40 | | - this.regionCode |
41 | | - ) |
| 41 | + }) |
42 | 42 | } |
43 | 43 | } |
0 commit comments