@@ -228,7 +228,7 @@ namespace client
228228 auto httpResponseOutcome = MakeRequestSync (request, requestName, method, std::move (endpointCallback));
229229 return m_serializer->Deserialize (std::move (httpResponseOutcome), GetServiceClientName (), requestName);
230230 }
231-
231+
232232 Aws::String GeneratePresignedUrl (
233233 EndpointUpdateCallback&& endpointCallback,
234234 Aws::Http::HttpMethod method,
@@ -238,110 +238,66 @@ namespace client
238238 const Aws::Http::HeaderValueCollection& customizedHeaders,
239239 const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const
240240 {
241- AwsSmithyClientAsyncRequestContext ctx;
242- auto authSchemeOptionOutcome = SelectAuthSchemeOption ( ctx);
243- auto authSchemeOption = std::move (authSchemeOptionOutcome.GetResultWithOwnership ());
244-
245- Aws::Endpoint::EndpointParameters epParams = Aws::Endpoint::EndpointParameters ();
246- const auto authSchemeEpParams = authSchemeOption.endpointParameters ();
247- epParams.insert (epParams.end (), authSchemeEpParams.begin (), authSchemeEpParams.end ());
248- if (serviceSpecificParameters)
249- {
250- auto bucketIt = serviceSpecificParameters->parameterMap .find (" bucketName" );
251- if (bucketIt != serviceSpecificParameters->parameterMap .end ())
241+ ExtractUriCallback getUriCallback = [&](Aws::Http::URI& uri, Aws::String& signerRegionOverride,
242+ Aws::String& signerServiceNameOverride, const AuthSchemeOption& authSchemeOption) -> bool {
243+
244+ Aws::Endpoint::EndpointParameters epParams = Aws::Endpoint::EndpointParameters ();
245+ const auto authSchemeEpParams = authSchemeOption.endpointParameters ();
246+ epParams.insert (epParams.end (), authSchemeEpParams.begin (), authSchemeEpParams.end ());
247+ if (serviceSpecificParameters)
252248 {
253- auto bucket = bucketIt->second ;
254- epParams.emplace_back (Aws::String (" Bucket" ), bucket);
249+ auto bucketIt = serviceSpecificParameters->parameterMap .find (" bucketName" );
250+ if (bucketIt != serviceSpecificParameters->parameterMap .end ())
251+ {
252+ auto bucket = bucketIt->second ;
253+ epParams.emplace_back (Aws::String (" Bucket" ), bucket);
254+ }
255255 }
256- }
257256
258- auto epResolutionOutcome = this ->ResolveEndpoint (std::move (epParams), std::move (endpointCallback));
259- if (!epResolutionOutcome.IsSuccess ())
260- {
261- AWS_LOGSTREAM_ERROR (ServiceNameT, " Presigned URL generating failed. Encountered error: " << epResolutionOutcome.GetError ().GetMessage ());
262- return {};
263- }
264- auto endpoint = std::move (epResolutionOutcome.GetResultWithOwnership ());
265- const Aws::Http::URI& uri = endpoint.GetURI ();
266- auto signerRegionOverride = region;
267- auto signerServiceNameOverride = serviceName;
268- // signer name is needed for some identity resolvers
269- if (endpoint.GetAttributes ()) {
270- if (endpoint.GetAttributes ()->authScheme .GetSigningRegion ()) {
271- signerRegionOverride = endpoint.GetAttributes ()->authScheme .GetSigningRegion ()->c_str ();
272- }
273- if (endpoint.GetAttributes ()->authScheme .GetSigningRegionSet ()) {
274- signerRegionOverride = endpoint.GetAttributes ()->authScheme .GetSigningRegionSet ()->c_str ();
257+ auto epResolutionOutcome = this ->ResolveEndpoint (std::move (epParams), std::move (endpointCallback));
258+ if (!epResolutionOutcome.IsSuccess ())
259+ {
260+ AWS_LOGSTREAM_ERROR (ServiceNameT, " Presigned URL generating failed. Encountered error: " << epResolutionOutcome.GetError ().GetMessage ());
261+ return false ;
275262 }
276- if (endpoint.GetAttributes ()->authScheme .GetSigningName ()) {
277- signerServiceNameOverride = endpoint.GetAttributes ()->authScheme .GetSigningName ()->c_str ();
263+ auto endpoint = std::move (epResolutionOutcome.GetResultWithOwnership ());
264+ uri = endpoint.GetURI ();
265+ signerRegionOverride = region;
266+ signerServiceNameOverride = serviceName;
267+ // signer name is needed for some identity resolvers
268+ if (endpoint.GetAttributes ()) {
269+ if (endpoint.GetAttributes ()->authScheme .GetSigningRegion ()) {
270+ signerRegionOverride = endpoint.GetAttributes ()->authScheme .GetSigningRegion ()->c_str ();
271+ }
272+ if (endpoint.GetAttributes ()->authScheme .GetSigningRegionSet ()) {
273+ signerRegionOverride = endpoint.GetAttributes ()->authScheme .GetSigningRegionSet ()->c_str ();
274+ }
275+ if (endpoint.GetAttributes ()->authScheme .GetSigningName ()) {
276+ signerServiceNameOverride = endpoint.GetAttributes ()->authScheme .GetSigningName ()->c_str ();
277+ }
278278 }
279- }
280- std::shared_ptr<HttpRequest> request = CreateHttpRequest (uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
281- request->SetServiceSpecificParameters (serviceSpecificParameters);
282- for (const auto & it: customizedHeaders)
283- {
284- request->SetHeaderValue (it.first .c_str (), it.second );
285- }
286- if (AwsClientRequestSigning<AuthSchemesVariantT>::PreSignRequest (request, authSchemeOption, m_authSchemes, signerRegionOverride, signerServiceNameOverride, expirationInSeconds).IsSuccess ())
287- {
288- return request->GetURIString ();
289- }
290- return {};
291- }
279+ return true ;
280+ };
292281
293- // legacy
294- Aws::String GeneratePresignedUrl (const Aws::Http::URI& uri,
295- Aws::Http::HttpMethod method,
296- const Aws::String& region,
297- const Aws::String& serviceName,
298- long long expirationInSeconds,
299- const Aws::Http::HeaderValueCollection& customizedHeaders,
300- const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const
301- {
302- std::shared_ptr<HttpRequest> request = CreateHttpRequest (uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
303- request->SetServiceSpecificParameters (serviceSpecificParameters);
304- for (const auto & it: customizedHeaders)
305- {
306- request->SetHeaderValue (it.first .c_str (), it.second );
307- }
308- AwsSmithyClientAsyncRequestContext ctx;
309- auto authSchemeOptionOutcome = SelectAuthSchemeOption ( ctx);
310- auto authSchemeOption = std::move (authSchemeOptionOutcome.GetResultWithOwnership ());
311- if (AwsClientRequestSigning<AuthSchemesVariantT>::PreSignRequest (request, authSchemeOption, m_authSchemes, region, serviceName, expirationInSeconds).IsSuccess ())
312- {
313- return request->GetURIString ();
314- }
315- return {};
316- }
317-
318-
319- Aws::String GeneratePresignedUrl (const Aws::Endpoint::AWSEndpoint& endpoint,
320- Aws::Http::HttpMethod method,
321- const Aws::String& region,
322- const Aws::String& serviceName,
323- long long expirationInSeconds,
324- const Aws::Http::HeaderValueCollection& customizedHeaders,
325- const std::shared_ptr<Aws::Http::ServiceSpecificParameters> serviceSpecificParameters) const
326- {
327- const Aws::Http::URI& uri = endpoint.GetURI ();
328- auto signerRegionOverride = region;
329- auto signerServiceNameOverride = serviceName;
330- // signer name is needed for some identity resolvers
331- if (endpoint.GetAttributes ()) {
332- if (endpoint.GetAttributes ()->authScheme .GetSigningRegion ()) {
333- signerRegionOverride = endpoint.GetAttributes ()->authScheme .GetSigningRegion ()->c_str ();
334- }
335- if (endpoint.GetAttributes ()->authScheme .GetSigningRegionSet ()) {
336- signerRegionOverride = endpoint.GetAttributes ()->authScheme .GetSigningRegionSet ()->c_str ();
337- }
338- if (endpoint.GetAttributes ()->authScheme .GetSigningName ()) {
339- signerServiceNameOverride = endpoint.GetAttributes ()->authScheme .GetSigningName ()->c_str ();
282+ CreateHttpRequestCallback createHttpRequestCallback = [&customizedHeaders, &serviceSpecificParameters](const Aws::Http::URI& uri, const Aws::Http::HttpMethod& method) -> std::shared_ptr<HttpRequest> {
283+ std::shared_ptr<HttpRequest> request = CreateHttpRequest (uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod);
284+ request->SetServiceSpecificParameters (serviceSpecificParameters);
285+ for (const auto & it: customizedHeaders)
286+ {
287+ request->SetHeaderValue (it.first .c_str (), it.second );
340288 }
341- }
342- return GeneratePresignedUrl (uri, method, signerRegionOverride, signerServiceNameOverride, expirationInSeconds, customizedHeaders, serviceSpecificParameters);
289+ return request;
290+ };
291+
292+ return GeneratePresignedUrl (
293+ std::move (getUriCallback),
294+ std::move (createHttpRequestCallback),
295+ method,
296+ region,
297+ serviceName,
298+ expirationInSeconds);
343299 }
344-
300+
345301 /* Service client specific config, the actual object is stored in AwsSmithyClientBase by pointer
346302 * In order to avoid config object duplication, smithy template client access it by a reference.
347303 * 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
352308 Aws::UnorderedMap<Aws::String, AuthSchemesVariantT> m_authSchemes{};
353309 std::shared_ptr<SerializerT> m_serializer{};
354310 private:
311+ using ExtractUriCallback = std::function<bool (Aws::Http::URI&, Aws::String& region, Aws::String& serviceName,const AuthSchemeOption&)>;
312+ using CreateHttpRequestCallback = std::function<std::shared_ptr<HttpRequest> (const Aws::Http::URI&, const Aws::Http::HttpMethod&)>;
313+
314+ Aws::String GeneratePresignedUrl (
315+ ExtractUriCallback&& getUriCallback,
316+ CreateHttpRequestCallback&& createHttpRequestCallback,
317+ Aws::Http::HttpMethod method,
318+ const Aws::String& region,
319+ const Aws::String& serviceName,
320+ long long expirationInSeconds) const
321+ {
322+ AwsSmithyClientAsyncRequestContext ctx;
323+ auto authSchemeOptionOutcome = SelectAuthSchemeOption ( ctx);
324+ auto authSchemeOption = std::move (authSchemeOptionOutcome.GetResultWithOwnership ());
325+ Aws::Http::URI uri;
326+ Aws::String signerRegionOverride = region;
327+ Aws::String signerServiceNameOverride = serviceName;
328+ if (!getUriCallback (uri , signerRegionOverride, signerServiceNameOverride, authSchemeOption))
329+ {
330+ return {};
331+ }
332+ std::shared_ptr<HttpRequest> request = createHttpRequestCallback (uri, method);
333+ if (AwsClientRequestSigning<AuthSchemesVariantT>::PreSignRequest (request, authSchemeOption, m_authSchemes, signerRegionOverride, signerServiceNameOverride, expirationInSeconds).IsSuccess ())
334+ {
335+ return request->GetURIString ();
336+ }
337+ return {};
338+ }
339+
355340 friend class AwsLegacyClientT <ServiceNameT, ResponseT, AwsSmithyClientT<ServiceNameT,
356341 ServiceClientConfigurationT,
357342 ServiceAuthSchemeResolverT,
0 commit comments