Repository navigation
Per-client configuration - #3987
Conversation
84c91d7 to
e95feb2
Compare
sbiscigl
left a comment
There was a problem hiding this comment.
The core of this is right, and we should keep it. That's removing the legacy constructors, making the converting constructor explicit, generating a configuration for every service, and no longer setting UseFIPS and UseDualStack on every client.
Where it runs into trouble is how service options reach the base client.
An object should be correct when its constructor finishes. Right now the base client is built with default checksum, chunking and Expect header settings, and ApplyServiceOptions patches them afterward. So every client depends on a second call to be right, and a client that misses the call has no way to know. S3CrtClient misses it. It now ignores checksumConfig, disableExpectHeader and the chunking settings for requests that don't go through the CRT, and before this PR the constructor read them.
Don't pay for what you don't use. The options left ClientConfiguration, but core still knows about all of them. ClientConfiguration.h now has ServiceClientOptions, ChecksumConfig, the chunk size constant and a loader for each option. Every client also still builds checksum and chunking interceptors, even when its service has no checksum operations.
Following both principles leads to one change. The service's configuration builds the interceptors its service needs, and the base asks for them once, in its constructor. ClientConfiguration already supplies the retry strategy and executor this way through configFactories.
The Swift SDK already works this way. Its service configurations carry interceptor providers, and the generated operations add the service's own interceptors, like the flexible checksum one only on operations that have checksums.
// Today. The base starts with defaults, and the generated client patches it.
S3Client(config) : AWSClient(config) {
ApplyServiceOptions(GetServiceClientOptions(config));
}
// Suggested. The configuration builds what its service needs, and the base asks once.
struct S3ClientConfiguration : GenericClientConfiguration {
Interceptors CreateInterceptors(const CreateInterceptorsRequest& request) const override {
return {ChecksumInterceptor(...), ChunkingInterceptor(...), ExpectHeaderInterceptor(...)};
}
};
AWSClient(const ClientConfiguration& config) : m_interceptors(config.CreateInterceptors({*m_httpClient})) {}DynamoDB has no checksum or streaming operations, so its configuration builds none of these.
Once the configuration owns this, the base doesn't need to know any service's options. It runs the interceptors it's given, and the service decides what those are.
With that, ApplyServiceOptions, ServiceClientOptions, GetServiceClientOptions and the core loaders go away, and ClientConfiguration.h doesn't gain anything.
7e864b4 to
1c7ae38
Compare
| Aws::String accountId; | ||
| Aws::String accountIdEndpointMode; | ||
| struct CreateInterceptorsRequest { | ||
| std::shared_ptr<Aws::Http::HttpClient> httpClient; |
There was a problem hiding this comment.
RequestCompressionInterceptor holds the HTTP client because AddCompressedContentBodyToRequest needs it and interceptors doesn't get the client's members. Before, compression
borrowed the base client's m_httpClient. I can make it a weak_ptr
if you'd rather it not share ownership.
| AWS_CORE_API RequestCompressionConfig LoadRequestCompressionConfigFromEnvOrProfile(const Aws::String& profileName); | ||
| AWS_CORE_API ChecksumConfig LoadChecksumConfigFromEnvOrProfile(const Aws::String& profileName); | ||
| AWS_CORE_API Aws::Vector<Aws::String> LoadSigV4aSigningRegionSetFromEnvOrProfile(const Aws::String& profileName); | ||
|
|
There was a problem hiding this comment.
Loaders that were just a lookup through
LoadConfigFromEnvOrProfile (useFIPS, useDualStack,
accountIdEndpointMode) are now generated inline in each
service's configuration, and loaders with real logic (checksum,
request compression, SigV4a region set) stay shared next to the
feature that uses them (ChecksumConfig.h, RequestCompression.h, SigV4aSigningRegionSet.h) so that logic isn't copied into every
service.
| if (resolvedNonEmptyAccountId && m_serviceOptions.accountId.empty()) { | ||
| endpointParameters.emplace_back("AccountId", resolvedAccountId.value(), Aws::Endpoint::EndpointParameter::ParameterOrigin::OPERATION_CONTEXT); | ||
| } | ||
| // Services whose endpoint rules take AccountId add it in their generated GetContextEndpointParameters override. |
There was a problem hiding this comment.
The "use the credentials' account ID unless accountId is
configured" rule moved out of core into a generated
GetContextEndpointParameters override, emitted only for services
whose endpoint rules take AccountId (only 4 services).
| const Aws::String& serviceName, | ||
| const Aws::String& region) | ||
| const Aws::String& region, | ||
| const Aws::Vector<Aws::String>& signingRegionSet = {}) |
There was a problem hiding this comment.
signingRegionSet is now a defaulted constructor parameter on
AwsSigV4aSigner and SigV4aAuthScheme, so a generated client
passes its configured sigV4aSigningRegionSet to the signer once,
when it builds the auth scheme. i can also add a separate overload constructor
| #foreach($entry in $AuthSchemeMapEntries) | ||
| #if($entry.contains("smithy::BearerTokenAuthScheme") && $serviceModel.metadata.signingName == "bedrock") | ||
| {${entry}{Aws::MakeShared<${metadata.classNamePrefix}AwsBearerTokenIdentityResolver>("BearerTokenAuthScheme", clientConfiguration.ResolveCredentialProviderConfig()), GetServiceName(), clientConfiguration.region}}, | ||
| #elseif($entry.contains("smithy::SigV4aAuthScheme") && $serviceModel.supportedClientOptions.contains("sigV4aSigningRegionSet")) |
There was a problem hiding this comment.
For services that have sigV4aSigningRegionSet (among smithy
clients, only STS), the generated constructors now pass
clientConfiguration.sigV4aSigningRegionSet to
SigV4aAuthScheme, so the signer gets the configured region set
once, when the client is built, instead of
UpdateAuthSchemeFromEndpoint copying it from
ServiceClientOptions on every request. not sure if this is the correct way to do it?
| } | ||
| } | ||
|
|
||
| #if($serviceModel.supportedClientOptions.contains("accountId")) |
There was a problem hiding this comment.
The "add the credentials' account ID as the AccountId endpoint
parameter unless accountId is configured" rule moved out of
AwsSmithyClientT::GetContextEndpointParametersImpl into this
generated override, emitted only for services that have
accountId (among smithy clients, only DynamoDB).
8cdef1a to
8ef69f7
Compare
| * Default aws-chunked buffer size for services that upload streams. | ||
| * Used by those services' configurations (awsChunkedBufferSize). | ||
| */ | ||
| static const size_t DEFAULT_AWS_CHUNKED_BUFFER_SIZE = 64UL * 1024; |
There was a problem hiding this comment.
having a header for just a numerical constant seems a little off, could this be move to a cpp file?
|
|
||
| Aws::Client::RequestCompressionConfig Aws::Client::LoadRequestCompressionConfigFromEnvOrProfile(const Aws::String& profileName) | ||
| { | ||
| static const char DISABLE_REQUEST_COMPRESSION_ENV_VAR[] = "DISABLE_REQUEST_COMPRESSION"; |
There was a problem hiding this comment.
nit: move to anonymous namespace in the cpp instead of static local to the function
8ef69f7 to
371d114
Compare
…tions Core, code generator and hand-written test changes: - Each service client is built from its own service-specific configuration. - Build each service's interceptors from its configuration at client construction. - Smoke tests: only set useFIPS/useDualStack when enabled. - Performance tests: build S3 and DynamoDB clients from their own configuration. - AwsConfigTest: check endpoint parameters without GetParameter() on a missing name. - S3 integration tests: set ARN region and MRAP options on the config. - Fix MSVC C4459: drop shadowing CLIENT_CONFIG_TAG in RequestCompression.cpp. - Add dualstack to the cspell dictionary. - Keep request compression and aws-chunked buffer defaults out of installed headers (anonymous-namespace constants in the .cpp; drop ChunkingConfig.h).
371d114 to
059ddd5
Compare
** Look at the first commit during review, second commit is all the generated files (too many of them)
Issue #, if available:
Description of changes:
Check all that applies:
Check which platforms you have built SDK on to verify the correctness of this PR.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.