25#include "rapidjson/writer.h"
26#include "rapidjson/stringbuffer.h"
33#include "NgapS3Credentials.h"
34#include "DmrppNames.h"
39#define AWS_ACCESS_KEY_ID_KEY "accessKeyId"
40#define AWS_SECRET_ACCESS_KEY_KEY "secretAccessKey"
41#define AWS_SESSION_TOKEN_KEY "sessionToken"
42#define AWS_EXPIRATION_KEY "expiration"
44#define prolog std::string("NgapS3Credentials::").append(__func__).append("() - ")
47const string NgapS3Credentials::AWS_SESSION_TOKEN =
"aws_session_token";
48const string NgapS3Credentials::AWS_TOKEN_EXPIRATION =
"aws_token_expiration";
49const string NgapS3Credentials::BES_CONF_S3_ENDPOINT_KEY =
"NGAP.S3.distribution.endpoint.url";
50const string NgapS3Credentials::BES_CONF_REFRESH_KEY =
"NGAP.S3.refresh.margin";
51const string NgapS3Credentials::BES_CONF_URL_BASE =
"NGAP.s3.url.base";
57 if (needs_refresh()) {
71 string accessKeyId, secretAccessKey, sessionToken, expiration;
73 BESDEBUG(MODULE, prolog <<
"distribution_api_endpoint: " << distribution_api_endpoint << endl);
75 rapidjson::Document d = curl::http_get_as_json(distribution_api_endpoint);
76 BESDEBUG(MODULE, prolog <<
"S3 Credentials:" << endl);
78 rapidjson::Value &val = d[AWS_ACCESS_KEY_ID_KEY];
79 accessKeyId = val.GetString();
80 add(ID_KEY, accessKeyId);
81 BESDEBUG(MODULE, prolog << AWS_ACCESS_KEY_ID_KEY <<
": " << accessKeyId << endl);
83 val = d[AWS_SECRET_ACCESS_KEY_KEY];
84 secretAccessKey = val.GetString();
85 add(KEY_KEY, secretAccessKey);
86 BESDEBUG(MODULE, prolog << AWS_SECRET_ACCESS_KEY_KEY <<
": " << secretAccessKey << endl);
88 val = d[AWS_SESSION_TOKEN_KEY];
89 sessionToken = val.GetString();
90 add(AWS_SESSION_TOKEN, sessionToken);
91 BESDEBUG(MODULE, prolog << AWS_SESSION_TOKEN_KEY <<
": " << sessionToken << endl);
93 val = d[AWS_EXPIRATION_KEY];
94 expiration = val.GetString();
95 add(AWS_TOKEN_EXPIRATION, expiration);
96 BESDEBUG(MODULE, prolog << AWS_EXPIRATION_KEY <<
": " << expiration << endl);
101 strptime(expiration.c_str(),
"%Y-%m-%d %H:%M:%S%z", &tm);
102 d_expiration_time = mktime(&tm);
103 BESDEBUG(MODULE, prolog <<
"expiration(time_t): " << d_expiration_time << endl);
void add(const std::string &key, const std::string &value)
Add the key and value pair.
virtual std::string get(const std::string &key)
std::string get(const std::string &key)
void get_temporary_credentials()
virtual bool is_s3_cred()
Do the URL, ID, Key amd Region items make up an S3 Credential?