|
40 | 40 | #include <aws/access-management/AccessManagementClient.h>
|
41 | 41 | #include <aws/iam/IAMClient.h>
|
42 | 42 | #include <aws/cognito-identity/CognitoIdentityClient.h>
|
| 43 | +#include <aws/sts/STSClient.h> |
| 44 | +#include <aws/sts/model/AssumeRoleRequest.h> |
43 | 45 |
|
44 | 46 | using namespace Aws;
|
45 | 47 | using namespace Aws::Http;
|
@@ -80,7 +82,7 @@ namespace
|
80 | 82 | config.connectTimeoutMs = 30000;
|
81 | 83 | config.requestTimeoutMs = 30000;
|
82 | 84 | m_client = S3ControlClient(config);
|
83 |
| - m_s3Client = S3::S3Client(config); |
| 85 | + m_s3Client = createS3Client(config); |
84 | 86 | m_httpClient = Aws::Http::CreateHttpClient(config);
|
85 | 87 |
|
86 | 88 | // IAM client has to use us-east-1 in its signer.
|
@@ -119,6 +121,24 @@ namespace
|
119 | 121 | return resourceUUID;
|
120 | 122 | }
|
121 | 123 |
|
| 124 | + static S3::S3Client createS3Client(const ClientConfiguration &configuration) { |
| 125 | + Aws::String testRoleArn(Aws::Environment::GetEnv("TEST_ASSUME_ROLE_ARN")); |
| 126 | + if (!testRoleArn.empty()) { |
| 127 | + STS::STSClient stsClient(configuration); |
| 128 | + STS::Model::AssumeRoleRequest assumeRoleRequest; |
| 129 | + assumeRoleRequest.SetRoleArn(testRoleArn); |
| 130 | + assumeRoleRequest.SetRoleSessionName("s3-control-cpp-integ-test"); |
| 131 | + STS::Model::AssumeRoleOutcome outcome = stsClient.AssumeRole(assumeRoleRequest); |
| 132 | + STS::Model::Credentials creds = outcome.GetResult().GetCredentials(); |
| 133 | + Auth::AWSCredentials awsCredentials(creds.GetAccessKeyId(), |
| 134 | + creds.GetSecretAccessKey(), |
| 135 | + creds.GetSessionToken(), |
| 136 | + creds.GetExpiration()); |
| 137 | + return {awsCredentials, configuration}; |
| 138 | + } |
| 139 | + return {configuration}; |
| 140 | + } |
| 141 | + |
122 | 142 | static bool WaitForBucketToPropagate(const Aws::String& bucketName, const S3::S3Client& client)
|
123 | 143 | {
|
124 | 144 | unsigned timeoutCount = 0;
|
@@ -217,7 +237,7 @@ namespace
|
217 | 237 |
|
218 | 238 | Aws::Client::ClientConfiguration config;
|
219 | 239 | config.region = region;
|
220 |
| - Aws::S3::S3Client s3Client(config); |
| 240 | + Aws::S3::S3Client s3Client = createS3Client(config); |
221 | 241 |
|
222 | 242 | S3::Model::CreateBucketRequest createBucketRequest;
|
223 | 243 | S3::Model::CreateBucketConfiguration bucketConfiguration;
|
@@ -288,7 +308,7 @@ namespace
|
288 | 308 | {
|
289 | 309 | Aws::Client::ClientConfiguration config;
|
290 | 310 | config.region = region;
|
291 |
| - Aws::S3::S3Client s3Client(config); |
| 311 | + Aws::S3::S3Client s3Client = createS3Client(config); |
292 | 312 |
|
293 | 313 | Aws::String regionalBucket = bucketName + "-" + region;
|
294 | 314 | S3::Model::DeleteBucketRequest deleteBucketRequest;
|
@@ -691,7 +711,7 @@ namespace
|
691 | 711 |
|
692 | 712 | Aws::Client::ClientConfiguration config;
|
693 | 713 | config.region = Aws::Region::US_WEST_2;
|
694 |
| - Aws::S3::S3Client s3Client(config); |
| 714 | + Aws::S3::S3Client s3Client = createS3Client(config); |
695 | 715 |
|
696 | 716 | Aws::Vector<Aws::String> objectKeys;
|
697 | 717 | objectKeys.push_back(TEST_OBJECT_KEY);
|
|
0 commit comments