|
7 | 7 | #include <aws/core/auth/signer/AWSAuthSignerCommon.h> |
8 | 8 | #include <aws/core/auth/signer/AWSAuthSignerHelper.h> |
9 | 9 |
|
| 10 | +#include <aws/core/AmazonWebServiceRequest.h> |
10 | 11 | #include <aws/core/auth/AWSCredentialsProvider.h> |
| 12 | +#include <aws/core/client/UserAgent.h> |
11 | 13 | #include <aws/core/http/HttpRequest.h> |
12 | 14 | #include <aws/core/http/URI.h> |
13 | 15 | #include <aws/core/utils/DateTime.h> |
@@ -342,6 +344,10 @@ bool AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest& request, const char* r |
342 | 344 | bool AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest& request, Aws::AmazonWebServiceRequest& awsRequest, const char* region, const char* serviceName, bool signBody) const |
343 | 345 | { |
344 | 346 | AWSCredentials credentials = GetCredentials(awsRequest, request.GetServiceSpecificParameters()); |
| 347 | + |
| 348 | + // Update User-Agent with credential tracking features added during credential resolution |
| 349 | + UpdateUserAgentWithCredentialFeatures(request, awsRequest); |
| 350 | + |
345 | 351 | return SignRequestWithCreds(request, credentials, region, serviceName, signBody); |
346 | 352 | } |
347 | 353 |
|
@@ -606,3 +612,48 @@ Aws::Auth::AWSCredentials AWSAuthV4Signer::GetCredentials(Aws::AmazonWebServiceR |
606 | 612 | AWS_UNREFERENCED_PARAM(serviceSpecificParameters); |
607 | 613 | return m_credentialsProvider->GetAWSCredentials(awsRequest); |
608 | 614 | } |
| 615 | + |
| 616 | +void AWSAuthV4Signer::UpdateUserAgentWithCredentialFeatures(Aws::Http::HttpRequest& request, const Aws::AmazonWebServiceRequest& awsRequest) const { |
| 617 | + if (request.HasHeader(USER_AGENT)) { |
| 618 | + auto existingUA = request.GetHeaderValue(USER_AGENT); |
| 619 | + auto features = awsRequest.GetUserAgentFeatures(); |
| 620 | + |
| 621 | + if (!features.empty()) { |
| 622 | + // Build business metrics string from features |
| 623 | + Aws::String businessMetrics = "m/"; |
| 624 | + bool first = true; |
| 625 | + for (const auto& feature : features) { |
| 626 | + if (!first) businessMetrics += ","; |
| 627 | + first = false; |
| 628 | + |
| 629 | + // Map features to their character codes |
| 630 | + switch (feature) { |
| 631 | + case Aws::Client::UserAgentFeature::CREDENTIALS_ENV_VARS: |
| 632 | + businessMetrics += "g"; |
| 633 | + break; |
| 634 | + // Add other feature mappings as needed |
| 635 | + default: |
| 636 | + // Skip unknown features |
| 637 | + break; |
| 638 | + } |
| 639 | + } |
| 640 | + |
| 641 | + // Parse existing User-Agent and replace business metrics section |
| 642 | + auto parts = Aws::Utils::StringUtils::Split(existingUA, ' '); |
| 643 | + for (auto& part : parts) { |
| 644 | + if (part.find("m/") == 0) { |
| 645 | + part = businessMetrics; |
| 646 | + break; |
| 647 | + } |
| 648 | + } |
| 649 | + |
| 650 | + // Rejoin and update |
| 651 | + Aws::String updatedUA; |
| 652 | + for (size_t i = 0; i < parts.size(); ++i) { |
| 653 | + if (i > 0) updatedUA += " "; |
| 654 | + updatedUA += parts[i]; |
| 655 | + } |
| 656 | + request.SetUserAgent(updatedUA); |
| 657 | + } |
| 658 | + } |
| 659 | +} |
0 commit comments