|
| 1 | +#include <aws/sts/STSClient.h> |
| 2 | +#include <aws/sts/model/GetCallerIdentityRequest.h> |
| 3 | +#include <aws/core/auth/AWSCredentialsProvider.h> |
| 4 | +#include <iostream> |
| 5 | + |
| 6 | +#include "example.h" |
| 7 | + |
| 8 | +bool AwsDoc::STS::getCallerIdentity(const Aws::Client::ClientConfiguration &clientConfig) { |
| 9 | + Aws::STS::STSClient sts(clientConfig); |
| 10 | + const Aws::STS::Model::GetCallerIdentityRequest req; |
| 11 | + |
| 12 | + const Aws::STS::Model::GetCallerIdentityOutcome outcome = sts.GetCallerIdentity(req); |
| 13 | + |
| 14 | + if (!outcome.IsSuccess()) { |
| 15 | + std::cerr << "Error getting caller identity. " << |
| 16 | + outcome.GetError().GetMessage() << std::endl; |
| 17 | + } else { |
| 18 | + std::cout << "Caller identtiy successfully retrieved." << std::endl; |
| 19 | + const Aws::STS::Model::GetCallerIdentityResult result = outcome.GetResult(); |
| 20 | + const Aws::String &arn = result.GetArn(); |
| 21 | + std::cout << "ARN: " << arn << std::endl; |
| 22 | + } |
| 23 | + |
| 24 | + const auto& headers = req.GetHeaders(); |
| 25 | + //const auto it = headers.find(Aws::String("User-Agent")); |
| 26 | + //assert(it != headers.end()); |
| 27 | + //std::cout << "User-Agent: " << std::string(FromAwsString(it->second)) << std::endl; |
| 28 | + //std::cout << "User-Agent: " << it->second << std::endl; |
| 29 | + std::cout << "HEADERS COUNT: " << headers.size() << std::endl; |
| 30 | + for(const auto& elem : headers) { |
| 31 | + std::cout << elem.first << ": " << elem.second << std::endl; |
| 32 | + } |
| 33 | + //std::cout << "User-Agent: " << sts.ComputUserAgentString() << std::endl; |
| 34 | + |
| 35 | + //const auto userAgent = headers.at(Aws::String("User-Agent")); |
| 36 | + //std::cout << "User-Agent: " << userAgent << std::endl; |
| 37 | + |
| 38 | + return outcome.IsSuccess(); |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +int main(int argc, char **argv) |
| 43 | +{ |
| 44 | + Aws::SDKOptions options; |
| 45 | + options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace; |
| 46 | + Aws::InitAPI(options); |
| 47 | + { |
| 48 | + Aws::Client::ClientConfiguration clientConfig; |
| 49 | + // Optional: Set to the AWS Region in which the bucket was created (overrides config file). |
| 50 | + // clientConfig.region = "us-east-1"; |
| 51 | + if (!AwsDoc::STS::getCallerIdentity(clientConfig)) |
| 52 | + { |
| 53 | + return 1; |
| 54 | + } |
| 55 | + } |
| 56 | + Aws::ShutdownAPI(options); |
| 57 | + return 0; |
| 58 | +} |
0 commit comments