Skip to content

Commit

Permalink
[fix](backup) support aws_token for backup/restore (apache#26242)
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdreamblue authored Nov 3, 2023
1 parent 91946dc commit 03ab822
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions be/src/util/s3_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ std::shared_ptr<Aws::S3::S3Client> S3ClientFactory::create(const S3Conf& s3_conf

Aws::Auth::AWSCredentials aws_cred(s3_conf.ak, s3_conf.sk);
DCHECK(!aws_cred.IsExpiredOrEmpty());
if (!s3_conf.token.empty()) {
aws_cred.SetSessionToken(s3_conf.token);
}

Aws::Client::ClientConfiguration aws_config = S3ClientFactory::getClientConfiguration();
aws_config.endpointOverride = s3_conf.endpoint;
Expand Down Expand Up @@ -189,6 +192,9 @@ Status S3ClientFactory::convert_properties_to_s3_conf(
StringCaseMap<std::string> properties(prop.begin(), prop.end());
s3_conf->ak = properties.find(S3_AK)->second;
s3_conf->sk = properties.find(S3_SK)->second;
if (properties.find(S3_TOKEN) != properties.end()) {
s3_conf->token = properties.find(S3_TOKEN)->second;
}
s3_conf->endpoint = properties.find(S3_ENDPOINT)->second;
s3_conf->region = properties.find(S3_REGION)->second;

Expand Down
9 changes: 6 additions & 3 deletions be/src/util/s3_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const static std::string S3_CONN_TIMEOUT_MS = "AWS_CONNECTION_TIMEOUT_MS";
struct S3Conf {
std::string ak;
std::string sk;
std::string token;
std::string endpoint;
std::string region;
std::string bucket;
Expand All @@ -80,16 +81,18 @@ struct S3Conf {

std::string to_string() const {
return fmt::format(
"(ak={}, sk=*, endpoint={}, region={}, bucket={}, prefix={}, max_connections={}, "
"request_timeout_ms={}, connect_timeout_ms={}, use_virtual_addressing={})",
ak, endpoint, region, bucket, prefix, max_connections, request_timeout_ms,
"(ak={}, sk=*, token={}, endpoint={}, region={}, bucket={}, prefix={}, "
"max_connections={}, request_timeout_ms={}, connect_timeout_ms={}, "
"use_virtual_addressing={})",
ak, token, endpoint, region, bucket, prefix, max_connections, request_timeout_ms,
connect_timeout_ms, use_virtual_addressing);
}

uint64_t get_hash() const {
uint64_t hash_code = 0;
hash_code += Fingerprint(ak);
hash_code += Fingerprint(sk);
hash_code += Fingerprint(token);
hash_code += Fingerprint(endpoint);
hash_code += Fingerprint(region);
hash_code += Fingerprint(bucket);
Expand Down

0 comments on commit 03ab822

Please sign in to comment.