aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp
diff options
context:
space:
mode:
authornalpp <nalpp@yandex-team.ru>2022-02-10 16:46:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:46 +0300
commit30d1ef3941e0dc835be7609de5ebee66958f215a (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp
parent87f3eb38999df2d3c1cb77f8ffb9c52ec9c516fb (diff)
downloadydb-30d1ef3941e0dc835be7609de5ebee66958f215a.tar.gz
Restoring authorship annotation for <nalpp@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp')
-rw-r--r--contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp140
1 files changed, 70 insertions, 70 deletions
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp
index b69c7f5b5d..24145e4d92 100644
--- a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp
+++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp
@@ -2,30 +2,30 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
-
-#include <aws/core/internal/AWSHttpResourceClient.h>
-#include <aws/core/client/DefaultRetryStrategy.h>
-#include <aws/core/http/HttpClient.h>
-#include <aws/core/http/HttpClientFactory.h>
-#include <aws/core/http/HttpResponse.h>
-#include <aws/core/utils/logging/LogMacros.h>
-#include <aws/core/utils/StringUtils.h>
+
+#include <aws/core/internal/AWSHttpResourceClient.h>
+#include <aws/core/client/DefaultRetryStrategy.h>
+#include <aws/core/http/HttpClient.h>
+#include <aws/core/http/HttpClientFactory.h>
+#include <aws/core/http/HttpResponse.h>
+#include <aws/core/utils/logging/LogMacros.h>
+#include <aws/core/utils/StringUtils.h>
#include <aws/core/utils/HashingUtils.h>
-#include <aws/core/platform/Environment.h>
-#include <aws/core/client/AWSError.h>
-#include <aws/core/client/CoreErrors.h>
+#include <aws/core/platform/Environment.h>
+#include <aws/core/client/AWSError.h>
+#include <aws/core/client/CoreErrors.h>
#include <aws/core/utils/xml/XmlSerializer.h>
#include <mutex>
-#include <sstream>
-
+#include <sstream>
+
using namespace Aws;
-using namespace Aws::Utils;
-using namespace Aws::Utils::Logging;
+using namespace Aws::Utils;
+using namespace Aws::Utils::Logging;
using namespace Aws::Utils::Xml;
-using namespace Aws::Http;
-using namespace Aws::Client;
-using namespace Aws::Internal;
-
+using namespace Aws::Http;
+using namespace Aws::Client;
+using namespace Aws::Internal;
+
static const char EC2_SECURITY_CREDENTIALS_RESOURCE[] = "/latest/meta-data/iam/security-credentials";
static const char EC2_REGION_RESOURCE[] = "/latest/meta-data/placement/availability-zone";
static const char EC2_IMDS_TOKEN_RESOURCE[] = "/latest/api/token";
@@ -35,7 +35,7 @@ static const char EC2_IMDS_TOKEN_HEADER[] = "x-aws-ec2-metadata-token";
static const char RESOURCE_CLIENT_CONFIGURATION_ALLOCATION_TAG[] = "AWSHttpResourceClient";
static const char EC2_METADATA_CLIENT_LOG_TAG[] = "EC2MetadataClient";
static const char ECS_CREDENTIALS_CLIENT_LOG_TAG[] = "ECSCredentialsClient";
-
+
namespace Aws
{
namespace Client
@@ -48,10 +48,10 @@ namespace Aws
static ClientConfiguration MakeDefaultHttpResourceClientConfiguration(const char *logtag)
{
ClientConfiguration res;
-
+
res.maxConnections = 2;
res.scheme = Scheme::HTTP;
-
+
#if defined(WIN32) && defined(BYPASS_DEFAULT_PROXY)
// For security reasons, we must bypass any proxy settings when fetching sensitive information, for example
// user credentials. On Windows, IXMLHttpRequest2 does not support bypassing proxy settings, therefore,
@@ -67,16 +67,16 @@ namespace Aws
res.proxyUserName = "";
res.proxyPassword = "";
res.proxyPort = 0;
-
+
// EC2MetadataService throttles by delaying the response so the service client should set a large read timeout.
// EC2MetadataService delay is in order of seconds so it only make sense to retry after a couple of seconds.
res.connectTimeoutMs = 1000;
res.requestTimeoutMs = 1000;
res.retryStrategy = Aws::MakeShared<DefaultRetryStrategy>(RESOURCE_CLIENT_CONFIGURATION_ALLOCATION_TAG, 1, 1000);
-
+
return res;
}
-
+
AWSHttpResourceClient::AWSHttpResourceClient(const Aws::Client::ClientConfiguration& clientConfiguration, const char* logtag)
: m_logtag(logtag), m_retryStrategy(clientConfiguration.retryStrategy), m_httpClient(nullptr)
{
@@ -85,24 +85,24 @@ namespace Aws
<< clientConfiguration.maxConnections
<< " and scheme "
<< SchemeMapper::ToString(clientConfiguration.scheme));
-
+
m_httpClient = CreateHttpClient(clientConfiguration);
}
-
+
AWSHttpResourceClient::AWSHttpResourceClient(const char* logtag)
: AWSHttpResourceClient(MakeDefaultHttpResourceClientConfiguration(logtag), logtag)
{
}
-
+
AWSHttpResourceClient::~AWSHttpResourceClient()
{
}
-
+
Aws::String AWSHttpResourceClient::GetResource(const char* endpoint, const char* resource, const char* authToken) const
{
return GetResourceWithAWSWebServiceResult(endpoint, resource, authToken).GetPayload();
}
-
+
AmazonWebServiceResult<Aws::String> AWSHttpResourceClient::GetResourceWithAWSWebServiceResult(const char *endpoint, const char *resource, const char *authToken) const
{
Aws::StringStream ss;
@@ -113,7 +113,7 @@ namespace Aws
}
std::shared_ptr<HttpRequest> request(CreateHttpRequest(ss.str(), HttpMethod::HTTP_GET,
Aws::Utils::Stream::DefaultResponseStreamFactoryMethod));
-
+
request->SetUserAgent(ComputeUserAgentString());
if (authToken)
@@ -125,7 +125,7 @@ namespace Aws
}
AmazonWebServiceResult<Aws::String> AWSHttpResourceClient::GetResourceWithAWSWebServiceResult(const std::shared_ptr<HttpRequest> &httpRequest) const
- {
+ {
AWS_LOGSTREAM_TRACE(m_logtag.c_str(), "Retrieving credentials from " << httpRequest->GetURIString());
for (long retries = 0;; retries++)
@@ -167,18 +167,18 @@ namespace Aws
AWS_LOGSTREAM_WARN(m_logtag.c_str(), "Request failed, now waiting " << sleepMillis << " ms before attempting again.");
m_httpClient->RetryRequestSleep(std::chrono::milliseconds(sleepMillis));
}
- }
-
+ }
+
EC2MetadataClient::EC2MetadataClient(const char* endpoint)
: AWSHttpResourceClient(EC2_METADATA_CLIENT_LOG_TAG), m_endpoint(endpoint), m_tokenRequired(true)
{
}
-
+
EC2MetadataClient::EC2MetadataClient(const Aws::Client::ClientConfiguration &clientConfiguration, const char *endpoint)
: AWSHttpResourceClient(clientConfiguration, EC2_METADATA_CLIENT_LOG_TAG), m_endpoint(endpoint), m_tokenRequired(true)
- {
- }
-
+ {
+ }
+
EC2MetadataClient::~EC2MetadataClient()
{
@@ -193,9 +193,9 @@ namespace Aws
{
std::unique_lock<std::recursive_mutex> locker(m_tokenMutex);
if (m_tokenRequired)
- {
+ {
return GetDefaultCredentialsSecurely();
- }
+ }
AWS_LOGSTREAM_TRACE(m_logtag.c_str(), "Getting default credentials for ec2 instance");
auto result = GetResourceWithAWSWebServiceResult(m_endpoint.c_str(), EC2_SECURITY_CREDENTIALS_RESOURCE, nullptr);
@@ -206,12 +206,12 @@ namespace Aws
// then when we fall back to insecure call, it might return 401 ask for secure call,
// Then, SDK might get into a recursive loop call situation between secure and insecure call.
if (httpResponseCode == Http::HttpResponseCode::UNAUTHORIZED)
- {
+ {
m_tokenRequired = true;
return {};
}
locker.unlock();
-
+
Aws::String trimmedCredentialsString = StringUtils::Trim(credentialsString.c_str());
if (trimmedCredentialsString.empty()) return {};
@@ -224,8 +224,8 @@ namespace Aws
{
AWS_LOGSTREAM_WARN(m_logtag.c_str(), "Initial call to ec2Metadataservice to get credentials failed");
return {};
- }
-
+ }
+
Aws::StringStream ss;
ss << EC2_SECURITY_CREDENTIALS_RESOURCE << "/" << securityCredentials[0];
AWS_LOGSTREAM_DEBUG(m_logtag.c_str(), "Calling EC2MetadataService resource " << ss.str());
@@ -233,7 +233,7 @@ namespace Aws
}
Aws::String EC2MetadataClient::GetDefaultCredentialsSecurely() const
- {
+ {
std::unique_lock<std::recursive_mutex> locker(m_tokenMutex);
if (!m_tokenRequired)
{
@@ -291,17 +291,17 @@ namespace Aws
credentialsRequest->SetUserAgent(userAgentString);
AWS_LOGSTREAM_DEBUG(m_logtag.c_str(), "Calling EC2MetadataService resource " << ss.str() << " with token.");
return GetResourceWithAWSWebServiceResult(credentialsRequest).GetPayload();
- }
-
+ }
+
Aws::String EC2MetadataClient::GetCurrentRegion() const
{
if (!m_region.empty())
{
return m_region;
}
-
+
AWS_LOGSTREAM_TRACE(m_logtag.c_str(), "Getting current region for ec2 instance");
-
+
Aws::StringStream ss;
ss << m_endpoint << EC2_REGION_RESOURCE;
std::shared_ptr<HttpRequest> regionRequest(CreateHttpRequest(ss.str(), HttpMethod::HTTP_GET,
@@ -315,21 +315,21 @@ namespace Aws
}
regionRequest->SetUserAgent(ComputeUserAgentString());
Aws::String azString = GetResourceWithAWSWebServiceResult(regionRequest).GetPayload();
-
+
if (azString.empty())
{
AWS_LOGSTREAM_INFO(m_logtag.c_str() ,
"Unable to pull region from instance metadata service ");
return {};
}
-
+
Aws::String trimmedAZString = StringUtils::Trim(azString.c_str());
AWS_LOGSTREAM_DEBUG(m_logtag.c_str(), "Calling EC2MetadataService resource "
<< EC2_REGION_RESOURCE << " , returned credential string " << trimmedAZString);
-
+
Aws::String region;
region.reserve(trimmedAZString.length());
-
+
bool digitFound = false;
for (auto character : trimmedAZString)
{
@@ -341,15 +341,15 @@ namespace Aws
{
digitFound = true;
}
-
+
region.append(1, character);
}
-
+
AWS_LOGSTREAM_INFO(m_logtag.c_str(), "Detected current region as " << region);
m_region = region;
return region;
}
-
+
#ifdef _MSC_VER
// VS2015 compiler's bug, warning s_ec2metadataClient: symbol will be dynamically initialized (implementation limitation)
AWS_SUPPRESS_WARNING(4592,
@@ -358,7 +358,7 @@ namespace Aws
#else
static std::shared_ptr<EC2MetadataClient> s_ec2metadataClient(nullptr);
#endif
-
+
void InitEC2MetadataClient()
{
if (s_ec2metadataClient)
@@ -367,7 +367,7 @@ namespace Aws
}
s_ec2metadataClient = Aws::MakeShared<EC2MetadataClient>(EC2_METADATA_CLIENT_LOG_TAG);
}
-
+
void CleanupEC2MetadataClient()
{
if (!s_ec2metadataClient)
@@ -376,31 +376,31 @@ namespace Aws
}
s_ec2metadataClient = nullptr;
}
-
+
std::shared_ptr<EC2MetadataClient> GetEC2MetadataClient()
{
return s_ec2metadataClient;
}
-
-
+
+
ECSCredentialsClient::ECSCredentialsClient(const char* resourcePath, const char* endpoint, const char* token)
: AWSHttpResourceClient(ECS_CREDENTIALS_CLIENT_LOG_TAG),
m_resourcePath(resourcePath), m_endpoint(endpoint), m_token(token)
- {
- }
+ {
+ }
ECSCredentialsClient::ECSCredentialsClient(const Aws::Client::ClientConfiguration& clientConfiguration, const char* resourcePath, const char* endpoint, const char* token)
: AWSHttpResourceClient(clientConfiguration, ECS_CREDENTIALS_CLIENT_LOG_TAG),
m_resourcePath(resourcePath), m_endpoint(endpoint), m_token(token)
- {
- }
-
+ {
+ }
+
static const char STS_RESOURCE_CLIENT_LOG_TAG[] = "STSResourceClient";
STSCredentialsClient::STSCredentialsClient(const Aws::Client::ClientConfiguration& clientConfiguration)
: AWSHttpResourceClient(clientConfiguration, STS_RESOURCE_CLIENT_LOG_TAG)
{
SetErrorMarshaller(Aws::MakeUnique<Aws::Client::XmlErrorMarshaller>(STS_RESOURCE_CLIENT_LOG_TAG));
-
+
Aws::StringStream ss;
if (clientConfiguration.scheme == Aws::Http::Scheme::HTTP)
{
@@ -410,11 +410,11 @@ namespace Aws
{
ss << "https://";
}
-
+
static const int CN_NORTH_1_HASH = Aws::Utils::HashingUtils::HashString(Aws::Region::CN_NORTH_1);
static const int CN_NORTHWEST_1_HASH = Aws::Utils::HashingUtils::HashString(Aws::Region::CN_NORTHWEST_1);
auto hash = Aws::Utils::HashingUtils::HashString(clientConfiguration.region.c_str());
-
+
ss << "sts." << clientConfiguration.region << ".amazonaws.com";
if (hash == CN_NORTH_1_HASH || hash == CN_NORTHWEST_1_HASH)
{
@@ -503,4 +503,4 @@ namespace Aws
return result;
}
}
-}
+}