Skip to content

Commit e305a59

Browse files
committed
feat(clients): profile setting for clients
1 parent 90e3032 commit e305a59

File tree

11 files changed

+63
-28
lines changed

11 files changed

+63
-28
lines changed

clients/client-s3/src/S3Client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,19 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
658658
*/
659659
region?: string | __Provider<string>;
660660

661+
/**
662+
* Setting a client profile is similar to setting a value for the
663+
* AWS_PROFILE environment variable. Setting a profile on a client
664+
* in code only affects the single client instance, unlike AWS_PROFILE.
665+
*
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.
670+
*
671+
*/
672+
profile?: string;
673+
661674
/**
662675
* The provider populating default tracking information to be sent with `user-agent`, `x-amz-user-agent` header
663676
* @internal

clients/client-s3/src/models/models_0.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// smithy-typescript generated code
22
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";
3-
43
import { StreamingBlobTypes } from "@smithy/types";
54

65
import { S3ServiceException as __BaseException } from "./S3ServiceException";

clients/client-s3/src/models/models_1.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// smithy-typescript generated code
22
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";
3-
43
import { StreamingBlobTypes } from "@smithy/types";
54

65
import {
@@ -40,7 +39,6 @@ import {
4039
Tag,
4140
TransitionDefaultMinimumObjectSize,
4241
} from "./models_0";
43-
4442
import { S3ServiceException as __BaseException } from "./S3ServiceException";
4543

4644
/**

clients/client-s3/src/runtimeConfig.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const getRuntimeConfig = (config: S3ClientConfig) => {
4141
const defaultConfigProvider = () => defaultsMode().then(loadConfigsForDefaultMode);
4242
const clientSharedValues = getSharedRuntimeConfig(config);
4343
awsCheckVersion(process.version);
44+
const profileConfig = { profile: config?.profile };
4445
return {
4546
...clientSharedValues,
4647
...config,
@@ -52,30 +53,39 @@ export const getRuntimeConfig = (config: S3ClientConfig) => {
5253
config?.defaultUserAgentProvider ??
5354
createDefaultUserAgentProvider({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
5455
disableS3ExpressSessionAuth:
55-
config?.disableS3ExpressSessionAuth ?? loadNodeConfig(NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS),
56+
config?.disableS3ExpressSessionAuth ??
57+
loadNodeConfig(NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS, profileConfig),
5658
eventStreamSerdeProvider: config?.eventStreamSerdeProvider ?? eventStreamSerdeProvider,
57-
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS),
59+
maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS, config),
5860
md5: config?.md5 ?? Hash.bind(null, "md5"),
59-
region: config?.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS),
61+
region:
62+
config?.region ??
63+
loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, { ...NODE_REGION_CONFIG_FILE_OPTIONS, ...profileConfig }),
6064
requestChecksumCalculation:
61-
config?.requestChecksumCalculation ?? loadNodeConfig(NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS),
65+
config?.requestChecksumCalculation ??
66+
loadNodeConfig(NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, profileConfig),
6267
requestHandler: RequestHandler.create(config?.requestHandler ?? defaultConfigProvider),
6368
responseChecksumValidation:
64-
config?.responseChecksumValidation ?? loadNodeConfig(NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS),
69+
config?.responseChecksumValidation ??
70+
loadNodeConfig(NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, profileConfig),
6571
retryMode:
6672
config?.retryMode ??
67-
loadNodeConfig({
68-
...NODE_RETRY_MODE_CONFIG_OPTIONS,
69-
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
70-
}),
73+
loadNodeConfig(
74+
{
75+
...NODE_RETRY_MODE_CONFIG_OPTIONS,
76+
default: async () => (await defaultConfigProvider()).retryMode || DEFAULT_RETRY_MODE,
77+
},
78+
config
79+
),
7180
sha1: config?.sha1 ?? Hash.bind(null, "sha1"),
7281
sha256: config?.sha256 ?? Hash.bind(null, "sha256"),
73-
sigv4aSigningRegionSet: config?.sigv4aSigningRegionSet ?? loadNodeConfig(NODE_SIGV4A_CONFIG_OPTIONS),
82+
sigv4aSigningRegionSet: config?.sigv4aSigningRegionSet ?? loadNodeConfig(NODE_SIGV4A_CONFIG_OPTIONS, profileConfig),
7483
streamCollector: config?.streamCollector ?? streamCollector,
7584
streamHasher: config?.streamHasher ?? streamHasher,
76-
useArnRegion: config?.useArnRegion ?? loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS),
77-
useDualstackEndpoint: config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS),
78-
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS),
79-
userAgentAppId: config?.userAgentAppId ?? loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS),
85+
useArnRegion: config?.useArnRegion ?? loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS, profileConfig),
86+
useDualstackEndpoint:
87+
config?.useDualstackEndpoint ?? loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, profileConfig),
88+
useFipsEndpoint: config?.useFipsEndpoint ?? loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, profileConfig),
89+
userAgentAppId: config?.userAgentAppId ?? loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS, profileConfig),
8090
};
8191
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
8989
null, AwsDependency.AWS_SDK_CORE,
9090
"/account-id-endpoint");
9191
writer.write(
92-
"loadNodeConfig(NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS)");
92+
"loadNodeConfig(NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS, profileConfig)");
9393
});
9494
break;
9595
default:

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ public void addConfigInterfaceFields(
9999
? "The AWS region to which this client will send requests"
100100
: "The AWS region to use as signing region for AWS Auth")
101101
.write("region?: string | __Provider<string>;\n");
102+
103+
104+
writer.writeDocs(
105+
"""
106+
Setting a client profile is similar to setting a value for the
107+
AWS_PROFILE environment variable. Setting a profile on a client
108+
in code only affects the single client instance, unlike AWS_PROFILE.
109+
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.
114+
""")
115+
.write("profile?: string;\n");
102116
}
103117
}
104118

@@ -145,6 +159,7 @@ public void prepareCustomizations(
145159
writer.addDependency(AwsDependency.AWS_SDK_CORE);
146160
writer.addImport("emitWarningIfUnsupportedVersion", "awsCheckVersion", AwsDependency.AWS_SDK_CORE);
147161
writer.write("awsCheckVersion(process.version);");
162+
writer.write("const profileConfig = { profile: config?.profile };");
148163
}
149164
}
150165

@@ -173,7 +188,7 @@ private Map<String, Consumer<TypeScriptWriter>> getDefaultConfig(
173188
writer.addImport("NODE_REGION_CONFIG_FILE_OPTIONS", "NODE_REGION_CONFIG_FILE_OPTIONS",
174189
TypeScriptDependency.CONFIG_RESOLVER);
175190
writer.write(
176-
"loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, NODE_REGION_CONFIG_FILE_OPTIONS)");
191+
"loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, {...NODE_REGION_CONFIG_FILE_OPTIONS, ...profileConfig})");
177192
});
178193
default:
179194
return Collections.emptyMap();
@@ -216,7 +231,7 @@ private Map<String, Consumer<TypeScriptWriter>> getEndpointConfigWriters(
216231
writer.addImport("NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS",
217232
"NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS",
218233
TypeScriptDependency.CONFIG_RESOLVER);
219-
writer.write("loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS)");
234+
writer.write("loadNodeConfig(NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, profileConfig)");
220235
},
221236
"useFipsEndpoint", writer -> {
222237
writer.addDependency(TypeScriptDependency.NODE_CONFIG_PROVIDER);
@@ -226,7 +241,7 @@ private Map<String, Consumer<TypeScriptWriter>> getEndpointConfigWriters(
226241
writer.addImport("NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS",
227242
"NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS",
228243
TypeScriptDependency.CONFIG_RESOLVER);
229-
writer.write("loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS)");
244+
writer.write("loadNodeConfig(NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, profileConfig)");
230245
}
231246
);
232247
default:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
126126
writer.addImport("NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS",
127127
"NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS",
128128
AwsDependency.MIDDLEWARE_ENDPOINT_DISCOVERY);
129-
writer.write("loadNodeConfig(NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS)");
129+
writer.write("loadNodeConfig(NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS, profileConfig)");
130130
}
131131
);
132132
default:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
141141
TypeScriptDependency.NODE_CONFIG_PROVIDER);
142142
writer.addImport("NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS", null,
143143
AwsDependency.FLEXIBLE_CHECKSUMS_MIDDLEWARE);
144-
writer.write("loadNodeConfig(NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS)");
144+
writer.write("loadNodeConfig(NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS, profileConfig)");
145145
},
146146
"responseChecksumValidation", writer -> {
147147
writer.addDependency(TypeScriptDependency.NODE_CONFIG_PROVIDER);
148148
writer.addImport("loadConfig", "loadNodeConfig",
149149
TypeScriptDependency.NODE_CONFIG_PROVIDER);
150150
writer.addImport("NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS", null,
151151
AwsDependency.FLEXIBLE_CHECKSUMS_MIDDLEWARE);
152-
writer.write("loadNodeConfig(NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS)");
152+
writer.write("loadNodeConfig(NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS, profileConfig)");
153153
}
154154
);
155155
case BROWSER:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
256256
.addDependency(AwsDependency.BUCKET_ENDPOINT_MIDDLEWARE)
257257
.addImport("NODE_USE_ARN_REGION_CONFIG_OPTIONS", "NODE_USE_ARN_REGION_CONFIG_OPTIONS",
258258
AwsDependency.BUCKET_ENDPOINT_MIDDLEWARE)
259-
.write("loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS)");
259+
.write("loadNodeConfig(NODE_USE_ARN_REGION_CONFIG_OPTIONS, profileConfig)");
260260
},
261261
"disableS3ExpressSessionAuth", writer -> {
262262
writer.addDependency(TypeScriptDependency.NODE_CONFIG_PROVIDER)
@@ -268,7 +268,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
268268
"NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS",
269269
AwsDependency.S3_MIDDLEWARE
270270
)
271-
.write("loadNodeConfig(NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS)");
271+
.write("loadNodeConfig(NODE_DISABLE_S3_EXPRESS_SESSION_AUTH_OPTIONS, profileConfig)");
272272
}
273273
);
274274
default:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
8484
writer.addDependency(AwsDependency.AWS_SDK_UTIL_USER_AGENT_NODE);
8585
writer.addImport("NODE_APP_ID_CONFIG_OPTIONS", "NODE_APP_ID_CONFIG_OPTIONS",
8686
AwsDependency.AWS_SDK_UTIL_USER_AGENT_NODE);
87-
writer.write("loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS)");
87+
writer.write("loadNodeConfig(NODE_APP_ID_CONFIG_OPTIONS, profileConfig)");
8888
}
8989
);
9090
case BROWSER:

0 commit comments

Comments
 (0)