diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:01 +0300 |
commit | 2d37894b1b037cf24231090eda8589bbb44fb6fc (patch) | |
tree | be835aa92c6248212e705f25388ebafcf84bc7a1 /contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client | |
parent | 718c552901d703c502ccbefdfc3c9028d608b947 (diff) | |
download | ydb-2d37894b1b037cf24231090eda8589bbb44fb6fc.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client')
8 files changed, 700 insertions, 700 deletions
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp index 8fa8421b49..e1ff064840 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSClient.cpp @@ -1,6 +1,6 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. */ #include <aws/core/client/AWSClient.h> @@ -16,7 +16,7 @@ #include <aws/core/http/HttpClientFactory.h> #include <aws/core/http/HttpResponse.h> #include <aws/core/http/standard/StandardHttpResponse.h> -#include <aws/core/http/URI.h> +#include <aws/core/http/URI.h> #include <aws/core/utils/stream/ResponseStream.h> #include <aws/core/utils/json/JsonSerializer.h> #include <aws/core/utils/Outcome.h> @@ -29,13 +29,13 @@ #include <aws/core/utils/crypto/MD5.h> #include <aws/core/utils/HashingUtils.h> #include <aws/core/utils/crypto/Factories.h> -#include <aws/core/utils/event/EventStream.h> -#include <aws/core/utils/UUID.h> +#include <aws/core/utils/event/EventStream.h> +#include <aws/core/utils/UUID.h> #include <aws/core/monitoring/MonitoringManager.h> -#include <aws/core/Region.h> -#include <aws/core/utils/DNS.h> -#include <aws/core/Version.h> -#include <aws/core/platform/OSVersionInfo.h> +#include <aws/core/Region.h> +#include <aws/core/utils/DNS.h> +#include <aws/core/Version.h> +#include <aws/core/platform/OSVersionInfo.h> #include <cstring> #include <cassert> @@ -52,7 +52,7 @@ static const int SUCCESS_RESPONSE_MAX = 299; static const char AWS_CLIENT_LOG_TAG[] = "AWSClient"; //4 Minutes -static const std::chrono::milliseconds TIME_DIFF_MAX = std::chrono::minutes(4); +static const std::chrono::milliseconds TIME_DIFF_MAX = std::chrono::minutes(4); //-4 Minutes static const std::chrono::milliseconds TIME_DIFF_MIN = std::chrono::minutes(-4); @@ -67,36 +67,36 @@ static CoreErrors GuessBodylessErrorType(Aws::Http::HttpResponseCode responseCod return CoreErrors::RESOURCE_NOT_FOUND; default: return CoreErrors::UNKNOWN; - } + } } -struct RequestInfo -{ - Aws::Utils::DateTime ttl; - long attempt; - long maxAttempts; - - operator String() - { - Aws::StringStream ss; - if (ttl.WasParseSuccessful() && ttl != DateTime()) - { - assert(attempt > 1); - ss << "ttl=" << ttl.ToGmtString(DateFormat::ISO_8601_BASIC) << "; "; - } - ss << "attempt=" << attempt; - if (maxAttempts > 0) - { - ss << "; max=" << maxAttempts; - } - return ss.str(); - } -}; - +struct RequestInfo +{ + Aws::Utils::DateTime ttl; + long attempt; + long maxAttempts; + + operator String() + { + Aws::StringStream ss; + if (ttl.WasParseSuccessful() && ttl != DateTime()) + { + assert(attempt > 1); + ss << "ttl=" << ttl.ToGmtString(DateFormat::ISO_8601_BASIC) << "; "; + } + ss << "attempt=" << attempt; + if (maxAttempts > 0) + { + ss << "; max=" << maxAttempts; + } + return ss.str(); + } +}; + AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration, const std::shared_ptr<Aws::Client::AWSAuthSigner>& signer, const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : - m_region(configuration.region), + m_region(configuration.region), m_httpClient(CreateHttpClient(configuration)), m_signerProvider(Aws::MakeUnique<Aws::Auth::DefaultAuthSignerProvider>(AWS_CLIENT_LOG_TAG, signer)), m_errorMarshaller(errorMarshaller), @@ -104,18 +104,18 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration, m_writeRateLimiter(configuration.writeRateLimiter), m_readRateLimiter(configuration.readRateLimiter), m_userAgent(configuration.userAgent), - m_customizedUserAgent(!m_userAgent.empty()), + m_customizedUserAgent(!m_userAgent.empty()), m_hash(Aws::Utils::Crypto::CreateMD5Implementation()), - m_requestTimeoutMs(configuration.requestTimeoutMs), + m_requestTimeoutMs(configuration.requestTimeoutMs), m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment) { - SetServiceClientName("AWSBaseClient"); + SetServiceClientName("AWSBaseClient"); } AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration, const std::shared_ptr<Aws::Auth::AWSAuthSignerProvider>& signerProvider, const std::shared_ptr<AWSErrorMarshaller>& errorMarshaller) : - m_region(configuration.region), + m_region(configuration.region), m_httpClient(CreateHttpClient(configuration)), m_signerProvider(signerProvider), m_errorMarshaller(errorMarshaller), @@ -123,33 +123,33 @@ AWSClient::AWSClient(const Aws::Client::ClientConfiguration& configuration, m_writeRateLimiter(configuration.writeRateLimiter), m_readRateLimiter(configuration.readRateLimiter), m_userAgent(configuration.userAgent), - m_customizedUserAgent(!m_userAgent.empty()), + m_customizedUserAgent(!m_userAgent.empty()), m_hash(Aws::Utils::Crypto::CreateMD5Implementation()), - m_requestTimeoutMs(configuration.requestTimeoutMs), + m_requestTimeoutMs(configuration.requestTimeoutMs), m_enableClockSkewAdjustment(configuration.enableClockSkewAdjustment) { - SetServiceClientName("AWSBaseClient"); + SetServiceClientName("AWSBaseClient"); +} + +void AWSClient::SetServiceClientName(const Aws::String& name) +{ + m_serviceName = name; + if (!m_customizedUserAgent) + { + Aws::StringStream ss; + ss << "aws-sdk-cpp/" << Version::GetVersionString() << "/" << m_serviceName << "/" << Aws::OSVersionInfo::ComputeOSVersionString() + << " " << Version::GetCompilerVersionString(); + m_userAgent = ss.str(); + } } -void AWSClient::SetServiceClientName(const Aws::String& name) -{ - m_serviceName = name; - if (!m_customizedUserAgent) - { - Aws::StringStream ss; - ss << "aws-sdk-cpp/" << Version::GetVersionString() << "/" << m_serviceName << "/" << Aws::OSVersionInfo::ComputeOSVersionString() - << " " << Version::GetCompilerVersionString(); - m_userAgent = ss.str(); - } +void AWSClient::DisableRequestProcessing() +{ + m_httpClient->DisableRequestProcessing(); } -void AWSClient::DisableRequestProcessing() -{ - m_httpClient->DisableRequestProcessing(); -} - -void AWSClient::EnableRequestProcessing() -{ +void AWSClient::EnableRequestProcessing() +{ m_httpClient->EnableRequestProcessing(); } @@ -159,34 +159,34 @@ Aws::Client::AWSAuthSigner* AWSClient::GetSignerByName(const char* name) const return signer ? signer.get() : nullptr; } -static DateTime GetServerTimeFromError(const AWSError<CoreErrors> error) -{ - const Http::HeaderValueCollection& headers = error.GetResponseHeaders(); - auto awsDateHeaderIter = headers.find(StringUtils::ToLower(Http::AWS_DATE_HEADER)); - auto dateHeaderIter = headers.find(StringUtils::ToLower(Http::DATE_HEADER)); - if (awsDateHeaderIter != headers.end()) - { - return DateTime(awsDateHeaderIter->second.c_str(), DateFormat::AutoDetect); - } - else if (dateHeaderIter != headers.end()) - { - return DateTime(dateHeaderIter->second.c_str(), DateFormat::AutoDetect); - } - else - { - return DateTime(); - } -} - +static DateTime GetServerTimeFromError(const AWSError<CoreErrors> error) +{ + const Http::HeaderValueCollection& headers = error.GetResponseHeaders(); + auto awsDateHeaderIter = headers.find(StringUtils::ToLower(Http::AWS_DATE_HEADER)); + auto dateHeaderIter = headers.find(StringUtils::ToLower(Http::DATE_HEADER)); + if (awsDateHeaderIter != headers.end()) + { + return DateTime(awsDateHeaderIter->second.c_str(), DateFormat::AutoDetect); + } + else if (dateHeaderIter != headers.end()) + { + return DateTime(dateHeaderIter->second.c_str(), DateFormat::AutoDetect); + } + else + { + return DateTime(); + } +} + bool AWSClient::AdjustClockSkew(HttpResponseOutcome& outcome, const char* signerName) const { if (m_enableClockSkewAdjustment) { auto signer = GetSignerByName(signerName); - //detect clock skew and try to correct. + //detect clock skew and try to correct. AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "If the signature check failed. This could be because of a time skew. Attempting to adjust the signer."); - DateTime serverTime = GetServerTimeFromError(outcome.GetError()); + DateTime serverTime = GetServerTimeFromError(outcome.GetError()); const auto signingTimestamp = signer->GetSigningTimestamp(); if (!serverTime.WasParseSuccessful() || serverTime == DateTime()) { @@ -202,11 +202,11 @@ bool AWSClient::AdjustClockSkew(HttpResponseOutcome& outcome, const char* signer diff = DateTime::Diff(serverTime, DateTime::Now()); AWS_LOGSTREAM_INFO(AWS_CLIENT_LOG_TAG, "Computed time difference as " << diff.count() << " milliseconds. Adjusting signer with the skew."); signer->SetClockSkew(diff); - AWSError<CoreErrors> newError( + AWSError<CoreErrors> newError( outcome.GetError().GetErrorType(), outcome.GetError().GetExceptionName(), outcome.GetError().GetMessage(), true); newError.SetResponseHeaders(outcome.GetError().GetResponseHeaders()); newError.SetResponseCode(outcome.GetError().GetResponseCode()); - outcome = std::move(newError); + outcome = std::move(newError); return true; } } @@ -216,43 +216,43 @@ bool AWSClient::AdjustClockSkew(HttpResponseOutcome& outcome, const char* signer HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, const Aws::AmazonWebServiceRequest& request, HttpMethod method, - const char* signerName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const + const char* signerName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - if (!Aws::Utils::IsValidHost(uri.GetAuthority())) - { - return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::VALIDATION, "", "Invalid DNS Label found in URI host", false/*retryable*/)); - } + if (!Aws::Utils::IsValidHost(uri.GetAuthority())) + { + return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::VALIDATION, "", "Invalid DNS Label found in URI host", false/*retryable*/)); + } std::shared_ptr<HttpRequest> httpRequest(CreateHttpRequest(uri, method, request.GetResponseStreamFactory())); HttpResponseOutcome outcome; - AWSError<CoreErrors> lastError; + AWSError<CoreErrors> lastError; Aws::Monitoring::CoreMetricsCollection coreMetrics; auto contexts = Aws::Monitoring::OnRequestStarted(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest); - const char* signerRegion = signerRegionOverride; - Aws::String regionFromResponse; - - Aws::String invocationId = UUID::RandomUUID(); - RequestInfo requestInfo; - requestInfo.attempt = 1; - requestInfo.maxAttempts = 0; - httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); - httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); - + const char* signerRegion = signerRegionOverride; + Aws::String regionFromResponse; + + Aws::String invocationId = UUID::RandomUUID(); + RequestInfo requestInfo; + requestInfo.attempt = 1; + requestInfo.maxAttempts = 0; + httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); + httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); + for (long retries = 0;; retries++) { - m_retryStrategy->GetSendToken(); - httpRequest->SetEventStreamRequest(request.IsEventStreamRequest()); - - outcome = AttemptOneRequest(httpRequest, request, signerName, signerRegion, signerServiceNameOverride); - if (retries == 0) - { - m_retryStrategy->RequestBookkeeping(outcome); - } - else - { - m_retryStrategy->RequestBookkeeping(outcome, lastError); - } + m_retryStrategy->GetSendToken(); + httpRequest->SetEventStreamRequest(request.IsEventStreamRequest()); + + outcome = AttemptOneRequest(httpRequest, request, signerName, signerRegion, signerServiceNameOverride); + if (retries == 0) + { + m_retryStrategy->RequestBookkeeping(outcome); + } + else + { + m_retryStrategy->RequestBookkeeping(outcome, lastError); + } coreMetrics.httpClientMetrics = httpRequest->GetRequestMetrics(); if (outcome.IsSuccess()) { @@ -260,11 +260,11 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request successful returning."); break; } - lastError = outcome.GetError(); + lastError = outcome.GetError(); + + DateTime serverTime = GetServerTimeFromError(outcome.GetError()); + auto clockSkew = DateTime::Diff(serverTime, DateTime::Now()); - DateTime serverTime = GetServerTimeFromError(outcome.GetError()); - auto clockSkew = DateTime::Diff(serverTime, DateTime::Now()); - Aws::Monitoring::OnRequestFailed(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, outcome, coreMetrics, contexts); if (!m_httpClient->IsRequestProcessingEnabled()) @@ -273,28 +273,28 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, break; } - // Adjust region - bool retryWithCorrectRegion = false; - HttpResponseCode httpResponseCode = outcome.GetError().GetResponseCode(); - if (httpResponseCode == HttpResponseCode::MOVED_PERMANENTLY || // 301 - httpResponseCode == HttpResponseCode::TEMPORARY_REDIRECT || // 307 - httpResponseCode == HttpResponseCode::BAD_REQUEST || // 400 - httpResponseCode == HttpResponseCode::FORBIDDEN) // 403 - { - regionFromResponse = GetErrorMarshaller()->ExtractRegion(outcome.GetError()); - if (m_region == Aws::Region::AWS_GLOBAL && !regionFromResponse.empty() && regionFromResponse != signerRegion) - { - signerRegion = regionFromResponse.c_str(); - retryWithCorrectRegion = true; - } - } - + // Adjust region + bool retryWithCorrectRegion = false; + HttpResponseCode httpResponseCode = outcome.GetError().GetResponseCode(); + if (httpResponseCode == HttpResponseCode::MOVED_PERMANENTLY || // 301 + httpResponseCode == HttpResponseCode::TEMPORARY_REDIRECT || // 307 + httpResponseCode == HttpResponseCode::BAD_REQUEST || // 400 + httpResponseCode == HttpResponseCode::FORBIDDEN) // 403 + { + regionFromResponse = GetErrorMarshaller()->ExtractRegion(outcome.GetError()); + if (m_region == Aws::Region::AWS_GLOBAL && !regionFromResponse.empty() && regionFromResponse != signerRegion) + { + signerRegion = regionFromResponse.c_str(); + retryWithCorrectRegion = true; + } + } + long sleepMillis = m_retryStrategy->CalculateDelayBeforeNextRetry(outcome.GetError(), retries); //AdjustClockSkew returns true means clock skew was the problem and skew was adjusted, false otherwise. - //sleep if clock skew and region was NOT the problem. AdjustClockSkew may update error inside outcome. - bool shouldSleep = !AdjustClockSkew(outcome, signerName) && !retryWithCorrectRegion; + //sleep if clock skew and region was NOT the problem. AdjustClockSkew may update error inside outcome. + bool shouldSleep = !AdjustClockSkew(outcome, signerName) && !retryWithCorrectRegion; - if (!retryWithCorrectRegion && !m_retryStrategy->ShouldRetry(outcome.GetError(), retries)) + if (!retryWithCorrectRegion && !m_retryStrategy->ShouldRetry(outcome.GetError(), retries)) { break; } @@ -315,68 +315,68 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, { m_httpClient->RetryRequestSleep(std::chrono::milliseconds(sleepMillis)); } - - Aws::Http::URI newUri = uri; - Aws::String newEndpoint = GetErrorMarshaller()->ExtractEndpoint(outcome.GetError()); - if (!newEndpoint.empty()) - { - newUri.SetAuthority(newEndpoint); - } - httpRequest = CreateHttpRequest(newUri, method, request.GetResponseStreamFactory()); - - httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); - if (serverTime.WasParseSuccessful() && serverTime != DateTime()) - { - requestInfo.ttl = DateTime::Now() + clockSkew + std::chrono::milliseconds(m_requestTimeoutMs); - } - requestInfo.attempt ++; - requestInfo.maxAttempts = m_retryStrategy->GetMaxAttempts(); - httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); + + Aws::Http::URI newUri = uri; + Aws::String newEndpoint = GetErrorMarshaller()->ExtractEndpoint(outcome.GetError()); + if (!newEndpoint.empty()) + { + newUri.SetAuthority(newEndpoint); + } + httpRequest = CreateHttpRequest(newUri, method, request.GetResponseStreamFactory()); + + httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); + if (serverTime.WasParseSuccessful() && serverTime != DateTime()) + { + requestInfo.ttl = DateTime::Now() + clockSkew + std::chrono::milliseconds(m_requestTimeoutMs); + } + requestInfo.attempt ++; + requestInfo.maxAttempts = m_retryStrategy->GetMaxAttempts(); + httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); Aws::Monitoring::OnRequestRetry(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, contexts); } Aws::Monitoring::OnFinish(this->GetServiceClientName(), request.GetServiceRequestName(), httpRequest, contexts); return outcome; } -HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, - HttpMethod method, - const char* signerName, - const char* requestName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const +HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, + HttpMethod method, + const char* signerName, + const char* requestName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - if (!Aws::Utils::IsValidHost(uri.GetAuthority())) - { - return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::VALIDATION, "", "Invalid DNS Label found in URI host", false/*retryable*/)); - } - + if (!Aws::Utils::IsValidHost(uri.GetAuthority())) + { + return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::VALIDATION, "", "Invalid DNS Label found in URI host", false/*retryable*/)); + } + std::shared_ptr<HttpRequest> httpRequest(CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod)); HttpResponseOutcome outcome; - AWSError<CoreErrors> lastError; + AWSError<CoreErrors> lastError; Aws::Monitoring::CoreMetricsCollection coreMetrics; auto contexts = Aws::Monitoring::OnRequestStarted(this->GetServiceClientName(), requestName, httpRequest); - const char* signerRegion = signerRegionOverride; - Aws::String regionFromResponse; - - Aws::String invocationId = UUID::RandomUUID(); - RequestInfo requestInfo; - requestInfo.attempt = 1; - requestInfo.maxAttempts = 0; - httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); - httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); - + const char* signerRegion = signerRegionOverride; + Aws::String regionFromResponse; + + Aws::String invocationId = UUID::RandomUUID(); + RequestInfo requestInfo; + requestInfo.attempt = 1; + requestInfo.maxAttempts = 0; + httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); + httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); + for (long retries = 0;; retries++) { - m_retryStrategy->GetSendToken(); - outcome = AttemptOneRequest(httpRequest, signerName, requestName, signerRegion, signerServiceNameOverride); - if (retries == 0) - { - m_retryStrategy->RequestBookkeeping(outcome); - } - else - { - m_retryStrategy->RequestBookkeeping(outcome, lastError); - } + m_retryStrategy->GetSendToken(); + outcome = AttemptOneRequest(httpRequest, signerName, requestName, signerRegion, signerServiceNameOverride); + if (retries == 0) + { + m_retryStrategy->RequestBookkeeping(outcome); + } + else + { + m_retryStrategy->RequestBookkeeping(outcome, lastError); + } coreMetrics.httpClientMetrics = httpRequest->GetRequestMetrics(); if (outcome.IsSuccess()) { @@ -384,11 +384,11 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Request successful returning."); break; } - lastError = outcome.GetError(); + lastError = outcome.GetError(); + + DateTime serverTime = GetServerTimeFromError(outcome.GetError()); + auto clockSkew = DateTime::Diff(serverTime, DateTime::Now()); - DateTime serverTime = GetServerTimeFromError(outcome.GetError()); - auto clockSkew = DateTime::Diff(serverTime, DateTime::Now()); - Aws::Monitoring::OnRequestFailed(this->GetServiceClientName(), requestName, httpRequest, outcome, coreMetrics, contexts); if (!m_httpClient->IsRequestProcessingEnabled()) @@ -397,28 +397,28 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, break; } - // Adjust region - bool retryWithCorrectRegion = false; - HttpResponseCode httpResponseCode = outcome.GetError().GetResponseCode(); - if (httpResponseCode == HttpResponseCode::MOVED_PERMANENTLY || // 301 - httpResponseCode == HttpResponseCode::TEMPORARY_REDIRECT || // 307 - httpResponseCode == HttpResponseCode::BAD_REQUEST || // 400 - httpResponseCode == HttpResponseCode::FORBIDDEN) // 403 - { - regionFromResponse = GetErrorMarshaller()->ExtractRegion(outcome.GetError()); - if (m_region == Aws::Region::AWS_GLOBAL && !regionFromResponse.empty() && regionFromResponse != signerRegion) - { - signerRegion = regionFromResponse.c_str(); - retryWithCorrectRegion = true; - } - } - + // Adjust region + bool retryWithCorrectRegion = false; + HttpResponseCode httpResponseCode = outcome.GetError().GetResponseCode(); + if (httpResponseCode == HttpResponseCode::MOVED_PERMANENTLY || // 301 + httpResponseCode == HttpResponseCode::TEMPORARY_REDIRECT || // 307 + httpResponseCode == HttpResponseCode::BAD_REQUEST || // 400 + httpResponseCode == HttpResponseCode::FORBIDDEN) // 403 + { + regionFromResponse = GetErrorMarshaller()->ExtractRegion(outcome.GetError()); + if (m_region == Aws::Region::AWS_GLOBAL && !regionFromResponse.empty() && regionFromResponse != signerRegion) + { + signerRegion = regionFromResponse.c_str(); + retryWithCorrectRegion = true; + } + } + long sleepMillis = m_retryStrategy->CalculateDelayBeforeNextRetry(outcome.GetError(), retries); //AdjustClockSkew returns true means clock skew was the problem and skew was adjusted, false otherwise. - //sleep if clock skew and region was NOT the problem. AdjustClockSkew may update error inside outcome. - bool shouldSleep = !AdjustClockSkew(outcome, signerName) && !retryWithCorrectRegion; + //sleep if clock skew and region was NOT the problem. AdjustClockSkew may update error inside outcome. + bool shouldSleep = !AdjustClockSkew(outcome, signerName) && !retryWithCorrectRegion; - if (!retryWithCorrectRegion && !m_retryStrategy->ShouldRetry(outcome.GetError(), retries)) + if (!retryWithCorrectRegion && !m_retryStrategy->ShouldRetry(outcome.GetError(), retries)) { break; } @@ -429,23 +429,23 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, { m_httpClient->RetryRequestSleep(std::chrono::milliseconds(sleepMillis)); } - - Aws::Http::URI newUri = uri; - Aws::String newEndpoint = GetErrorMarshaller()->ExtractEndpoint(outcome.GetError()); - if (!newEndpoint.empty()) - { - newUri.SetAuthority(newEndpoint); - } - httpRequest = CreateHttpRequest(newUri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - - httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); - if (serverTime.WasParseSuccessful() && serverTime != DateTime()) - { - requestInfo.ttl = DateTime::Now() + clockSkew + std::chrono::milliseconds(m_requestTimeoutMs); - } - requestInfo.attempt ++; - requestInfo.maxAttempts = m_retryStrategy->GetMaxAttempts(); - httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); + + Aws::Http::URI newUri = uri; + Aws::String newEndpoint = GetErrorMarshaller()->ExtractEndpoint(outcome.GetError()); + if (!newEndpoint.empty()) + { + newUri.SetAuthority(newEndpoint); + } + httpRequest = CreateHttpRequest(newUri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); + + httpRequest->SetHeaderValue(Http::SDK_INVOCATION_ID_HEADER, invocationId); + if (serverTime.WasParseSuccessful() && serverTime != DateTime()) + { + requestInfo.ttl = DateTime::Now() + clockSkew + std::chrono::milliseconds(m_requestTimeoutMs); + } + requestInfo.attempt ++; + requestInfo.maxAttempts = m_retryStrategy->GetMaxAttempts(); + httpRequest->SetHeaderValue(Http::SDK_REQUEST_HEADER, requestInfo); Aws::Monitoring::OnRequestRetry(this->GetServiceClientName(), requestName, httpRequest, contexts); } Aws::Monitoring::OnFinish(this->GetServiceClientName(), requestName, httpRequest, contexts); @@ -454,29 +454,29 @@ HttpResponseOutcome AWSClient::AttemptExhaustively(const Aws::Http::URI& uri, static bool DoesResponseGenerateError(const std::shared_ptr<HttpResponse>& response) { - if (response->HasClientError()) return true; + if (response->HasClientError()) return true; int responseCode = static_cast<int>(response->GetResponseCode()); return responseCode < SUCCESS_RESPONSE_MIN || responseCode > SUCCESS_RESPONSE_MAX; } -HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<HttpRequest>& httpRequest, const Aws::AmazonWebServiceRequest& request, - const char* signerName, const char* signerRegionOverride, const char* signerServiceNameOverride) const +HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<HttpRequest>& httpRequest, const Aws::AmazonWebServiceRequest& request, + const char* signerName, const char* signerRegionOverride, const char* signerServiceNameOverride) const { BuildHttpRequest(request, httpRequest); auto signer = GetSignerByName(signerName); - if (!signer->SignRequest(*httpRequest, signerRegionOverride, signerServiceNameOverride, request.SignBody())) + if (!signer->SignRequest(*httpRequest, signerRegionOverride, signerServiceNameOverride, request.SignBody())) { AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Request signing failed. Returning error."); return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::CLIENT_SIGNING_FAILURE, "", "SDK failed to sign the request", false/*retryable*/)); } - if (request.GetRequestSignedHandler()) - { - request.GetRequestSignedHandler()(*httpRequest); - } - + if (request.GetRequestSignedHandler()) + { + request.GetRequestSignedHandler()(*httpRequest); + } + AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request Successfully signed"); std::shared_ptr<HttpResponse> httpResponse( m_httpClient->MakeRequest(httpRequest, m_readRateLimiter.get(), m_writeRateLimiter.get())); @@ -484,22 +484,22 @@ HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<HttpReque if (DoesResponseGenerateError(httpResponse)) { AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); - auto error = BuildAWSError(httpResponse); - return HttpResponseOutcome(std::move(error)); + auto error = BuildAWSError(httpResponse); + return HttpResponseOutcome(std::move(error)); } AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); - return HttpResponseOutcome(std::move(httpResponse)); + return HttpResponseOutcome(std::move(httpResponse)); } -HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<HttpRequest>& httpRequest, - const char* signerName, const char* requestName, const char* signerRegionOverride, const char* signerServiceNameOverride) const +HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<HttpRequest>& httpRequest, + const char* signerName, const char* requestName, const char* signerRegionOverride, const char* signerServiceNameOverride) const { AWS_UNREFERENCED_PARAM(requestName); auto signer = GetSignerByName(signerName); - if (!signer->SignRequest(*httpRequest, signerRegionOverride, signerServiceNameOverride, true)) + if (!signer->SignRequest(*httpRequest, signerRegionOverride, signerServiceNameOverride, true)) { AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, "Request signing failed. Returning error."); return HttpResponseOutcome(AWSError<CoreErrors>(CoreErrors::CLIENT_SIGNING_FAILURE, "", "SDK failed to sign the request", false/*retryable*/)); @@ -515,23 +515,23 @@ HttpResponseOutcome AWSClient::AttemptOneRequest(const std::shared_ptr<HttpReque if (DoesResponseGenerateError(httpResponse)) { AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); - auto error = BuildAWSError(httpResponse); - return HttpResponseOutcome(std::move(error)); + auto error = BuildAWSError(httpResponse); + return HttpResponseOutcome(std::move(error)); } AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); - return HttpResponseOutcome(std::move(httpResponse)); + return HttpResponseOutcome(std::move(httpResponse)); } StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& uri, const Aws::AmazonWebServiceRequest& request, Http::HttpMethod method, - const char* signerName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const + const char* signerName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - HttpResponseOutcome httpResponseOutcome = AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride); + HttpResponseOutcome httpResponseOutcome = AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride); if (httpResponseOutcome.IsSuccess()) { return StreamOutcome(AmazonWebServiceResult<Stream::ResponseStream>( @@ -539,17 +539,17 @@ StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& u httpResponseOutcome.GetResult()->GetHeaders(), httpResponseOutcome.GetResult()->GetResponseCode())); } - return StreamOutcome(std::move(httpResponseOutcome)); + return StreamOutcome(std::move(httpResponseOutcome)); } -StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& uri, - Http::HttpMethod method, - const char* signerName, - const char* requestName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const +StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& uri, + Http::HttpMethod method, + const char* signerName, + const char* requestName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - HttpResponseOutcome httpResponseOutcome = AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride); + HttpResponseOutcome httpResponseOutcome = AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride); if (httpResponseOutcome.IsSuccess()) { return StreamOutcome(AmazonWebServiceResult<Stream::ResponseStream>( @@ -557,39 +557,39 @@ StreamOutcome AWSClient::MakeRequestWithUnparsedResponse(const Aws::Http::URI& u httpResponseOutcome.GetResult()->GetHeaders(), httpResponseOutcome.GetResult()->GetResponseCode())); } - return StreamOutcome(std::move(httpResponseOutcome)); + return StreamOutcome(std::move(httpResponseOutcome)); } XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri, const Aws::AmazonWebServiceRequest& request, Http::HttpMethod method, - const char* signerName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const + const char* signerName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - HttpResponseOutcome httpOutcome = AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride); + HttpResponseOutcome httpOutcome = AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride); if (httpOutcome.IsSuccess()) { return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); } - return XmlOutcome(std::move(httpOutcome)); + return XmlOutcome(std::move(httpOutcome)); } -XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri, - Http::HttpMethod method, - const char* signerName, - const char* requestName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const +XmlOutcome AWSXMLClient::MakeRequestWithEventStream(const Aws::Http::URI& uri, + Http::HttpMethod method, + const char* signerName, + const char* requestName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - HttpResponseOutcome httpOutcome = AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride); + HttpResponseOutcome httpOutcome = AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride); if (httpOutcome.IsSuccess()) { return XmlOutcome(AmazonWebServiceResult<XmlDocument>(XmlDocument(), httpOutcome.GetResult()->GetHeaders())); } - return XmlOutcome(std::move(httpOutcome)); + return XmlOutcome(std::move(httpOutcome)); } void AWSClient::AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, @@ -604,7 +604,7 @@ void AWSClient::AddHeadersToRequest(const std::shared_ptr<Aws::Http::HttpRequest } void AWSClient::AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpRequest>& httpRequest, - const std::shared_ptr<Aws::IOStream>& body, bool needsContentMd5, bool isChunked) const + const std::shared_ptr<Aws::IOStream>& body, bool needsContentMd5, bool isChunked) const { httpRequest->AddContentBody(body); @@ -616,8 +616,8 @@ void AWSClient::AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpReq AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "No content body, content-length headers"); if(httpRequest->GetMethod() == HttpMethod::HTTP_POST || httpRequest->GetMethod() == HttpMethod::HTTP_PUT) - { - httpRequest->SetHeaderValue(Http::CONTENT_LENGTH_HEADER, "0"); + { + httpRequest->SetHeaderValue(Http::CONTENT_LENGTH_HEADER, "0"); } else { @@ -625,20 +625,20 @@ void AWSClient::AddContentBodyToRequest(const std::shared_ptr<Aws::Http::HttpReq } } - //Add transfer-encoding:chunked to header - if (body && isChunked) - { - httpRequest->SetTransferEncoding(CHUNKED_VALUE); - } + //Add transfer-encoding:chunked to header + if (body && isChunked) + { + httpRequest->SetTransferEncoding(CHUNKED_VALUE); + } //in the scenario where we are adding a content body as a stream, the request object likely already //has a content-length header set and we don't want to seek the stream just to find this information. - else if (body && !httpRequest->HasHeader(Http::CONTENT_LENGTH_HEADER)) + else if (body && !httpRequest->HasHeader(Http::CONTENT_LENGTH_HEADER)) { - if (!m_httpClient->SupportsChunkedTransferEncoding()) - { - AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "This http client doesn't support transfer-encoding:chunked. " << - "The request may fail if it's not a seekable stream."); - } + if (!m_httpClient->SupportsChunkedTransferEncoding()) + { + AWS_LOGSTREAM_WARN(AWS_CLIENT_LOG_TAG, "This http client doesn't support transfer-encoding:chunked. " << + "The request may fail if it's not a seekable stream."); + } AWS_LOGSTREAM_TRACE(AWS_CLIENT_LOG_TAG, "Found body, but content-length has not been set, attempting to compute content-length"); body->seekg(0, body->end); auto streamSize = body->tellg(); @@ -682,20 +682,20 @@ Aws::String Aws::Client::GetAuthorizationHeader(const Aws::Http::HttpRequest& ht return authHeader.substr(signaturePosition + strlen(Aws::Auth::SIGNATURE) + 1); } -void AWSClient::BuildHttpRequest(const Aws::AmazonWebServiceRequest& request, - const std::shared_ptr<HttpRequest>& httpRequest) const +void AWSClient::BuildHttpRequest(const Aws::AmazonWebServiceRequest& request, + const std::shared_ptr<HttpRequest>& httpRequest) const { - //do headers first since the request likely will set content-length as it's own header. + //do headers first since the request likely will set content-length as it's own header. AddHeadersToRequest(httpRequest, request.GetHeaders()); - if (request.IsEventStreamRequest()) + if (request.IsEventStreamRequest()) { - httpRequest->AddContentBody(request.GetBody()); + httpRequest->AddContentBody(request.GetBody()); + } + else + { + AddContentBodyToRequest(httpRequest, request.GetBody(), request.ShouldComputeContentMd5(), request.IsStreaming() && request.IsChunked() && m_httpClient->SupportsChunkedTransferEncoding()); } - else - { - AddContentBodyToRequest(httpRequest, request.GetBody(), request.ShouldComputeContentMd5(), request.IsStreaming() && request.IsChunked() && m_httpClient->SupportsChunkedTransferEncoding()); - } // Pass along handlers for processing data sent/received in bytes httpRequest->SetDataReceivedEventHandler(request.GetDataReceivedEventHandler()); @@ -738,34 +738,34 @@ Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const A return {}; } -Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const char* region, long long expirationInSeconds) const -{ - std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*request, region, expirationInSeconds)) - { - return request->GetURIString(); - } - - return {}; -} - -Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const char* region, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) -{ - std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - for (const auto& it: customizedHeaders) - { - request->SetHeaderValue(it.first.c_str(), it.second); - } - auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*request, region, expirationInSeconds)) - { - return request->GetURIString(); - } - - return {}; -} - +Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const char* region, long long expirationInSeconds) const +{ + std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + if (signer->PresignRequest(*request, region, expirationInSeconds)) + { + return request->GetURIString(); + } + + return {}; +} + +Aws::String AWSClient::GeneratePresignedUrl(URI& uri, HttpMethod method, const char* region, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) +{ + std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); + for (const auto& it: customizedHeaders) + { + request->SetHeaderValue(it.first.c_str(), it.second); + } + auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); + if (signer->PresignRequest(*request, region, expirationInSeconds)) + { + return request->GetURIString(); + } + + return {}; +} + Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, long long expirationInSeconds) const { std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); @@ -778,15 +778,15 @@ Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::Http return {}; } -Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) +Aws::String AWSClient::GeneratePresignedUrl(Aws::Http::URI& uri, Aws::Http::HttpMethod method, const char* region, const char* serviceName, const Aws::Http::HeaderValueCollection& customizedHeaders, long long expirationInSeconds) { std::shared_ptr<HttpRequest> request = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - for (const auto& it: customizedHeaders) - { - request->SetHeaderValue(it.first.c_str(), it.second); - } + for (const auto& it: customizedHeaders) + { + request->SetHeaderValue(it.first.c_str(), it.second); + } auto signer = GetSignerByName(Aws::Auth::SIGV4_SIGNER); - if (signer->PresignRequest(*request, region, serviceName, expirationInSeconds)) + if (signer->PresignRequest(*request, region, serviceName, expirationInSeconds)) { return request->GetURIString(); } @@ -841,7 +841,7 @@ std::shared_ptr<Aws::Http::HttpRequest> AWSClient::ConvertToRequestForPresigning { request.PutToPresignedUrl(uri); std::shared_ptr<HttpRequest> httpRequest = CreateHttpRequest(uri, method, Aws::Utils::Stream::DefaultResponseStreamFactoryMethod); - + for (auto& param : extraParams) { httpRequest->AddQueryStringParameter(param.first.c_str(), param.second); @@ -875,14 +875,14 @@ AWSJsonClient::AWSJsonClient(const Aws::Client::ClientConfiguration& configurati JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri, const Aws::AmazonWebServiceRequest& request, Http::HttpMethod method, - const char* signerName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const + const char* signerName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride)); + HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride)); if (!httpOutcome.IsSuccess()) { - return JsonOutcome(std::move(httpOutcome)); + return JsonOutcome(std::move(httpOutcome)); } if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) @@ -898,14 +898,14 @@ JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri, JsonOutcome AWSJsonClient::MakeRequest(const Aws::Http::URI& uri, Http::HttpMethod method, const char* signerName, - const char* requestName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const + const char* requestName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride)); + HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride)); if (!httpOutcome.IsSuccess()) { - return JsonOutcome(std::move(httpOutcome)); + return JsonOutcome(std::move(httpOutcome)); } if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) @@ -933,13 +933,13 @@ JsonOutcome AWSJsonClient::MakeEventStreamRequest(std::shared_ptr<Aws::Http::Htt if (DoesResponseGenerateError(httpResponse)) { AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned error. Attempting to generate appropriate error codes from response"); - auto error = BuildAWSError(httpResponse); - return JsonOutcome(std::move(error)); + auto error = BuildAWSError(httpResponse); + return JsonOutcome(std::move(error)); } AWS_LOGSTREAM_DEBUG(AWS_CLIENT_LOG_TAG, "Request returned successful response."); - HttpResponseOutcome httpOutcome(std::move(httpResponse)); + HttpResponseOutcome httpOutcome(std::move(httpResponse)); if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) { @@ -962,10 +962,10 @@ AWSError<CoreErrors> AWSJsonClient::BuildAWSError( const std::shared_ptr<Aws::Http::HttpResponse>& httpResponse) const { AWSError<CoreErrors> error; - if (httpResponse->HasClientError()) + if (httpResponse->HasClientError()) { - bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; - error = AWSError<CoreErrors>(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); + bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; + error = AWSError<CoreErrors>(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); } else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) { @@ -985,7 +985,7 @@ AWSError<CoreErrors> AWSJsonClient::BuildAWSError( error.SetResponseHeaders(httpResponse->GetHeaders()); error.SetResponseCode(httpResponse->GetResponseCode()); - error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost()); + error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost()); AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, error); return error; } @@ -1008,14 +1008,14 @@ AWSXMLClient::AWSXMLClient(const Aws::Client::ClientConfiguration& configuration XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri, const Aws::AmazonWebServiceRequest& request, Http::HttpMethod method, - const char* signerName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const + const char* signerName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride)); + HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, request, method, signerName, signerRegionOverride, signerServiceNameOverride)); if (!httpOutcome.IsSuccess()) { - return XmlOutcome(std::move(httpOutcome)); + return XmlOutcome(std::move(httpOutcome)); } if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) @@ -1038,14 +1038,14 @@ XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri, XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri, Http::HttpMethod method, const char* signerName, - const char* requestName, - const char* signerRegionOverride, - const char* signerServiceNameOverride) const + const char* requestName, + const char* signerRegionOverride, + const char* signerServiceNameOverride) const { - HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride)); + HttpResponseOutcome httpOutcome(BASECLASS::AttemptExhaustively(uri, method, signerName, requestName, signerRegionOverride, signerServiceNameOverride)); if (!httpOutcome.IsSuccess()) { - return XmlOutcome(std::move(httpOutcome)); + return XmlOutcome(std::move(httpOutcome)); } if (httpOutcome.GetResult()->GetResponseBody().tellp() > 0) @@ -1061,12 +1061,12 @@ XmlOutcome AWSXMLClient::MakeRequest(const Aws::Http::URI& uri, AWSError<CoreErrors> AWSXMLClient::BuildAWSError(const std::shared_ptr<Http::HttpResponse>& httpResponse) const { AWSError<CoreErrors> error; - if (httpResponse->HasClientError()) + if (httpResponse->HasClientError()) { - bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; - error = AWSError<CoreErrors>(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); + bool retryable = httpResponse->GetClientErrorType() == CoreErrors::NETWORK_CONNECTION ? true : false; + error = AWSError<CoreErrors>(httpResponse->GetClientErrorType(), "", httpResponse->GetClientErrorMessage(), retryable); } - else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) + else if (!httpResponse->GetResponseBody() || httpResponse->GetResponseBody().tellp() < 1) { auto responseCode = httpResponse->GetResponseCode(); auto errorCode = GuessBodylessErrorType(responseCode); @@ -1092,7 +1092,7 @@ AWSError<CoreErrors> AWSXMLClient::BuildAWSError(const std::shared_ptr<Http::Htt error.SetResponseHeaders(httpResponse->GetHeaders()); error.SetResponseCode(httpResponse->GetResponseCode()); - error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost()); + error.SetRemoteHostIpAddress(httpResponse->GetOriginatingRequest().GetResolvedRemoteHost()); AWS_LOGSTREAM_ERROR(AWS_CLIENT_LOG_TAG, error); return error; } diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp index 565d491015..f5fa676f98 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AWSErrorMarshaller.cpp @@ -1,7 +1,7 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ #include <aws/core/client/AWSErrorMarshaller.h> #include <aws/core/utils/logging/LogMacros.h> @@ -18,54 +18,54 @@ using namespace Aws::Http; using namespace Aws::Utils; using namespace Aws::Client; -static const char AWS_ERROR_MARSHALLER_LOG_TAG[] = "AWSErrorMarshaller"; -AWS_CORE_API extern const char MESSAGE_LOWER_CASE[] = "message"; -AWS_CORE_API extern const char MESSAGE_CAMEL_CASE[] = "Message"; -AWS_CORE_API extern const char ERROR_TYPE_HEADER[] = "x-amzn-ErrorType"; -AWS_CORE_API extern const char REQUEST_ID_HEADER[] = "x-amzn-RequestId"; -AWS_CORE_API extern const char TYPE[] = "__type"; +static const char AWS_ERROR_MARSHALLER_LOG_TAG[] = "AWSErrorMarshaller"; +AWS_CORE_API extern const char MESSAGE_LOWER_CASE[] = "message"; +AWS_CORE_API extern const char MESSAGE_CAMEL_CASE[] = "Message"; +AWS_CORE_API extern const char ERROR_TYPE_HEADER[] = "x-amzn-ErrorType"; +AWS_CORE_API extern const char REQUEST_ID_HEADER[] = "x-amzn-RequestId"; +AWS_CORE_API extern const char TYPE[] = "__type"; AWSError<CoreErrors> JsonErrorMarshaller::Marshall(const Aws::Http::HttpResponse& httpResponse) const { JsonValue exceptionPayload(httpResponse.GetResponseBody()); JsonView payloadView(exceptionPayload); - AWSError<CoreErrors> error; - if (exceptionPayload.WasParseSuccessful()) + AWSError<CoreErrors> error; + if (exceptionPayload.WasParseSuccessful()) { - AWS_LOGSTREAM_TRACE(AWS_ERROR_MARSHALLER_LOG_TAG, "Error response is " << payloadView.WriteReadable()); - - Aws::String message(payloadView.ValueExists(MESSAGE_CAMEL_CASE) ? payloadView.GetString(MESSAGE_CAMEL_CASE) : - payloadView.ValueExists(MESSAGE_LOWER_CASE) ? payloadView.GetString(MESSAGE_LOWER_CASE) : ""); - - if (httpResponse.HasHeader(ERROR_TYPE_HEADER)) - { - error = Marshall(httpResponse.GetHeader(ERROR_TYPE_HEADER), message); - } - else if (payloadView.ValueExists(TYPE)) - { - error = Marshall(payloadView.GetString(TYPE), message); - } - else - { - error = FindErrorByHttpResponseCode(httpResponse.GetResponseCode()); - error.SetMessage(message); - } + AWS_LOGSTREAM_TRACE(AWS_ERROR_MARSHALLER_LOG_TAG, "Error response is " << payloadView.WriteReadable()); + + Aws::String message(payloadView.ValueExists(MESSAGE_CAMEL_CASE) ? payloadView.GetString(MESSAGE_CAMEL_CASE) : + payloadView.ValueExists(MESSAGE_LOWER_CASE) ? payloadView.GetString(MESSAGE_LOWER_CASE) : ""); + + if (httpResponse.HasHeader(ERROR_TYPE_HEADER)) + { + error = Marshall(httpResponse.GetHeader(ERROR_TYPE_HEADER), message); + } + else if (payloadView.ValueExists(TYPE)) + { + error = Marshall(payloadView.GetString(TYPE), message); + } + else + { + error = FindErrorByHttpResponseCode(httpResponse.GetResponseCode()); + error.SetMessage(message); + } } else { - error = AWSError<CoreErrors>(CoreErrors::UNKNOWN, "", "Failed to parse error payload", false); + error = AWSError<CoreErrors>(CoreErrors::UNKNOWN, "", "Failed to parse error payload", false); } - - error.SetRequestId(httpResponse.HasHeader(REQUEST_ID_HEADER) ? httpResponse.GetHeader(REQUEST_ID_HEADER) : ""); - error.SetJsonPayload(std::move(exceptionPayload)); - return error; + + error.SetRequestId(httpResponse.HasHeader(REQUEST_ID_HEADER) ? httpResponse.GetHeader(REQUEST_ID_HEADER) : ""); + error.SetJsonPayload(std::move(exceptionPayload)); + return error; +} + +const JsonValue& JsonErrorMarshaller::GetJsonPayloadFromError(const AWSError<CoreErrors>& error) const +{ + return error.GetJsonPayload(); } -const JsonValue& JsonErrorMarshaller::GetJsonPayloadFromError(const AWSError<CoreErrors>& error) const -{ - return error.GetJsonPayload(); -} - AWSError<CoreErrors> XmlErrorMarshaller::Marshall(const Aws::Http::HttpResponse& httpResponse) const { XmlDocument doc = XmlDocument::CreateFromXmlStream(httpResponse.GetResponseBody()); @@ -75,10 +75,10 @@ AWSError<CoreErrors> XmlErrorMarshaller::Marshall(const Aws::Http::HttpResponse& if (doc.WasParseSuccessful() && !doc.GetRootElement().IsNull()) { XmlNode errorNode = doc.GetRootElement(); - - Aws::String requestId(!errorNode.FirstChild("RequestId").IsNull() ? errorNode.FirstChild("RequestId").GetText() : - !errorNode.FirstChild("RequestID").IsNull() ? errorNode.FirstChild("RequestID").GetText() : ""); - + + Aws::String requestId(!errorNode.FirstChild("RequestId").IsNull() ? errorNode.FirstChild("RequestId").GetText() : + !errorNode.FirstChild("RequestID").IsNull() ? errorNode.FirstChild("RequestID").GetText() : ""); + if (errorNode.GetName() != "Error") { errorNode = doc.GetRootElement().FirstChild("Error"); @@ -94,9 +94,9 @@ AWSError<CoreErrors> XmlErrorMarshaller::Marshall(const Aws::Http::HttpResponse& if (!errorNode.IsNull()) { - requestId = !requestId.empty() ? requestId : !errorNode.FirstChild("RequestId").IsNull() ? errorNode.FirstChild("RequestId").GetText() : - !errorNode.FirstChild("RequestID").IsNull() ? errorNode.FirstChild("RequestID").GetText() : ""; - + requestId = !requestId.empty() ? requestId : !errorNode.FirstChild("RequestId").IsNull() ? errorNode.FirstChild("RequestId").GetText() : + !errorNode.FirstChild("RequestID").IsNull() ? errorNode.FirstChild("RequestID").GetText() : ""; + XmlNode codeNode = errorNode.FirstChild("Code"); XmlNode messageNode = errorNode.FirstChild("Message"); @@ -107,8 +107,8 @@ AWSError<CoreErrors> XmlErrorMarshaller::Marshall(const Aws::Http::HttpResponse& errorParsed = true; } } - - error.SetRequestId(requestId); + + error.SetRequestId(requestId); } if(!errorParsed) @@ -120,15 +120,15 @@ AWSError<CoreErrors> XmlErrorMarshaller::Marshall(const Aws::Http::HttpResponse& error = FindErrorByHttpResponseCode(httpResponse.GetResponseCode()); } - error.SetXmlPayload(std::move(doc)); + error.SetXmlPayload(std::move(doc)); return error; } -const XmlDocument& XmlErrorMarshaller::GetXmlPayloadFromError(const AWSError<CoreErrors>& error) const -{ - return error.GetXmlPayload(); -} - +const XmlDocument& XmlErrorMarshaller::GetXmlPayloadFromError(const AWSError<CoreErrors>& error) const +{ + return error.GetXmlPayload(); +} + AWSError<CoreErrors> AWSErrorMarshaller::Marshall(const Aws::String& exceptionName, const Aws::String& message) const { if(exceptionName.empty()) @@ -142,11 +142,11 @@ AWSError<CoreErrors> AWSErrorMarshaller::Marshall(const Aws::String& exceptionNa if (locationOfPound != Aws::String::npos) { - formalExceptionName = exceptionName.substr(locationOfPound + 1); + formalExceptionName = exceptionName.substr(locationOfPound + 1); } else if (locationOfColon != Aws::String::npos) { - formalExceptionName = exceptionName.substr(0, locationOfColon); + formalExceptionName = exceptionName.substr(0, locationOfColon); } else { @@ -161,7 +161,7 @@ AWSError<CoreErrors> AWSErrorMarshaller::Marshall(const Aws::String& exceptionNa error.SetExceptionName(formalExceptionName); error.SetMessage(message); return error; - } + } AWS_LOGSTREAM_WARN(AWS_ERROR_MARSHALLER_LOG_TAG, "Encountered Unknown AWSError '" << exceptionName.c_str() << "': " << message.c_str()); diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AsyncCallerContext.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AsyncCallerContext.cpp index 80e19495df..4f9abdc9e4 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AsyncCallerContext.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/AsyncCallerContext.cpp @@ -1,7 +1,7 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ #include <aws/core/client/AsyncCallerContext.h> #include <aws/core/utils/UUID.h> diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp index 6e2fd8e56d..e517379a77 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp @@ -1,31 +1,31 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ #include <aws/core/client/ClientConfiguration.h> -#include <aws/core/auth/AWSCredentialsProvider.h> +#include <aws/core/auth/AWSCredentialsProvider.h> #include <aws/core/client/DefaultRetryStrategy.h> -#include <aws/core/platform/Environment.h> +#include <aws/core/platform/Environment.h> #include <aws/core/platform/OSVersionInfo.h> #include <aws/core/utils/memory/AWSMemory.h> -#include <aws/core/utils/StringUtils.h> +#include <aws/core/utils/StringUtils.h> #include <aws/core/utils/threading/Executor.h> #include <aws/core/utils/memory/stl/AWSStringStream.h> #include <aws/core/Version.h> -#include <aws/core/config/AWSProfileConfigLoader.h> -#include <aws/core/utils/logging/LogMacros.h> +#include <aws/core/config/AWSProfileConfigLoader.h> +#include <aws/core/utils/logging/LogMacros.h> namespace Aws { -namespace Auth -{ - AWS_CORE_API Aws::String GetConfigProfileFilename(); -} +namespace Auth +{ + AWS_CORE_API Aws::String GetConfigProfileFilename(); +} namespace Client { -static const char* CLIENT_CONFIG_TAG = "ClientConfiguration"; +static const char* CLIENT_CONFIG_TAG = "ClientConfiguration"; AWS_CORE_API Aws::String ComputeUserAgentString() { @@ -35,126 +35,126 @@ AWS_CORE_API Aws::String ComputeUserAgentString() return ss.str(); } -ClientConfiguration::ClientConfiguration() : - scheme(Aws::Http::Scheme::HTTPS), +ClientConfiguration::ClientConfiguration() : + scheme(Aws::Http::Scheme::HTTPS), useDualStack(false), - maxConnections(25), - httpRequestTimeoutMs(0), - requestTimeoutMs(3000), + maxConnections(25), + httpRequestTimeoutMs(0), + requestTimeoutMs(3000), connectTimeoutMs(1000), - enableTcpKeepAlive(true), - tcpKeepAliveIntervalMs(30000), - lowSpeedLimit(1), + enableTcpKeepAlive(true), + tcpKeepAliveIntervalMs(30000), + lowSpeedLimit(1), proxyScheme(Aws::Http::Scheme::HTTP), proxyPort(0), - executor(Aws::MakeShared<Aws::Utils::Threading::DefaultExecutor>(CLIENT_CONFIG_TAG)), + executor(Aws::MakeShared<Aws::Utils::Threading::DefaultExecutor>(CLIENT_CONFIG_TAG)), verifySSL(true), writeRateLimiter(nullptr), readRateLimiter(nullptr), httpLibOverride(Aws::Http::TransferLibType::DEFAULT_CLIENT), - followRedirects(FollowRedirectsPolicy::DEFAULT), + followRedirects(FollowRedirectsPolicy::DEFAULT), disableExpectHeader(false), enableClockSkewAdjustment(true), enableHostPrefixInjection(true), - enableEndpointDiscovery(false), - profileName(Aws::Auth::GetConfigProfileName()) + enableEndpointDiscovery(false), + profileName(Aws::Auth::GetConfigProfileName()) +{ + AWS_LOGSTREAM_DEBUG(CLIENT_CONFIG_TAG, "ClientConfiguration will use SDK Auto Resolved profile: [" << profileName << "] if not specified by users."); + + // Initialize Retry Strategy + int maxAttempts; + Aws::String maxAttemptsString = Aws::Environment::GetEnv("AWS_MAX_ATTEMPTS"); + if (maxAttemptsString.empty()) + { + maxAttemptsString = Aws::Config::GetCachedConfigValue("max_attempts"); + } + // In case users specify 0 explicitly to disable retry. + if (maxAttemptsString == "0") + { + maxAttempts = 0; + } + else + { + maxAttempts = static_cast<int>(Aws::Utils::StringUtils::ConvertToInt32(maxAttemptsString.c_str())); + if (maxAttempts == 0) + { + AWS_LOGSTREAM_WARN(CLIENT_CONFIG_TAG, "Retry Strategy will use the default max attempts."); + maxAttempts = -1; + } + } + + Aws::String retryMode = Aws::Environment::GetEnv("AWS_RETRY_MODE"); + if (retryMode.empty()) + { + retryMode = Aws::Config::GetCachedConfigValue("retry_mode"); + } + if (retryMode == "standard") + { + if (maxAttempts < 0) + { + retryStrategy = Aws::MakeShared<StandardRetryStrategy>(CLIENT_CONFIG_TAG); + } + else + { + retryStrategy = Aws::MakeShared<StandardRetryStrategy>(CLIENT_CONFIG_TAG, maxAttempts); + } + } + else + { + retryStrategy = Aws::MakeShared<DefaultRetryStrategy>(CLIENT_CONFIG_TAG); + } + + // Automatically determine the AWS region from environment variables, configuration file and EC2 metadata. + region = Aws::Environment::GetEnv("AWS_DEFAULT_REGION"); + if (!region.empty()) + { + return; + } + + region = Aws::Environment::GetEnv("AWS_REGION"); + if (!region.empty()) + { + return; + } + + region = Aws::Config::GetCachedConfigValue("region"); + if (!region.empty()) + { + return; + } + + if (Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_EC2_METADATA_DISABLED").c_str()) != "true") + { + auto client = Aws::Internal::GetEC2MetadataClient(); + if (client) + { + region = client->GetCurrentRegion(); + } + } + + if (!region.empty()) + { + return; + } + + region = Aws::String(Aws::Region::US_EAST_1); +} + +ClientConfiguration::ClientConfiguration(const char* profile) : ClientConfiguration() { - AWS_LOGSTREAM_DEBUG(CLIENT_CONFIG_TAG, "ClientConfiguration will use SDK Auto Resolved profile: [" << profileName << "] if not specified by users."); - - // Initialize Retry Strategy - int maxAttempts; - Aws::String maxAttemptsString = Aws::Environment::GetEnv("AWS_MAX_ATTEMPTS"); - if (maxAttemptsString.empty()) - { - maxAttemptsString = Aws::Config::GetCachedConfigValue("max_attempts"); - } - // In case users specify 0 explicitly to disable retry. - if (maxAttemptsString == "0") - { - maxAttempts = 0; - } - else - { - maxAttempts = static_cast<int>(Aws::Utils::StringUtils::ConvertToInt32(maxAttemptsString.c_str())); - if (maxAttempts == 0) - { - AWS_LOGSTREAM_WARN(CLIENT_CONFIG_TAG, "Retry Strategy will use the default max attempts."); - maxAttempts = -1; - } - } - - Aws::String retryMode = Aws::Environment::GetEnv("AWS_RETRY_MODE"); - if (retryMode.empty()) - { - retryMode = Aws::Config::GetCachedConfigValue("retry_mode"); - } - if (retryMode == "standard") - { - if (maxAttempts < 0) - { - retryStrategy = Aws::MakeShared<StandardRetryStrategy>(CLIENT_CONFIG_TAG); - } - else - { - retryStrategy = Aws::MakeShared<StandardRetryStrategy>(CLIENT_CONFIG_TAG, maxAttempts); - } - } - else - { - retryStrategy = Aws::MakeShared<DefaultRetryStrategy>(CLIENT_CONFIG_TAG); - } - - // Automatically determine the AWS region from environment variables, configuration file and EC2 metadata. - region = Aws::Environment::GetEnv("AWS_DEFAULT_REGION"); - if (!region.empty()) - { - return; - } - - region = Aws::Environment::GetEnv("AWS_REGION"); - if (!region.empty()) - { - return; - } - - region = Aws::Config::GetCachedConfigValue("region"); - if (!region.empty()) - { - return; - } - - if (Aws::Utils::StringUtils::ToLower(Aws::Environment::GetEnv("AWS_EC2_METADATA_DISABLED").c_str()) != "true") - { - auto client = Aws::Internal::GetEC2MetadataClient(); - if (client) - { - region = client->GetCurrentRegion(); - } - } - - if (!region.empty()) - { - return; - } - - region = Aws::String(Aws::Region::US_EAST_1); + if (profile && Aws::Config::HasCachedConfigProfile(profile)) + { + this->profileName = Aws::String(profile); + AWS_LOGSTREAM_DEBUG(CLIENT_CONFIG_TAG, "Use user specified profile: [" << this->profileName << "] for ClientConfiguration."); + auto tmpRegion = Aws::Config::GetCachedConfigProfile(this->profileName).GetRegion(); + if (!tmpRegion.empty()) + { + region = tmpRegion; + } + return; + } + AWS_LOGSTREAM_WARN(CLIENT_CONFIG_TAG, "User specified profile: [" << profile << "] is not found, will use the SDK resolved one."); } -ClientConfiguration::ClientConfiguration(const char* profile) : ClientConfiguration() -{ - if (profile && Aws::Config::HasCachedConfigProfile(profile)) - { - this->profileName = Aws::String(profile); - AWS_LOGSTREAM_DEBUG(CLIENT_CONFIG_TAG, "Use user specified profile: [" << this->profileName << "] for ClientConfiguration."); - auto tmpRegion = Aws::Config::GetCachedConfigProfile(this->profileName).GetRegion(); - if (!tmpRegion.empty()) - { - region = tmpRegion; - } - return; - } - AWS_LOGSTREAM_WARN(CLIENT_CONFIG_TAG, "User specified profile: [" << profile << "] is not found, will use the SDK resolved one."); -} - } // namespace Client } // namespace Aws diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp index 03d736bd36..8c2c288dcd 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/CoreErrors.cpp @@ -1,7 +1,7 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ #include <aws/core/client/AWSError.h> #include <aws/core/client/CoreErrors.h> @@ -31,7 +31,7 @@ void CoreErrorsMapper::InitCoreErrorsMapper() return; } s_CoreErrorsMapper = Aws::MakeUnique<Aws::Map<Aws::String, AWSError<CoreErrors> > >("InitCoreErrorsMapper"); - + s_CoreErrorsMapper->emplace("IncompleteSignature", AWSError<CoreErrors>(CoreErrors::INCOMPLETE_SIGNATURE, false)); s_CoreErrorsMapper->emplace("IncompleteSignatureException", AWSError<CoreErrors>(CoreErrors::INCOMPLETE_SIGNATURE, false)); s_CoreErrorsMapper->emplace("InvalidSignatureException", AWSError<CoreErrors>(CoreErrors::INVALID_SIGNATURE, false)); @@ -112,40 +112,40 @@ AWS_CORE_API AWSError<CoreErrors> CoreErrorsMapper::GetErrorForHttpResponseCode( { // best effort attempt to map HTTP response codes to CoreErrors bool retryable = IsRetryableHttpResponseCode(code); - AWSError<CoreErrors> error; - switch (code) + AWSError<CoreErrors> error; + switch (code) { case HttpResponseCode::UNAUTHORIZED: case HttpResponseCode::FORBIDDEN: - error = AWSError<CoreErrors>(CoreErrors::ACCESS_DENIED, retryable); - break; + error = AWSError<CoreErrors>(CoreErrors::ACCESS_DENIED, retryable); + break; case HttpResponseCode::NOT_FOUND: - error = AWSError<CoreErrors>(CoreErrors::RESOURCE_NOT_FOUND, retryable); - break; + error = AWSError<CoreErrors>(CoreErrors::RESOURCE_NOT_FOUND, retryable); + break; case HttpResponseCode::TOO_MANY_REQUESTS: - error = AWSError<CoreErrors>(CoreErrors::SLOW_DOWN, retryable); - break; + error = AWSError<CoreErrors>(CoreErrors::SLOW_DOWN, retryable); + break; case HttpResponseCode::INTERNAL_SERVER_ERROR: - error = AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, retryable); - break; + error = AWSError<CoreErrors>(CoreErrors::INTERNAL_FAILURE, retryable); + break; case HttpResponseCode::BANDWIDTH_LIMIT_EXCEEDED: - error = AWSError<CoreErrors>(CoreErrors::THROTTLING, retryable); - break; + error = AWSError<CoreErrors>(CoreErrors::THROTTLING, retryable); + break; case HttpResponseCode::SERVICE_UNAVAILABLE: - error = AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, retryable); - break; + error = AWSError<CoreErrors>(CoreErrors::SERVICE_UNAVAILABLE, retryable); + break; case HttpResponseCode::REQUEST_TIMEOUT: case HttpResponseCode::AUTHENTICATION_TIMEOUT: case HttpResponseCode::LOGIN_TIMEOUT: case HttpResponseCode::GATEWAY_TIMEOUT: case HttpResponseCode::NETWORK_READ_TIMEOUT: case HttpResponseCode::NETWORK_CONNECT_TIMEOUT: - error = AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, retryable); - break; + error = AWSError<CoreErrors>(CoreErrors::REQUEST_TIMEOUT, retryable); + break; default: int codeValue = static_cast<int>(code); - error = AWSError<CoreErrors>(CoreErrors::UNKNOWN, codeValue >= 500 && codeValue < 600); + error = AWSError<CoreErrors>(CoreErrors::UNKNOWN, codeValue >= 500 && codeValue < 600); } - error.SetResponseCode(code); - return error; + error.SetResponseCode(code); + return error; } diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/DefaultRetryStrategy.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/DefaultRetryStrategy.cpp index 7bda42541d..7e57c79ffc 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/DefaultRetryStrategy.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/DefaultRetryStrategy.cpp @@ -1,7 +1,7 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ #include <aws/core/client/DefaultRetryStrategy.h> diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/RetryStrategy.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/RetryStrategy.cpp index f66070220d..b439b7ca99 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/RetryStrategy.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/RetryStrategy.cpp @@ -1,102 +1,102 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/core/client/RetryStrategy.h> - -#include <aws/core/client/AWSError.h> -#include <aws/core/client/CoreErrors.h> -#include <aws/core/utils/Outcome.h> - -using namespace Aws::Utils::Threading; - -namespace Aws -{ - namespace Client - { - static const int INITIAL_RETRY_TOKENS = 500; - static const int RETRY_COST = 5; - static const int NO_RETRY_INCREMENT = 1; - static const int TIMEOUT_RETRY_COST = 10; - - StandardRetryStrategy::StandardRetryStrategy(long maxAttempts) : - m_retryQuotaContainer(Aws::MakeShared<DefaultRetryQuotaContainer>("StandardRetryStrategy")), - m_maxAttempts(maxAttempts) - {} - - StandardRetryStrategy::StandardRetryStrategy(std::shared_ptr<RetryQuotaContainer> retryQuotaContainer, long maxAttempts) : - m_retryQuotaContainer(retryQuotaContainer), - m_maxAttempts(maxAttempts) - {} - - void StandardRetryStrategy::RequestBookkeeping(const HttpResponseOutcome& httpResponseOutcome) - { - if (httpResponseOutcome.IsSuccess()) - { - m_retryQuotaContainer->ReleaseRetryQuota(NO_RETRY_INCREMENT); - } - } - - void StandardRetryStrategy::RequestBookkeeping(const HttpResponseOutcome& httpResponseOutcome, const AWSError<CoreErrors>& lastError) - { - if (httpResponseOutcome.IsSuccess()) - { - m_retryQuotaContainer->ReleaseRetryQuota(lastError); - } - } - - bool StandardRetryStrategy::ShouldRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const - { - if (!error.ShouldRetry()) - return false; - - if (attemptedRetries + 1 >= m_maxAttempts) - return false; - - return m_retryQuotaContainer->AcquireRetryQuota(error); - } - - long StandardRetryStrategy::CalculateDelayBeforeNextRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const - { - AWS_UNREFERENCED_PARAM(error); - return (std::min)(rand() % 1000 * (1 << attemptedRetries), 20000); - } - - DefaultRetryQuotaContainer::DefaultRetryQuotaContainer() : m_retryQuota(INITIAL_RETRY_TOKENS) - {} - - bool DefaultRetryQuotaContainer::AcquireRetryQuota(int capacityAmount) - { - WriterLockGuard guard(m_retryQuotaLock); - - if (capacityAmount > m_retryQuota) - { - return false; - } - else - { - m_retryQuota -= capacityAmount; - return true; - } - } - - bool DefaultRetryQuotaContainer::AcquireRetryQuota(const AWSError<CoreErrors>& error) - { - int capacityAmount = error.GetErrorType() == CoreErrors::REQUEST_TIMEOUT ? TIMEOUT_RETRY_COST : RETRY_COST; - return AcquireRetryQuota(capacityAmount); - } - - void DefaultRetryQuotaContainer::ReleaseRetryQuota(int capacityAmount) - { - WriterLockGuard guard(m_retryQuotaLock); - m_retryQuota = (std::min)(m_retryQuota + capacityAmount, INITIAL_RETRY_TOKENS); - } - - void DefaultRetryQuotaContainer::ReleaseRetryQuota(const AWSError<CoreErrors>& error) - { - int capacityAmount = error.GetErrorType() == CoreErrors::REQUEST_TIMEOUT ? TIMEOUT_RETRY_COST : RETRY_COST; - ReleaseRetryQuota(capacityAmount); - } - } -}
\ No newline at end of file +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include <aws/core/client/RetryStrategy.h> + +#include <aws/core/client/AWSError.h> +#include <aws/core/client/CoreErrors.h> +#include <aws/core/utils/Outcome.h> + +using namespace Aws::Utils::Threading; + +namespace Aws +{ + namespace Client + { + static const int INITIAL_RETRY_TOKENS = 500; + static const int RETRY_COST = 5; + static const int NO_RETRY_INCREMENT = 1; + static const int TIMEOUT_RETRY_COST = 10; + + StandardRetryStrategy::StandardRetryStrategy(long maxAttempts) : + m_retryQuotaContainer(Aws::MakeShared<DefaultRetryQuotaContainer>("StandardRetryStrategy")), + m_maxAttempts(maxAttempts) + {} + + StandardRetryStrategy::StandardRetryStrategy(std::shared_ptr<RetryQuotaContainer> retryQuotaContainer, long maxAttempts) : + m_retryQuotaContainer(retryQuotaContainer), + m_maxAttempts(maxAttempts) + {} + + void StandardRetryStrategy::RequestBookkeeping(const HttpResponseOutcome& httpResponseOutcome) + { + if (httpResponseOutcome.IsSuccess()) + { + m_retryQuotaContainer->ReleaseRetryQuota(NO_RETRY_INCREMENT); + } + } + + void StandardRetryStrategy::RequestBookkeeping(const HttpResponseOutcome& httpResponseOutcome, const AWSError<CoreErrors>& lastError) + { + if (httpResponseOutcome.IsSuccess()) + { + m_retryQuotaContainer->ReleaseRetryQuota(lastError); + } + } + + bool StandardRetryStrategy::ShouldRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const + { + if (!error.ShouldRetry()) + return false; + + if (attemptedRetries + 1 >= m_maxAttempts) + return false; + + return m_retryQuotaContainer->AcquireRetryQuota(error); + } + + long StandardRetryStrategy::CalculateDelayBeforeNextRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const + { + AWS_UNREFERENCED_PARAM(error); + return (std::min)(rand() % 1000 * (1 << attemptedRetries), 20000); + } + + DefaultRetryQuotaContainer::DefaultRetryQuotaContainer() : m_retryQuota(INITIAL_RETRY_TOKENS) + {} + + bool DefaultRetryQuotaContainer::AcquireRetryQuota(int capacityAmount) + { + WriterLockGuard guard(m_retryQuotaLock); + + if (capacityAmount > m_retryQuota) + { + return false; + } + else + { + m_retryQuota -= capacityAmount; + return true; + } + } + + bool DefaultRetryQuotaContainer::AcquireRetryQuota(const AWSError<CoreErrors>& error) + { + int capacityAmount = error.GetErrorType() == CoreErrors::REQUEST_TIMEOUT ? TIMEOUT_RETRY_COST : RETRY_COST; + return AcquireRetryQuota(capacityAmount); + } + + void DefaultRetryQuotaContainer::ReleaseRetryQuota(int capacityAmount) + { + WriterLockGuard guard(m_retryQuotaLock); + m_retryQuota = (std::min)(m_retryQuota + capacityAmount, INITIAL_RETRY_TOKENS); + } + + void DefaultRetryQuotaContainer::ReleaseRetryQuota(const AWSError<CoreErrors>& error) + { + int capacityAmount = error.GetErrorType() == CoreErrors::REQUEST_TIMEOUT ? TIMEOUT_RETRY_COST : RETRY_COST; + ReleaseRetryQuota(capacityAmount); + } + } +}
\ No newline at end of file diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/SpecifiedRetryableErrorsRetryStrategy.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/SpecifiedRetryableErrorsRetryStrategy.cpp index 007743c322..ec4e373304 100644 --- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/SpecifiedRetryableErrorsRetryStrategy.cpp +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/client/SpecifiedRetryableErrorsRetryStrategy.cpp @@ -1,28 +1,28 @@ -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/core/client/SpecifiedRetryableErrorsRetryStrategy.h> - -#include <aws/core/client/AWSError.h> - -using namespace Aws; -using namespace Aws::Client; - -bool SpecifiedRetryableErrorsRetryStrategy::ShouldRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const -{ - if (attemptedRetries >= m_maxRetries) - { - return false; - } - for (const auto& err: m_specifiedRetryableErrors) - { - if (error.GetExceptionName() == err) - { - return true; - } - } - - return error.ShouldRetry(); -} +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include <aws/core/client/SpecifiedRetryableErrorsRetryStrategy.h> + +#include <aws/core/client/AWSError.h> + +using namespace Aws; +using namespace Aws::Client; + +bool SpecifiedRetryableErrorsRetryStrategy::ShouldRetry(const AWSError<CoreErrors>& error, long attemptedRetries) const +{ + if (attemptedRetries >= m_maxRetries) + { + return false; + } + for (const auto& err: m_specifiedRetryableErrors) + { + if (error.GetExceptionName() == err) + { + return true; + } + } + + return error.ShouldRetry(); +} |