Skip to content

Commit c054379

Browse files
committed
Revert "[C++] SDKs to track feature Ids for Credentials (ENV)(#3516)"
This reverts commit 27bb163.
1 parent 27bb163 commit c054379

File tree

7 files changed

+11
-250
lines changed

7 files changed

+11
-250
lines changed

src/aws-cpp-sdk-core/include/aws/core/auth/AWSCredentials.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,12 @@
66
#pragma once
77

88
#include <aws/core/Core_EXPORTS.h>
9-
#include <aws/core/client/UserAgent.h>
109
#include <aws/core/utils/memory/stl/AWSString.h>
1110
#include <aws/core/utils/DateTime.h>
1211
namespace Aws
1312
{
1413
namespace Auth
1514
{
16-
/**
17-
* Context class for credential resolution that tracks features used during credential retrieval.
18-
*/
19-
class AWS_CORE_API CredentialsResolutionContext
20-
{
21-
public:
22-
// Default constructor - no features tracked
23-
CredentialsResolutionContext() = default;
24-
25-
/**
26-
* Add a user agent feature to track credential usage.
27-
*/
28-
void AddUserAgentFeature(Aws::Client::UserAgentFeature feature)
29-
{
30-
m_features.insert(feature);
31-
}
32-
33-
/**
34-
* Get all tracked credential features.
35-
*/
36-
const Aws::Set<Aws::Client::UserAgentFeature> GetUserAgentFeatures() const
37-
{
38-
return m_features;
39-
}
40-
41-
private:
42-
Aws::Set<Aws::Client::UserAgentFeature> m_features;
43-
};
44-
4515
/**
4616
* Simple data object around aws credentials
4717
*/
@@ -244,24 +214,12 @@ namespace Aws
244214
m_expiration = expiration;
245215
}
246216

247-
/**
248-
* Gets credential resolution context. this is information about the call
249-
* such as what credentials provider was used to to resolve the credentials
250-
*/
251-
inline CredentialsResolutionContext GetContext() { return m_context; }
252-
253-
/**
254-
* Adds a user agent feature used during credentials resolution to the credentials
255-
* context. This is useful to track which credentials provider was used.
256-
*/
257-
inline void AddUserAgentFeature(Aws::Client::UserAgentFeature feature) { m_context.AddUserAgentFeature(feature); }
258217
private:
259218
Aws::String m_accessKeyId;
260219
Aws::String m_secretKey;
261220
Aws::String m_sessionToken;
262221
Aws::Utils::DateTime m_expiration;
263222
Aws::String m_accountId;
264-
CredentialsResolutionContext m_context;
265223
};
266224
}
267225
}

src/aws-cpp-sdk-core/include/aws/core/auth/signer/AWSAuthV4Signer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ namespace Aws
3636
{
3737
class AWSCredentials;
3838
class AWSCredentialsProvider;
39-
class CredentialsResolutionContext;
4039

4140
enum class AWSSigningAlgorithm
4241
{
@@ -192,7 +191,6 @@ namespace Aws
192191

193192
protected:
194193
virtual bool ServiceRequireUnsignedPayload(const Aws::String& serviceName) const;
195-
void UpdateUserAgentWithCredentialFeatures(Aws::Http::HttpRequest& request, const Aws::Auth::CredentialsResolutionContext& context) const;
196194
bool m_includeSha256HashHeader;
197195

198196
private:

src/aws-cpp-sdk-core/include/aws/core/client/UserAgent.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ enum class UserAgentFeature {
3232
ACCOUNT_ID_MODE_REQUIRED,
3333
RESOLVED_ACCOUNT_ID,
3434
GZIP_REQUEST_COMPRESSION,
35-
CREDENTIALS_ENV_VARS,
3635
};
3736

3837
class AWS_CORE_API UserAgent {
3938
public:
40-
static Aws::String BusinessMetricForFeature(UserAgentFeature feature);
4139
explicit UserAgent(const ClientConfiguration& clientConfiguration, const Aws::String& retryStrategyName, const Aws::String& apiName);
4240
Aws::String SerializeWithFeatures(const Aws::Set<UserAgentFeature>& features) const;
4341
void SetApiName(const Aws::String& apiName) { m_api = apiName; }

src/aws-cpp-sdk-core/source/auth/AWSCredentialsProvider.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <aws/core/client/AWSError.h>
1919
#include <aws/core/utils/StringUtils.h>
2020
#include <aws/core/utils/xml/XmlSerializer.h>
21-
#include <aws/core/client/UserAgent.h>
2221
#include <cstdlib>
2322
#include <fstream>
2423
#include <string.h>
@@ -104,10 +103,6 @@ AWSCredentials EnvironmentAWSCredentialsProvider::GetAWSCredentials()
104103
}
105104
}
106105

107-
if (!credentials.IsEmpty()) {
108-
credentials.AddUserAgentFeature(UserAgentFeature::CREDENTIALS_ENV_VARS);
109-
}
110-
111106
return credentials;
112107
}
113108

src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <aws/core/auth/signer/AWSAuthSignerHelper.h>
99

1010
#include <aws/core/auth/AWSCredentialsProvider.h>
11-
#include <aws/core/client/UserAgent.h>
1211
#include <aws/core/http/HttpRequest.h>
1312
#include <aws/core/http/URI.h>
1413
#include <aws/core/utils/DateTime.h>
@@ -26,7 +25,6 @@
2625

2726
#include <iomanip>
2827
#include <cstring>
29-
#include <numeric>
3028

3129
using namespace Aws;
3230
using namespace Aws::Client;
@@ -83,8 +81,6 @@ bool AWSAuthV4Signer::SignRequestWithSigV4a(Aws::Http::HttpRequest& request, con
8381
bool signBody, long long expirationTimeInSeconds, Aws::Crt::Auth::SignatureType signatureType) const
8482
{
8583
AWSCredentials credentials = GetCredentials(request.GetServiceSpecificParameters());
86-
87-
UpdateUserAgentWithCredentialFeatures(request, credentials.GetContext());
8884
auto crtCredentials = Aws::MakeShared<Aws::Crt::Auth::Credentials>(v4AsymmetricLogTag,
8985
Aws::Crt::ByteCursorFromCString(credentials.GetAWSAccessKeyId().c_str()),
9086
Aws::Crt::ByteCursorFromCString(credentials.GetAWSSecretKey().c_str()),
@@ -340,9 +336,6 @@ bool AWSAuthV4Signer::SignRequestWithCreds(Aws::Http::HttpRequest& request, cons
340336
bool AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest& request, const char* region, const char* serviceName, bool signBody) const
341337
{
342338
AWSCredentials credentials = GetCredentials(request.GetServiceSpecificParameters());
343-
344-
UpdateUserAgentWithCredentialFeatures(request, credentials.GetContext());
345-
346339
return SignRequestWithCreds(request, credentials, region, serviceName, signBody);
347340
}
348341

@@ -471,9 +464,6 @@ bool AWSAuthV4Signer::PresignRequest(Aws::Http::HttpRequest& request, const Aws:
471464
bool AWSAuthV4Signer::PresignRequest(Aws::Http::HttpRequest& request, const char* region, const char* serviceName, long long expirationTimeInSeconds) const
472465
{
473466
AWSCredentials credentials = GetCredentials(request.GetServiceSpecificParameters());
474-
475-
UpdateUserAgentWithCredentialFeatures(request, credentials.GetContext());
476-
477467
return PresignRequest(request, credentials, region,serviceName, expirationTimeInSeconds );
478468
}
479469

@@ -605,51 +595,3 @@ Aws::Auth::AWSCredentials AWSAuthV4Signer::GetCredentials(const std::shared_ptr<
605595
AWS_UNREFERENCED_PARAM(serviceSpecificParameters);
606596
return m_credentialsProvider->GetAWSCredentials();
607597
}
608-
609-
void AWSAuthV4Signer::UpdateUserAgentWithCredentialFeatures(Aws::Http::HttpRequest& request, const Aws::Auth::CredentialsResolutionContext& context) const {
610-
if (!request.HasHeader(USER_AGENT)) {
611-
AWS_LOGSTREAM_DEBUG(v4LogTag, "Request does not have User-Agent header, skipping credential feature update");
612-
return;
613-
}
614-
615-
const auto features = context.GetUserAgentFeatures();
616-
if (features.empty()) {
617-
AWS_LOGSTREAM_DEBUG(v4LogTag, "No credential features to add to User-Agent");
618-
return;
619-
}
620-
621-
std::vector<Aws::String> businessMetrics(features.size());
622-
std::transform(features.begin(),
623-
features.end(),
624-
businessMetrics.begin(),
625-
[](UserAgentFeature feature) -> Aws::String { return UserAgent::BusinessMetricForFeature(feature); });
626-
627-
const auto credentialFeatures = std::accumulate(std::next(businessMetrics.begin()),
628-
businessMetrics.end(),
629-
businessMetrics.front(),
630-
[](const Aws::String& a, const Aws::String& b) {
631-
return a + "," + b;
632-
});
633-
634-
const auto userAgent = request.GetHeaderValue(USER_AGENT);
635-
auto userAgentParsed = Aws::Utils::StringUtils::Split(userAgent, ' ');
636-
auto metricsSegment = std::find_if(userAgentParsed.begin(), userAgentParsed.end(),
637-
[](const Aws::String& value) { return value.find("m/") != Aws::String::npos; });
638-
639-
if (metricsSegment != userAgentParsed.end()) {
640-
// Add new metrics to existing metrics section
641-
*metricsSegment = Aws::String{*metricsSegment + "," + credentialFeatures};
642-
} else {
643-
// No metrics section exists, add new one
644-
userAgentParsed.push_back("m/" + credentialFeatures);
645-
}
646-
647-
// Reassemble all parts with spaces
648-
const auto newUserAgent = std::accumulate(std::next(userAgentParsed.begin()),
649-
userAgentParsed.end(),
650-
userAgentParsed.front(),
651-
[](const Aws::String& a, const Aws::String& b) {
652-
return a + " " + b;
653-
});
654-
request.SetUserAgent(newUserAgent);
655-
}

src/aws-cpp-sdk-core/source/client/UserAgent.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,19 @@ const std::pair<UserAgentFeature, const char*> BUSINESS_METRIC_MAPPING[] = {
4242
{UserAgentFeature::ACCOUNT_ID_MODE_REQUIRED, "R"},
4343
{UserAgentFeature::RESOLVED_ACCOUNT_ID, "T"},
4444
{UserAgentFeature::GZIP_REQUEST_COMPRESSION, "L"},
45-
{UserAgentFeature::CREDENTIALS_ENV_VARS, "g"},
4645
};
4746

47+
Aws::String BusinessMetricForFeature(UserAgentFeature feature) {
48+
const auto* const metric =
49+
std::find_if(std::begin(BUSINESS_METRIC_MAPPING), std::end(BUSINESS_METRIC_MAPPING),
50+
[feature](const std::pair<UserAgentFeature, const char*>& pair) -> bool { return pair.first == feature; });
51+
if (metric == std::end(BUSINESS_METRIC_MAPPING)) {
52+
AWS_LOGSTREAM_ERROR(LOG_TAG, "business metric mapping not found for feature");
53+
return {};
54+
}
55+
return metric->second;
56+
}
57+
4858
const std::pair<const char*, UserAgentFeature> RETRY_FEATURE_MAPPING[] = {
4959
{"default", UserAgentFeature::RETRY_MODE_LEGACY},
5060
{"standard", UserAgentFeature::RETRY_MODE_STANDARD},
@@ -86,17 +96,6 @@ const char* APP_ID = "app";
8696
const char* BUSINESS_METRICS = "m";
8797
} // namespace
8898

89-
Aws::String UserAgent::BusinessMetricForFeature(UserAgentFeature feature) {
90-
const auto* const metric =
91-
std::find_if(std::begin(BUSINESS_METRIC_MAPPING), std::end(BUSINESS_METRIC_MAPPING),
92-
[feature](const std::pair<UserAgentFeature, const char*>& pair) -> bool { return pair.first == feature; });
93-
if (metric == std::end(BUSINESS_METRIC_MAPPING)) {
94-
AWS_LOGSTREAM_ERROR(LOG_TAG, "business metric mapping not found for feature");
95-
return {};
96-
}
97-
return metric->second;
98-
}
99-
10099
UserAgent::UserAgent(const ClientConfiguration& clientConfiguration,
101100
const Aws::String& retryStrategyName,
102101
const Aws::String& apiName)

tests/aws-cpp-sdk-core-tests/aws/auth/CredentialTrackingTest.cpp

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)