-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Pre-requisite Changes Enable smithy query + rest-xml clients #3321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,7 +228,7 @@ namespace client | |
auto httpResponseOutcome = MakeRequestSync(request, requestName, method, std::move(endpointCallback)); | ||
return m_serializer->Deserialize(std::move(httpResponseOutcome), GetServiceClientName(), requestName); | ||
} | ||
|
||
Aws::String GeneratePresignedUrl( | ||
EndpointUpdateCallback&& endpointCallback, | ||
Aws::Http::HttpMethod method, | ||
|
@@ -238,110 +238,66 @@ namespace client | |
const Aws::Http::HeaderValueCollection& customizedHeaders, | ||
const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const | ||
{ | ||
AwsSmithyClientAsyncRequestContext ctx; | ||
auto authSchemeOptionOutcome = SelectAuthSchemeOption( ctx); | ||
auto authSchemeOption = std::move(authSchemeOptionOutcome.GetResultWithOwnership()); | ||
|
||
Aws::Endpoint::EndpointParameters epParams = Aws::Endpoint::EndpointParameters(); | ||
const auto authSchemeEpParams = authSchemeOption.endpointParameters(); | ||
epParams.insert(epParams.end(), authSchemeEpParams.begin(), authSchemeEpParams.end()); | ||
if(serviceSpecificParameters) | ||
{ | ||
auto bucketIt = serviceSpecificParameters->parameterMap.find("bucketName"); | ||
if(bucketIt != serviceSpecificParameters->parameterMap.end()) | ||
ExtractUriCallback getUriCallback = [&](Aws::Http::URI& uri, Aws::String& signerRegionOverride, | ||
Aws::String& signerServiceNameOverride, const AuthSchemeOption& authSchemeOption) -> bool{ | ||
|
||
Aws::Endpoint::EndpointParameters epParams = Aws::Endpoint::EndpointParameters(); | ||
const auto authSchemeEpParams = authSchemeOption.endpointParameters(); | ||
epParams.insert(epParams.end(), authSchemeEpParams.begin(), authSchemeEpParams.end()); | ||
if(serviceSpecificParameters) | ||
{ | ||
auto bucket = bucketIt->second; | ||
epParams.emplace_back(Aws::String("Bucket"), bucket); | ||
auto bucketIt = serviceSpecificParameters->parameterMap.find("bucketName"); | ||
if(bucketIt != serviceSpecificParameters->parameterMap.end()) | ||
{ | ||
auto bucket = bucketIt->second; | ||
epParams.emplace_back(Aws::String("Bucket"), bucket); | ||
} | ||
} | ||
} | ||
|
||
auto epResolutionOutcome = this->ResolveEndpoint(std::move(epParams), std::move(endpointCallback)); | ||
if (!epResolutionOutcome.IsSuccess()) | ||
{ | ||
AWS_LOGSTREAM_ERROR(ServiceNameT, "Presigned URL generating failed. Encountered error: " << epResolutionOutcome.GetError().GetMessage()); | ||
return {}; | ||
} | ||
auto endpoint = std::move(epResolutionOutcome.GetResultWithOwnership()); | ||
const Aws::Http::URI& uri = endpoint.GetURI(); | ||
auto signerRegionOverride = region; | ||
auto signerServiceNameOverride = serviceName; | ||
//signer name is needed for some identity resolvers | ||
if (endpoint.GetAttributes()) { | ||
if (endpoint.GetAttributes()->authScheme.GetSigningRegion()) { | ||
signerRegionOverride = endpoint.GetAttributes()->authScheme.GetSigningRegion()->c_str(); | ||
} | ||
if (endpoint.GetAttributes()->authScheme.GetSigningRegionSet()) { | ||
signerRegionOverride = endpoint.GetAttributes()->authScheme.GetSigningRegionSet()->c_str(); | ||
auto epResolutionOutcome = this->ResolveEndpoint(std::move(epParams), std::move(endpointCallback)); | ||
if (!epResolutionOutcome.IsSuccess()) | ||
{ | ||
AWS_LOGSTREAM_ERROR(ServiceNameT, "Presigned URL generating failed. Encountered error: " << epResolutionOutcome.GetError().GetMessage()); | ||
return false; | ||
} | ||
if (endpoint.GetAttributes()->authScheme.GetSigningName()) { | ||
signerServiceNameOverride = endpoint.GetAttributes()->authScheme.GetSigningName()->c_str(); | ||
auto endpoint = std::move(epResolutionOutcome.GetResultWithOwnership()); | ||
uri = endpoint.GetURI(); | ||
signerRegionOverride = region; | ||
signerServiceNameOverride = serviceName; | ||
//signer name is needed for some identity resolvers | ||
if (endpoint.GetAttributes()) { | ||
if (endpoint.GetAttributes()->authScheme.GetSigningRegion()) { | ||
signerRegionOverride = endpoint.GetAttributes()->authScheme.GetSigningRegion()->c_str(); | ||
} | ||
if (endpoint.GetAttributes()->authScheme.GetSigningRegionSet()) { | ||
signerRegionOverride = endpoint.GetAttributes()->authScheme.GetSigningRegionSet()->c_str(); | ||
} | ||
if (endpoint.GetAttributes()->authScheme.GetSigningName()) { | ||
signerServiceNameOverride = endpoint.GetAttributes()->authScheme.GetSigningName()->c_str(); | ||
} | ||
} | ||
} | ||
std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); | ||
request->SetServiceSpecificParameters(serviceSpecificParameters); | ||
for (const auto& it: customizedHeaders) | ||
{ | ||
request->SetHeaderValue(it.first.c_str(), it.second); | ||
} | ||
if (AwsClientRequestSigning<AuthSchemesVariantT>::PreSignRequest(request, authSchemeOption, m_authSchemes, signerRegionOverride, signerServiceNameOverride, expirationInSeconds).IsSuccess()) | ||
{ | ||
return request->GetURIString(); | ||
} | ||
return {}; | ||
} | ||
return true; | ||
}; | ||
|
||
//legacy | ||
Aws::String GeneratePresignedUrl(const Aws::Http::URI& uri, | ||
Aws::Http::HttpMethod method, | ||
const Aws::String& region, | ||
const Aws::String& serviceName, | ||
long long expirationInSeconds, | ||
const Aws::Http::HeaderValueCollection& customizedHeaders, | ||
const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const | ||
{ | ||
std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); | ||
request->SetServiceSpecificParameters(serviceSpecificParameters); | ||
for (const auto& it: customizedHeaders) | ||
{ | ||
request->SetHeaderValue(it.first.c_str(), it.second); | ||
} | ||
AwsSmithyClientAsyncRequestContext ctx; | ||
auto authSchemeOptionOutcome = SelectAuthSchemeOption( ctx); | ||
auto authSchemeOption = std::move(authSchemeOptionOutcome.GetResultWithOwnership()); | ||
if (AwsClientRequestSigning<AuthSchemesVariantT>::PreSignRequest(request, authSchemeOption, m_authSchemes, region, serviceName, expirationInSeconds).IsSuccess()) | ||
{ | ||
return request->GetURIString(); | ||
} | ||
return {}; | ||
} | ||
|
||
|
||
Aws::String GeneratePresignedUrl(const Aws::Endpoint::AWSEndpoint& endpoint, | ||
Aws::Http::HttpMethod method, | ||
const Aws::String& region, | ||
const Aws::String& serviceName, | ||
long long expirationInSeconds, | ||
const Aws::Http::HeaderValueCollection& customizedHeaders, | ||
const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const | ||
{ | ||
const Aws::Http::URI& uri = endpoint.GetURI(); | ||
auto signerRegionOverride = region; | ||
auto signerServiceNameOverride = serviceName; | ||
// signer name is needed for some identity resolvers | ||
if (endpoint.GetAttributes()) { | ||
if (endpoint.GetAttributes()->authScheme.GetSigningRegion()) { | ||
signerRegionOverride = endpoint.GetAttributes()->authScheme.GetSigningRegion()->c_str(); | ||
} | ||
if (endpoint.GetAttributes()->authScheme.GetSigningRegionSet()) { | ||
signerRegionOverride = endpoint.GetAttributes()->authScheme.GetSigningRegionSet()->c_str(); | ||
} | ||
if (endpoint.GetAttributes()->authScheme.GetSigningName()) { | ||
signerServiceNameOverride = endpoint.GetAttributes()->authScheme.GetSigningName()->c_str(); | ||
CreateHttpRequestCallback createHttpRequestCallback = [&customizedHeaders, &serviceSpecificParameters](const Aws::Http::URI& uri, const Aws::Http::HttpMethod& method) -> std::shared_ptr<HttpRequest> { | ||
std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); | ||
request->SetServiceSpecificParameters(serviceSpecificParameters); | ||
for (const auto& it: customizedHeaders) | ||
{ | ||
request->SetHeaderValue(it.first.c_str(), it.second); | ||
} | ||
} | ||
return GeneratePresignedUrl(uri, method, signerRegionOverride, signerServiceNameOverride, expirationInSeconds, customizedHeaders, serviceSpecificParameters); | ||
return request; | ||
}; | ||
|
||
return GeneratePresignedUrl( | ||
std::move(getUriCallback), | ||
std::move(createHttpRequestCallback), | ||
method, | ||
region, | ||
serviceName, | ||
expirationInSeconds); | ||
} | ||
|
||
/* Service client specific config, the actual object is stored in AwsSmithyClientBase by pointer | ||
* In order to avoid config object duplication, smithy template client access it by a reference. | ||
* So that base client has it by base config pointer, child smithy client has it by child config reference. | ||
|
@@ -352,6 +308,35 @@ namespace client | |
Aws::UnorderedMap<Aws::String, AuthSchemesVariantT> m_authSchemes{}; | ||
std::shared_ptr<SerializerT> m_serializer{}; | ||
private: | ||
using ExtractUriCallback = std::function<bool (Aws::Http::URI&, Aws::String& region, Aws::String& serviceName,const AuthSchemeOption&)>; | ||
using CreateHttpRequestCallback = std::function<std::shared_ptr<HttpRequest> (const Aws::Http::URI&, const Aws::Http::HttpMethod&)>; | ||
|
||
Aws::String GeneratePresignedUrl( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. having four generate presigned URL methods seems excessive and that we are creating bloat in this class. can we do something similar to how we did In fact we already do this on the old client but have it as a signer to look up. lets just add it as a mix in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the changes to have all legacy presigners in legacy client and smithy client have only one implementation. Under the hood, they all reuse a private implementation . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a to duplicate this method body? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are overlaps in the message body for the auth scheme selection bit, but differs in processing uri with request. I will push a commit with an attempt to reuse the overlapping block. |
||
ExtractUriCallback&& getUriCallback, | ||
CreateHttpRequestCallback&& createHttpRequestCallback, | ||
Aws::Http::HttpMethod method, | ||
const Aws::String& region, | ||
const Aws::String& serviceName, | ||
long long expirationInSeconds) const | ||
{ | ||
AwsSmithyClientAsyncRequestContext ctx; | ||
auto authSchemeOptionOutcome = SelectAuthSchemeOption( ctx); | ||
auto authSchemeOption = std::move(authSchemeOptionOutcome.GetResultWithOwnership()); | ||
Aws::Http::URI uri; | ||
Aws::String signerRegionOverride = region; | ||
Aws::String signerServiceNameOverride = serviceName; | ||
if(!getUriCallback(uri , signerRegionOverride, signerServiceNameOverride, authSchemeOption)) | ||
{ | ||
return {}; | ||
} | ||
std::shared_ptr<HttpRequest> request = createHttpRequestCallback(uri, method); | ||
if (AwsClientRequestSigning<AuthSchemesVariantT>::PreSignRequest(request, authSchemeOption, m_authSchemes, signerRegionOverride, signerServiceNameOverride, expirationInSeconds).IsSuccess()) | ||
{ | ||
return request->GetURIString(); | ||
} | ||
return {}; | ||
} | ||
|
||
friend class AwsLegacyClientT<ServiceNameT, ResponseT, AwsSmithyClientT<ServiceNameT, | ||
ServiceClientConfigurationT, | ||
ServiceAuthSchemeResolverT, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
|
||
|
@@ -176,7 +177,7 @@ protected List<SdkFileEntry> generateClientSourceFile( List<ServiceModel> servic | |
{ | ||
if(serviceModels.get(index).isUseSmithyClient() && !serviceModels.get(index).hasEventStreamingRequestShapes()) | ||
{ | ||
return GenerateSmithyClientSourceFile(serviceModels.get(index), index); | ||
return GenerateSmithyClientSourceFile(serviceModels.get(index), index, Optional.empty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reuse base class function |
||
} | ||
else | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so fan of having on presigner now, only question i really have is why is this in the the Smithy client and the others legcy. I think something that we could talk about is "what the public interface of a pre signer should be". but since this is already here, im open to moving forward without having a answer for that for now