Skip to content

Commit 8d6c0de

Browse files
committed
feat(clients): profile scoped clients
1 parent b48810c commit 8d6c0de

File tree

12 files changed

+87
-46
lines changed

12 files changed

+87
-46
lines changed

clients/client-cognito-identity/src/CognitoIdentityClient.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,25 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
267267
*/
268268
region?: string | __Provider<string>;
269269

270+
/**
271+
* Setting a client profile is similar to setting a value for the
272+
* AWS_PROFILE environment variable. Setting a profile on a client
273+
* in code only affects the single client instance, unlike AWS_PROFILE.
274+
*
275+
* When set, and only for environments where an AWS configuration
276+
* file exists, fields configurable by this file will be retrieved
277+
* from the specified profile within that file.
278+
* Conflicting code configuration and environment variables will
279+
* still have higher priority.
280+
*
281+
* For client credential resolution that involves checking the AWS
282+
* configuration file, the client's profile (this value) will be
283+
* used unless a different profile is set in the credential
284+
* provider options.
285+
*
286+
*/
287+
profile?: string;
288+
270289
/**
271290
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
272291
* @internal

clients/client-cognito-identity/src/runtimeConfig.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const getRuntimeConfig = (config: CognitoIdentityClientConfig) => {
3232
const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode);
3333
const clientSharedValues = getSharedRuntimeConfig(config);
3434
awsCheckVersion(process.version);
35+
const profileConfig = { profile: config?.profile };
3536
return {
3637
...clientSharedValues,
3738
...config,
@@ -42,19 +43,25 @@ export const getRuntimeConfig = (config: CognitoIdentityClientConfig) => {
4243
defaultUserAgentProvider:
4344
config?.defaultUserAgentProvider ??
4445
createDefaultUserAgentProvider({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
45-
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
46-
region: config?.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
46+
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS, config),
47+
region:
48+
config?.region ??
49+
loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, { ...NODE_REGION_CONFIG_FILE_OPTIONS, ...profileConfig }),
4750
requestHandler: RequestHandler.create(config?.requestHandler ?? defaultConfigProvider),
4851
retryMode:
4952
config?.retryMode ??
50-
loadNodeConfig({
51-
...NODE_RETRY_MODE_CONFIG_OPTIONS,
52-
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
53-
}),
53+
loadNodeConfig(
54+
{
55+
...NODE_RETRY_MODE_CONFIG_OPTIONS,
56+
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
57+
},
58+
config
59+
),
5460
sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
5561
streamCollector: config?.streamCollector ?? streamCollector,
56-
useDualstackEndpoint: config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS),
57-
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS),
58-
userAgentAppId: config?.userAgentAppId ?? loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS),
62+
useDualstackEndpoint:
63+
config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, profileConfig),
64+
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, profileConfig),
65+
userAgentAppId: config?.userAgentAppId ?? loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS, profileConfig),
5966
};
6067
};

clients/client-s3/src/S3Client.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,10 +663,16 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
663663
* AWS_PROFILE environment variable. Setting a profile on a client
664664
* in code only affects the single client instance, unlike AWS_PROFILE.
665665
*
666-
* When set, and only for environments where a profile configuration
667-
* file exists, values configurable by this file will be retrieved
668-
* with the specified profile. Conflicting code configuration and
669-
* environment variables will still have higher priority.
666+
* When set, and only for environments where an AWS configuration
667+
* file exists, fields configurable by this file will be retrieved
668+
* from the specified profile within that file.
669+
* Conflicting code configuration and environment variables will
670+
* still have higher priority.
671+
*
672+
* For client credential resolution that involves checking the AWS
673+
* configuration file, the client's profile (this value) will be
674+
* used unless a different profile is set in the credential
675+
* provider options.
670676
*
671677
*/
672678
profile?: string;

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddAwsRuntimeConfig.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,16 @@ public void addConfigInterfaceFields(
107107
AWS_PROFILE environment variable. Setting a profile on a client
108108
in code only affects the single client instance, unlike AWS_PROFILE.
109109
110-
When set, and only for environments where a profile configuration
111-
file exists, values configurable by this file will be retrieved
112-
with the specified profile. Conflicting code configuration and
113-
environment variables will still have higher priority.
110+
When set, and only for environments where an AWS configuration
111+
file exists, fields configurable by this file will be retrieved
112+
from the specified profile within that file.
113+
Conflicting code configuration and environment variables will
114+
still have higher priority.
115+
116+
For client credential resolution that involves checking the AWS
117+
configuration file, the client's profile (this value) will be
118+
used unless a different profile is set in the credential
119+
provider options.
114120
""")
115121
.write("profile?: string;\n");
116122
}

packages/credential-provider-cognito-identity/src/fromCognitoIdentity.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ export function fromCognitoIdentity(parameters: FromCognitoIdentityParameters):
3333
parameters.logger?.debug("@aws-sdk/credential-provider-cognito-identity - fromCognitoIdentity");
3434
const { GetCredentialsForIdentityCommand, CognitoIdentityClient } = await import("./loadCognitoIdentity");
3535

36+
const fromConfigs = (property: "region" | "profile"): any =>
37+
parameters.clientConfig?.[property] ??
38+
parameters.parentClientConfig?.[property] ??
39+
awsIdentityProperties?.callerClientConfig?.[property];
40+
3641
const {
3742
Credentials: {
3843
AccessKeyId = throwOnMissingAccessKeyId(parameters.logger),
@@ -44,10 +49,8 @@ export function fromCognitoIdentity(parameters: FromCognitoIdentityParameters):
4449
parameters.client ??
4550
new CognitoIdentityClient(
4651
Object.assign({}, parameters.clientConfig ?? {}, {
47-
region:
48-
parameters.clientConfig?.region ??
49-
parameters.parentClientConfig?.region ??
50-
awsIdentityProperties?.callerClientConfig?.region,
52+
region: fromConfigs("region"),
53+
profile: fromConfigs("profile"),
5154
})
5255
)
5356
).send(

packages/credential-provider-cognito-identity/src/fromCognitoIdentityPool.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ export function fromCognitoIdentityPool({
3737

3838
let provider: CognitoIdentityCredentialProvider = async (awsIdentityProperties?: AwsIdentityProperties) => {
3939
const { GetIdCommand, CognitoIdentityClient } = await import("./loadCognitoIdentity");
40+
41+
const fromConfigs = (property: "region" | "profile"): any =>
42+
clientConfig?.[property] ??
43+
parentClientConfig?.[property] ??
44+
awsIdentityProperties?.callerClientConfig?.[property];
45+
4046
const _client =
4147
client ??
4248
new CognitoIdentityClient(
4349
Object.assign({}, clientConfig ?? {}, {
44-
region:
45-
clientConfig?.region ?? parentClientConfig?.region ?? awsIdentityProperties?.callerClientConfig?.region,
50+
region: fromConfigs("region"),
51+
profile: fromConfigs("profile"),
4652
})
4753
);
4854

packages/credential-provider-ini/src/fromIni.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ export const fromIni =
6060
async ({ callerClientConfig } = {}) => {
6161
const init: FromIniInit = {
6262
..._init,
63-
};
64-
if (callerClientConfig?.region) {
65-
init.parentClientConfig = {
66-
region: callerClientConfig.region,
63+
parentClientConfig: {
64+
...callerClientConfig,
6765
..._init.parentClientConfig,
68-
};
69-
}
66+
},
67+
};
7068
init.logger?.debug("@aws-sdk/credential-provider-ini - fromIni");
7169
const profiles = await parseKnownFiles(init);
7270
return resolveProfileData(getProfileName(init), profiles, init);

packages/credential-provider-web-identity/src/fromWebToken.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,10 @@ export const fromWebToken =
169169
{
170170
...init.clientConfig,
171171
credentialProviderLogger: init.logger,
172-
...(awsIdentityProperties?.callerClientConfig?.region || init.parentClientConfig
173-
? {
174-
parentClientConfig: {
175-
region: awsIdentityProperties?.callerClientConfig?.region,
176-
...init.parentClientConfig,
177-
},
178-
}
179-
: {}),
172+
parentClientConfig: {
173+
...awsIdentityProperties?.callerClientConfig,
174+
...init.parentClientConfig,
175+
},
180176
},
181177
init.clientPlugins
182178
);

packages/middleware-signing/src/awsAuthConfiguration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ const createConfigBoundCredentialProvider = (input: {
318318
credentials?: AwsCredentialIdentity | AwsCredentialIdentityProvider | RegionalAwsCredentialIdentityProvider;
319319
credentialDefaultProvider: PreviouslyResolved["credentialDefaultProvider"];
320320
region: PreviouslyResolved["region"];
321+
profile?: string;
321322
}): AwsCredentialIdentityProvider => {
322323
const normalizedCredentialsProvider = input.credentials
323324
? normalizeCredentialProvider(input.credentials)
@@ -330,6 +331,7 @@ const createConfigBoundCredentialProvider = (input: {
330331
(normalizedCredentialsProvider as RegionalAwsCredentialIdentityProvider)({
331332
callerClientConfig: {
332333
region: normalizeProvider(input.region),
334+
profile: input.profile,
333335
},
334336
});
335337
return normalizedCreds;

packages/token-providers/src/fromSso.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,10 @@ export const fromSso =
4040
async (awsIdentityProperties?: AwsIdentityProperties) => {
4141
const init: FromSsoInit = {
4242
..._init,
43-
...(awsIdentityProperties?.callerClientConfig?.region
44-
? {
45-
parentClientConfig: {
46-
region: awsIdentityProperties?.callerClientConfig?.region,
47-
..._init.parentClientConfig,
48-
},
49-
}
50-
: {}),
43+
parentClientConfig: {
44+
...awsIdentityProperties?.callerClientConfig,
45+
..._init.parentClientConfig,
46+
},
5147
};
5248
init.logger?.debug("@aws-sdk/token-providers - fromSso");
5349

0 commit comments

Comments
 (0)