From dc8100456abb1fc09e6cd85cd0ab61c3f28d8ac0 Mon Sep 17 00:00:00 2001 From: Theodore Tsirpanis Date: Wed, 18 Sep 2024 14:26:16 +0300 Subject: [PATCH] Support passing `ClientConfiguration` to `GeneralHTTPCredentialsProvider`. --- .../auth/GeneralHTTPCredentialsProvider.h | 18 +++++++++++++++ .../auth/GeneralHTTPCredentialsProvider.cpp | 22 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/aws-cpp-sdk-core/include/aws/core/auth/GeneralHTTPCredentialsProvider.h b/src/aws-cpp-sdk-core/include/aws/core/auth/GeneralHTTPCredentialsProvider.h index a3c3be4c896..47445d7f8bc 100644 --- a/src/aws-cpp-sdk-core/include/aws/core/auth/GeneralHTTPCredentialsProvider.h +++ b/src/aws-cpp-sdk-core/include/aws/core/auth/GeneralHTTPCredentialsProvider.h @@ -24,6 +24,24 @@ namespace Aws public: using ShouldCreateFunc = std::function; + /** + * Initializes the provider to retrieve credentials from a general http provided endpoint every 5 minutes or before it + * expires. + * @param relativeUri A path appended to the metadata service endpoint. OR + * @param absoluteUri The full URI to resolve to get credentials. + * @param authTokenFilePath A path to a file with optional authorization token passed to the URI via the 'Authorization' HTTP header. + * @param authToken An optional authorization token passed to the URI via the 'Authorization' HTTP header. + * @param refreshRateMs The number of milliseconds after which the credentials will be fetched again. + * @param ShouldCreateFunc + */ + GeneralHTTPCredentialsProvider(const Aws::Client::ClientConfiguration& clientConfig, + const Aws::String& relativeUri, + const Aws::String& absoluteUri, + const Aws::String& authTokenFilePath = "", + const Aws::String& authToken = "", + long refreshRateMs = REFRESH_THRESHOLD, + ShouldCreateFunc shouldCreateFunc = ShouldCreateGeneralHTTPProvider); + /** * Initializes the provider to retrieve credentials from a general http provided endpoint every 5 minutes or before it * expires. diff --git a/src/aws-cpp-sdk-core/source/auth/GeneralHTTPCredentialsProvider.cpp b/src/aws-cpp-sdk-core/source/auth/GeneralHTTPCredentialsProvider.cpp index 601b469ede3..34e758485bd 100644 --- a/src/aws-cpp-sdk-core/source/auth/GeneralHTTPCredentialsProvider.cpp +++ b/src/aws-cpp-sdk-core/source/auth/GeneralHTTPCredentialsProvider.cpp @@ -147,6 +147,28 @@ bool GeneralHTTPCredentialsProvider::ShouldCreateGeneralHTTPProvider(const Aws:: return false; } +GeneralHTTPCredentialsProvider::GeneralHTTPCredentialsProvider(const Aws::Client::ClientConfiguration& clientConfig, + const Aws::String& relativeUri, + const Aws::String& absoluteUri, + const Aws::String& authToken, + const Aws::String& authTokenFilePath, + long refreshRateMs, + ShouldCreateFunc shouldCreateFunc) : + m_authTokenFilePath(authTokenFilePath), + m_loadFrequencyMs(refreshRateMs) +{ + if (shouldCreateFunc(relativeUri, absoluteUri, authToken)) + { + AWS_LOGSTREAM_INFO(GEN_HTTP_LOG_TAG, "Creating GeneralHTTPCredentialsProvider with refresh rate " << refreshRateMs); + if (!relativeUri.empty()) { + m_ecsCredentialsClient = Aws::MakeShared(GEN_HTTP_LOG_TAG, clientConfig, relativeUri.c_str(), AWS_ECS_CONTAINER_HOST, authToken.c_str()); + } + else if (!absoluteUri.empty()) { + m_ecsCredentialsClient = Aws::MakeShared(GEN_HTTP_LOG_TAG, clientConfig, "", absoluteUri.c_str(), authToken.c_str()); + } + } +} + GeneralHTTPCredentialsProvider::GeneralHTTPCredentialsProvider(const Aws::String& relativeUri, const Aws::String& absoluteUri, const Aws::String& authToken,