Skip to content

Commit d0f426c

Browse files
authored
feat(credential-providers): deferred loading for credential providers aggregation package (#8129)
1 parent 492bd59 commit d0f426c

28 files changed

Lines changed: 192 additions & 130 deletions

packages-internal/credential-provider-ini/src/resolveLoginCredentials.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { setCredentialFeature } from "@aws-sdk/core/client";
2-
import { fromLoginCredentials } from "@aws-sdk/credential-provider-login";
32
import type { AwsIdentityProperties } from "@aws-sdk/types";
43
import type { AwsCredentialIdentity, ParsedIniData } from "@smithy/types";
54

@@ -20,6 +19,7 @@ export const resolveLoginCredentials = async (
2019
options: FromIniInit,
2120
callerClientConfig?: AwsIdentityProperties["callerClientConfig"]
2221
): Promise<AwsCredentialIdentity> => {
22+
const { fromLoginCredentials } = await import("@aws-sdk/credential-provider-login");
2323
const credentials = await fromLoginCredentials({
2424
...options,
2525
profile: profileName,

packages-internal/credential-provider-sso/src/fromSSO.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { resolveSSOCredentials } from "./resolveSSOCredentials";
1212
import { validateSsoProfile } from "./validateSsoProfile";
1313

1414
/**
15-
* @internal
15+
* @public
1616
*/
1717
export interface SsoCredentialsParameters {
1818
/**
@@ -43,7 +43,7 @@ export interface SsoCredentialsParameters {
4343
}
4444

4545
/**
46-
* @internal
46+
* @public
4747
*/
4848
export interface FromSSOInit extends SourceProfileInit, CredentialProviderOptions {
4949
ssoClient?: SSOClient;
@@ -52,8 +52,6 @@ export interface FromSSOInit extends SourceProfileInit, CredentialProviderOption
5252
}
5353

5454
/**
55-
* @internal
56-
*
5755
* Creates a credential provider that will read from a credential_process specified
5856
* in ini files.
5957
*
@@ -81,6 +79,8 @@ export interface FromSSOInit extends SourceProfileInit, CredentialProviderOption
8179
* sso_region = us-east-1
8280
* sso_start_url = https://www.....com/start
8381
* ```
82+
*
83+
* @internal
8484
*/
8585
export const fromSSO =
8686
(init: FromSSOInit & Partial<SsoCredentialsParameters> = {}): RuntimeConfigAwsCredentialIdentityProvider =>

packages-internal/types/src/identity/AwsCredentialIdentity.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,32 @@ export interface AwsIdentityProperties {
3333
}
3434

3535
/**
36-
* @public
37-
*
3836
* Variation of {@link IdentityProvider} which accepts a contextual
3937
* client configuration that includes an AWS region and potentially other
4038
* configurable fields.
4139
*
4240
* Used to link a credential provider to a client if it is being called
4341
* in the context of a client.
42+
*
43+
* @public
4444
*/
4545
export type RuntimeConfigIdentityProvider<T> = (awsIdentityProperties?: AwsIdentityProperties) => Promise<T>;
4646

4747
/**
48-
* @public
49-
*
5048
* Variation of {@link AwsCredentialIdentityProvider} which accepts a contextual
5149
* client configuration that includes an AWS region and potentially other
5250
* configurable fields.
5351
*
5452
* Used to link a credential provider to a client if it is being called
5553
* in the context of a client.
54+
*
55+
* @public
5656
*/
5757
export type RuntimeConfigAwsCredentialIdentityProvider = RuntimeConfigIdentityProvider<AwsCredentialIdentity>;
5858

5959
/**
60-
* @public
61-
*
6260
* AwsCredentialIdentity with source attribution metadata.
61+
* @public
6362
*/
6463
export type AttributedAwsCredentialIdentity = AwsCredentialIdentity & {
6564
$source?: AwsSdkCredentialsFeatures;

packages/credential-providers/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
},
3838
"license": "Apache-2.0",
3939
"dependencies": {
40-
"@aws-sdk/client-cognito-identity": "workspace:3.1081.0",
4140
"@aws-sdk/core": "workspace:^3.974.29",
4241
"@aws-sdk/credential-provider-cognito-identity": "workspace:^3.972.54",
4342
"@aws-sdk/credential-provider-env": "workspace:^3.972.55",

packages/credential-providers/src/fromCognitoIdentity.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ vi.mock("@aws-sdk/client-cognito-identity", () => ({
1010
}));
1111

1212
vi.mock("@aws-sdk/credential-provider-cognito-identity", () => ({
13-
fromCognitoIdentity: vi.fn(),
13+
fromCognitoIdentity: vi.fn().mockReturnValue(vi.fn()),
1414
}));
1515

1616
describe("fromCognitoIdentity", () => {
@@ -20,10 +20,11 @@ describe("fromCognitoIdentity", () => {
2020
vi.clearAllMocks();
2121
});
2222

23-
it("defers to @aws-sdk/credential-provider-cognito-identity", () => {
24-
fromCognitoIdentity({
23+
it("defers to @aws-sdk/credential-provider-cognito-identity", async () => {
24+
const provider = fromCognitoIdentity({
2525
identityId,
2626
});
27+
await provider({});
2728
expect(coreProvider).toHaveBeenCalledWith({
2829
identityId,
2930
});

packages/credential-providers/src/fromCognitoIdentity.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
import type { CognitoIdentityClientConfig } from "@aws-sdk/client-cognito-identity";
21
import type {
32
CognitoIdentityCredentialProvider as _CognitoIdentityCredentialProvider,
43
FromCognitoIdentityParameters as _FromCognitoIdentityParameters,
54
} from "@aws-sdk/credential-provider-cognito-identity";
6-
import { fromCognitoIdentity as _fromCognitoIdentity } from "@aws-sdk/credential-provider-cognito-identity";
5+
import type { AwsIdentityProperties } from "@aws-sdk/types";
76

87
/**
98
* @public
109
*/
11-
export interface FromCognitoIdentityParameters extends Omit<_FromCognitoIdentityParameters, "client"> {
12-
/**
13-
* Custom client configuration if you need overwrite default Cognito Identity client configuration.
14-
*/
15-
clientConfig?: CognitoIdentityClientConfig;
16-
}
10+
export interface FromCognitoIdentityParameters extends Omit<_FromCognitoIdentityParameters, "client"> {}
1711

1812
export type CognitoIdentityCredentialProvider = _CognitoIdentityCredentialProvider;
1913

@@ -54,7 +48,9 @@ export type CognitoIdentityCredentialProvider = _CognitoIdentityCredentialProvid
5448
*
5549
* @public
5650
*/
57-
export const fromCognitoIdentity = (options: FromCognitoIdentityParameters): CognitoIdentityCredentialProvider =>
58-
_fromCognitoIdentity({
59-
...options,
60-
});
51+
export const fromCognitoIdentity = (options: FromCognitoIdentityParameters): CognitoIdentityCredentialProvider => {
52+
return async (args?: AwsIdentityProperties) => {
53+
const { fromCognitoIdentity: _fromCognitoIdentity } = await import("@aws-sdk/credential-provider-cognito-identity");
54+
return _fromCognitoIdentity(options)(args);
55+
};
56+
};

packages/credential-providers/src/fromCognitoIdentityPool.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ vi.mock("@aws-sdk/client-cognito-identity", () => ({
1010
}));
1111

1212
vi.mock("@aws-sdk/credential-provider-cognito-identity", () => ({
13-
fromCognitoIdentityPool: vi.fn(),
13+
fromCognitoIdentityPool: vi.fn().mockReturnValue(vi.fn()),
1414
}));
1515

1616
describe("fromCognitoIdentityPool", () => {
@@ -20,10 +20,11 @@ describe("fromCognitoIdentityPool", () => {
2020
vi.clearAllMocks();
2121
});
2222

23-
it("defers to @aws-sdk/credential-provider-cognito-identity", () => {
24-
fromCognitoIdentityPool({
23+
it("defers to @aws-sdk/credential-provider-cognito-identity", async () => {
24+
const provider = fromCognitoIdentityPool({
2525
identityPoolId,
2626
});
27+
await provider({});
2728
expect(coreProvider).toHaveBeenCalledWith({
2829
identityPoolId,
2930
});

packages/credential-providers/src/fromCognitoIdentityPool.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type { CognitoIdentityClientConfig } from "@aws-sdk/client-cognito-identity";
21
import type {
32
CognitoIdentityCredentialProvider,
43
FromCognitoIdentityPoolParameters as _FromCognitoIdentityPoolParameters,
54
} from "@aws-sdk/credential-provider-cognito-identity";
6-
import { fromCognitoIdentityPool as _fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity";
5+
import type { AwsIdentityProperties } from "@aws-sdk/types";
76

8-
export interface FromCognitoIdentityPoolParameters extends Omit<_FromCognitoIdentityPoolParameters, "client"> {
9-
clientConfig?: CognitoIdentityClientConfig;
10-
}
7+
/**
8+
* @public
9+
*/
10+
export interface FromCognitoIdentityPoolParameters extends Omit<_FromCognitoIdentityPoolParameters, "client"> {}
1111

1212
/**
1313
* Creates a credential provider function that retrieves or generates a unique identifier using Amazon Cognito's `GetId`
@@ -53,7 +53,11 @@ export interface FromCognitoIdentityPoolParameters extends Omit<_FromCognitoIden
5353
*/
5454
export const fromCognitoIdentityPool = (
5555
options: FromCognitoIdentityPoolParameters
56-
): CognitoIdentityCredentialProvider =>
57-
_fromCognitoIdentityPool({
58-
...options,
59-
});
56+
): CognitoIdentityCredentialProvider => {
57+
return async (args?: AwsIdentityProperties) => {
58+
const { fromCognitoIdentityPool: _fromCognitoIdentityPool } = await import(
59+
"@aws-sdk/credential-provider-cognito-identity"
60+
);
61+
return _fromCognitoIdentityPool(options)(args);
62+
};
63+
};

packages/credential-providers/src/fromContainerMetadata.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { CredentialProviderOptions } from "@aws-sdk/types";
1+
import type { AwsIdentityProperties, CredentialProviderOptions } from "@aws-sdk/types";
22
import type { RemoteProviderInit as _RemoteProviderInit } from "@smithy/credential-provider-imds";
3-
import { fromContainerMetadata as _fromContainerMetadata } from "@smithy/credential-provider-imds";
43
import type { AwsCredentialIdentityProvider } from "@smithy/types";
54

65
export interface RemoteProviderInit extends _RemoteProviderInit, CredentialProviderOptions {}
@@ -27,6 +26,9 @@ export interface RemoteProviderInit extends _RemoteProviderInit, CredentialProvi
2726
* @public
2827
*/
2928
export const fromContainerMetadata = (init?: RemoteProviderInit): AwsCredentialIdentityProvider => {
30-
init?.logger?.debug("@smithy/credential-provider-imds", "fromContainerMetadata");
31-
return _fromContainerMetadata(init);
29+
return async (props?: AwsIdentityProperties) => {
30+
init?.logger?.debug("@smithy/credential-provider-imds", "fromContainerMetadata");
31+
const { fromContainerMetadata: _fromContainerMetadata } = await import("@smithy/credential-provider-imds");
32+
return _fromContainerMetadata(init)();
33+
};
3234
};

packages/credential-providers/src/fromEnv.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { FromEnvInit } from "@aws-sdk/credential-provider-env";
2-
import { fromEnv as _fromEnv } from "@aws-sdk/credential-provider-env";
2+
import type { AwsIdentityProperties } from "@aws-sdk/types";
33
import type { AwsCredentialIdentityProvider } from "@smithy/types";
44

55
/**
@@ -28,4 +28,9 @@ import type { AwsCredentialIdentityProvider } from "@smithy/types";
2828
*
2929
* @public
3030
*/
31-
export const fromEnv = (init?: FromEnvInit): AwsCredentialIdentityProvider => _fromEnv(init);
31+
export const fromEnv = (init?: FromEnvInit): AwsCredentialIdentityProvider => {
32+
return async (args?: AwsIdentityProperties) => {
33+
const { fromEnv: _fromEnv } = await import("@aws-sdk/credential-provider-env");
34+
return _fromEnv(init)(args);
35+
};
36+
};

0 commit comments

Comments
 (0)