Coverage Report

Created: 2025-09-10 18:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/util/s3_util.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "util/s3_util.h"
19
20
#include <aws/core/auth/AWSAuthSigner.h>
21
#include <aws/core/auth/AWSCredentials.h>
22
#include <aws/core/auth/AWSCredentialsProviderChain.h>
23
#include <aws/core/client/DefaultRetryStrategy.h>
24
#include <aws/core/utils/logging/LogLevel.h>
25
#include <aws/core/utils/logging/LogSystemInterface.h>
26
#include <aws/core/utils/memory/stl/AWSStringStream.h>
27
#include <aws/identity-management/auth/STSAssumeRoleCredentialsProvider.h>
28
#include <aws/s3/S3Client.h>
29
#include <aws/sts/STSClient.h>
30
#include <bvar/reducer.h>
31
#include <util/string_util.h>
32
33
#include <atomic>
34
#ifdef USE_AZURE
35
#include <azure/core/diagnostics/logger.hpp>
36
#include <azure/storage/blobs/blob_container_client.hpp>
37
#endif
38
#include <cstdlib>
39
#include <filesystem>
40
#include <functional>
41
#include <memory>
42
#include <ostream>
43
#include <utility>
44
45
#include "common/config.h"
46
#include "common/logging.h"
47
#include "common/status.h"
48
#include "cpp/aws_logger.h"
49
#include "cpp/obj_retry_strategy.h"
50
#include "cpp/sync_point.h"
51
#include "cpp/util.h"
52
#ifdef USE_AZURE
53
#include "io/fs/azure_obj_storage_client.h"
54
#endif
55
#include "io/fs/obj_storage_client.h"
56
#include "io/fs/s3_obj_storage_client.h"
57
#include "runtime/exec_env.h"
58
#include "s3_uri.h"
59
#include "vec/exec/scan/scanner_scheduler.h"
60
61
namespace doris {
62
namespace s3_bvar {
63
bvar::LatencyRecorder s3_get_latency("s3_get");
64
bvar::LatencyRecorder s3_put_latency("s3_put");
65
bvar::LatencyRecorder s3_delete_object_latency("s3_delete_object");
66
bvar::LatencyRecorder s3_delete_objects_latency("s3_delete_objects");
67
bvar::LatencyRecorder s3_head_latency("s3_head");
68
bvar::LatencyRecorder s3_multi_part_upload_latency("s3_multi_part_upload");
69
bvar::LatencyRecorder s3_list_latency("s3_list");
70
bvar::LatencyRecorder s3_list_object_versions_latency("s3_list_object_versions");
71
bvar::LatencyRecorder s3_get_bucket_version_latency("s3_get_bucket_version");
72
bvar::LatencyRecorder s3_copy_object_latency("s3_copy_object");
73
}; // namespace s3_bvar
74
75
namespace {
76
77
5
doris::Status is_s3_conf_valid(const S3ClientConf& conf) {
78
5
    if (conf.endpoint.empty()) {
79
0
        return Status::InvalidArgument<false>("Invalid s3 conf, empty endpoint");
80
0
    }
81
5
    if (conf.region.empty()) {
82
0
        return Status::InvalidArgument<false>("Invalid s3 conf, empty region");
83
0
    }
84
85
5
    if (conf.role_arn.empty()) {
86
        // Allow anonymous access when both ak and sk are empty
87
5
        bool hasAk = !conf.ak.empty();
88
5
        bool hasSk = !conf.sk.empty();
89
90
        // Either both credentials are provided or both are empty (anonymous access)
91
5
        if (hasAk && conf.sk.empty()) {
92
0
            return Status::InvalidArgument<false>("Invalid s3 conf, empty sk");
93
0
        }
94
5
        if (hasSk && conf.ak.empty()) {
95
0
            return Status::InvalidArgument<false>("Invalid s3 conf, empty ak");
96
0
        }
97
5
    }
98
5
    return Status::OK();
99
5
}
100
101
// Return true is convert `str` to int successfully
102
0
bool to_int(std::string_view str, int& res) {
103
0
    auto [_, ec] = std::from_chars(str.data(), str.data() + str.size(), res);
104
0
    return ec == std::errc {};
105
0
}
106
107
constexpr char USE_PATH_STYLE[] = "use_path_style";
108
109
constexpr char AZURE_PROVIDER_STRING[] = "AZURE";
110
constexpr char S3_PROVIDER[] = "provider";
111
constexpr char S3_AK[] = "AWS_ACCESS_KEY";
112
constexpr char S3_SK[] = "AWS_SECRET_KEY";
113
constexpr char S3_ENDPOINT[] = "AWS_ENDPOINT";
114
constexpr char S3_REGION[] = "AWS_REGION";
115
constexpr char S3_TOKEN[] = "AWS_TOKEN";
116
constexpr char S3_MAX_CONN_SIZE[] = "AWS_MAX_CONN_SIZE";
117
constexpr char S3_REQUEST_TIMEOUT_MS[] = "AWS_REQUEST_TIMEOUT_MS";
118
constexpr char S3_CONN_TIMEOUT_MS[] = "AWS_CONNECTION_TIMEOUT_MS";
119
constexpr char S3_NEED_OVERRIDE_ENDPOINT[] = "AWS_NEED_OVERRIDE_ENDPOINT";
120
121
constexpr char S3_ROLE_ARN[] = "AWS_ROLE_ARN";
122
constexpr char S3_EXTERNAL_ID[] = "AWS_EXTERNAL_ID";
123
} // namespace
124
125
bvar::Adder<int64_t> get_rate_limit_ns("get_rate_limit_ns");
126
bvar::Adder<int64_t> get_rate_limit_exceed_req_num("get_rate_limit_exceed_req_num");
127
bvar::Adder<int64_t> put_rate_limit_ns("put_rate_limit_ns");
128
bvar::Adder<int64_t> put_rate_limit_exceed_req_num("put_rate_limit_exceed_req_num");
129
130
0
S3RateLimiterHolder* S3ClientFactory::rate_limiter(S3RateLimitType type) {
131
0
    CHECK(type == S3RateLimitType::GET || type == S3RateLimitType::PUT) << to_string(type);
132
0
    return _rate_limiters[static_cast<size_t>(type)].get();
133
0
}
134
135
0
int reset_s3_rate_limiter(S3RateLimitType type, size_t max_speed, size_t max_burst, size_t limit) {
136
0
    if (type == S3RateLimitType::UNKNOWN) {
137
0
        return -1;
138
0
    }
139
0
    return S3ClientFactory::instance().rate_limiter(type)->reset(max_speed, max_burst, limit);
140
0
}
141
142
1
S3ClientFactory::S3ClientFactory() {
143
1
    _aws_options = Aws::SDKOptions {};
144
1
    auto logLevel = static_cast<Aws::Utils::Logging::LogLevel>(config::aws_log_level);
145
1
    _aws_options.loggingOptions.logLevel = logLevel;
146
1
    _aws_options.loggingOptions.logger_create_fn = [logLevel] {
147
1
        return std::make_shared<DorisAWSLogger>(logLevel);
148
1
    };
149
1
    Aws::InitAPI(_aws_options);
150
1
    _ca_cert_file_path = get_valid_ca_cert_path(doris::split(config::ca_cert_file_paths, ";"));
151
1
    _rate_limiters = {
152
1
            std::make_unique<S3RateLimiterHolder>(
153
1
                    config::s3_get_token_per_second, config::s3_get_bucket_tokens,
154
1
                    config::s3_get_token_limit,
155
1
                    metric_func_factory(get_rate_limit_ns, get_rate_limit_exceed_req_num)),
156
1
            std::make_unique<S3RateLimiterHolder>(
157
1
                    config::s3_put_token_per_second, config::s3_put_bucket_tokens,
158
1
                    config::s3_put_token_limit,
159
1
                    metric_func_factory(put_rate_limit_ns, put_rate_limit_exceed_req_num))};
160
161
#ifdef USE_AZURE
162
    auto azureLogLevel =
163
            static_cast<Azure::Core::Diagnostics::Logger::Level>(config::azure_log_level);
164
    Azure::Core::Diagnostics::Logger::SetLevel(azureLogLevel);
165
    Azure::Core::Diagnostics::Logger::SetListener(
166
            [&](Azure::Core::Diagnostics::Logger::Level level, const std::string& message) {
167
                switch (level) {
168
                case Azure::Core::Diagnostics::Logger::Level::Verbose:
169
                    LOG(INFO) << message;
170
                    break;
171
                case Azure::Core::Diagnostics::Logger::Level::Informational:
172
                    LOG(INFO) << message;
173
                    break;
174
                case Azure::Core::Diagnostics::Logger::Level::Warning:
175
                    LOG(WARNING) << message;
176
                    break;
177
                case Azure::Core::Diagnostics::Logger::Level::Error:
178
                    LOG(ERROR) << message;
179
                    break;
180
                default:
181
                    LOG(WARNING) << "Unknown level: " << static_cast<int>(level)
182
                                 << ", message: " << message;
183
                    break;
184
                }
185
            });
186
#endif
187
1
}
188
189
1
S3ClientFactory::~S3ClientFactory() {
190
1
    Aws::ShutdownAPI(_aws_options);
191
1
}
192
193
6
S3ClientFactory& S3ClientFactory::instance() {
194
6
    static S3ClientFactory ret;
195
6
    return ret;
196
6
}
197
198
5
std::shared_ptr<io::ObjStorageClient> S3ClientFactory::create(const S3ClientConf& s3_conf) {
199
5
    if (!is_s3_conf_valid(s3_conf).ok()) {
200
0
        return nullptr;
201
0
    }
202
203
5
    uint64_t hash = s3_conf.get_hash();
204
5
    {
205
5
        std::lock_guard l(_lock);
206
5
        auto it = _cache.find(hash);
207
5
        if (it != _cache.end()) {
208
2
            return it->second;
209
2
        }
210
5
    }
211
212
3
    auto obj_client = (s3_conf.provider == io::ObjStorageType::AZURE)
213
3
                              ? _create_azure_client(s3_conf)
214
3
                              : _create_s3_client(s3_conf);
215
216
3
    {
217
3
        uint64_t hash = s3_conf.get_hash();
218
3
        std::lock_guard l(_lock);
219
3
        _cache[hash] = obj_client;
220
3
    }
221
3
    return obj_client;
222
5
}
223
224
std::shared_ptr<io::ObjStorageClient> S3ClientFactory::_create_azure_client(
225
0
        const S3ClientConf& s3_conf) {
226
#ifdef USE_AZURE
227
    auto cred =
228
            std::make_shared<Azure::Storage::StorageSharedKeyCredential>(s3_conf.ak, s3_conf.sk);
229
230
    const std::string container_name = s3_conf.bucket;
231
    std::string uri;
232
    if (config::force_azure_blob_global_endpoint) {
233
        uri = fmt::format("https://{}.blob.core.windows.net/{}", s3_conf.ak, container_name);
234
    } else {
235
        uri = fmt::format("{}/{}", s3_conf.endpoint, container_name);
236
        if (s3_conf.endpoint.find("://") == std::string::npos) {
237
            uri = "https://" + uri;
238
        }
239
    }
240
241
    Azure::Storage::Blobs::BlobClientOptions options;
242
    options.Retry.StatusCodes.insert(Azure::Core::Http::HttpStatusCode::TooManyRequests);
243
    options.Retry.MaxRetries = config::max_s3_client_retry;
244
    options.PerRetryPolicies.emplace_back(std::make_unique<AzureRetryRecordPolicy>());
245
246
    std::string normalized_uri = normalize_http_uri(uri);
247
    VLOG_DEBUG << "uri:" << uri << ", normalized_uri:" << normalized_uri;
248
249
    auto containerClient = std::make_shared<Azure::Storage::Blobs::BlobContainerClient>(
250
            uri, cred, std::move(options));
251
    LOG_INFO("create one azure client with {}", s3_conf.to_string());
252
    return std::make_shared<io::AzureObjStorageClient>(std::move(containerClient));
253
#else
254
0
    LOG_FATAL("BE is not compiled with azure support, export BUILD_AZURE=ON before building");
255
0
    return nullptr;
256
0
#endif
257
0
}
258
259
std::shared_ptr<Aws::Auth::AWSCredentialsProvider> S3ClientFactory::get_aws_credentials_provider(
260
2
        const S3ClientConf& s3_conf) {
261
2
    if (!s3_conf.ak.empty() && !s3_conf.sk.empty()) {
262
2
        Aws::Auth::AWSCredentials aws_cred(s3_conf.ak, s3_conf.sk);
263
2
        DCHECK(!aws_cred.IsExpiredOrEmpty());
264
2
        if (!s3_conf.token.empty()) {
265
0
            aws_cred.SetSessionToken(s3_conf.token);
266
0
        }
267
2
        return std::make_shared<Aws::Auth::SimpleAWSCredentialsProvider>(std::move(aws_cred));
268
2
    }
269
270
0
    if (s3_conf.cred_provider_type == CredProviderType::InstanceProfile) {
271
0
        if (s3_conf.role_arn.empty()) {
272
0
            return std::make_shared<Aws::Auth::InstanceProfileCredentialsProvider>();
273
0
        }
274
275
0
        Aws::Client::ClientConfiguration clientConfiguration =
276
0
                S3ClientFactory::getClientConfiguration();
277
278
0
        if (_ca_cert_file_path.empty()) {
279
0
            _ca_cert_file_path =
280
0
                    get_valid_ca_cert_path(doris::split(config::ca_cert_file_paths, ";"));
281
0
        }
282
0
        if (!_ca_cert_file_path.empty()) {
283
0
            clientConfiguration.caFile = _ca_cert_file_path;
284
0
        }
285
286
0
        auto stsClient = std::make_shared<Aws::STS::STSClient>(
287
0
                std::make_shared<Aws::Auth::InstanceProfileCredentialsProvider>(),
288
0
                clientConfiguration);
289
290
0
        return std::make_shared<Aws::Auth::STSAssumeRoleCredentialsProvider>(
291
0
                s3_conf.role_arn, Aws::String(), s3_conf.external_id,
292
0
                Aws::Auth::DEFAULT_CREDS_LOAD_FREQ_SECONDS, stsClient);
293
0
    }
294
295
    // Support anonymous access for public datasets when no credentials are provided
296
0
    if (s3_conf.ak.empty() && s3_conf.sk.empty()) {
297
0
        return std::make_shared<Aws::Auth::AnonymousAWSCredentialsProvider>();
298
0
    }
299
300
0
    return std::make_shared<Aws::Auth::DefaultAWSCredentialsProviderChain>();
301
0
}
302
303
std::shared_ptr<io::ObjStorageClient> S3ClientFactory::_create_s3_client(
304
3
        const S3ClientConf& s3_conf) {
305
3
    TEST_SYNC_POINT_RETURN_WITH_VALUE(
306
2
            "s3_client_factory::create",
307
2
            std::make_shared<io::S3ObjStorageClient>(std::make_shared<Aws::S3::S3Client>()));
308
2
    Aws::Client::ClientConfiguration aws_config = S3ClientFactory::getClientConfiguration();
309
2
    if (s3_conf.need_override_endpoint) {
310
2
        aws_config.endpointOverride = s3_conf.endpoint;
311
2
    }
312
2
    aws_config.region = s3_conf.region;
313
314
2
    if (_ca_cert_file_path.empty()) {
315
0
        _ca_cert_file_path = get_valid_ca_cert_path(doris::split(config::ca_cert_file_paths, ";"));
316
0
    }
317
318
2
    if (!_ca_cert_file_path.empty()) {
319
2
        aws_config.caFile = _ca_cert_file_path;
320
2
    }
321
322
2
    if (s3_conf.max_connections > 0) {
323
0
        aws_config.maxConnections = s3_conf.max_connections;
324
2
    } else {
325
        // AWS SDK max concurrent tcp connections for a single http client to use. Default 25.
326
2
        aws_config.maxConnections = std::max(config::doris_scanner_thread_pool_thread_num, 25);
327
2
    }
328
329
2
    aws_config.requestTimeoutMs = 30000;
330
2
    if (s3_conf.request_timeout_ms > 0) {
331
0
        aws_config.requestTimeoutMs = s3_conf.request_timeout_ms;
332
0
    }
333
334
2
    if (s3_conf.connect_timeout_ms > 0) {
335
0
        aws_config.connectTimeoutMs = s3_conf.connect_timeout_ms;
336
0
    }
337
338
2
    if (config::s3_client_http_scheme == "http") {
339
2
        aws_config.scheme = Aws::Http::Scheme::HTTP;
340
2
    }
341
342
2
    aws_config.retryStrategy = std::make_shared<S3CustomRetryStrategy>(
343
2
            config::max_s3_client_retry /*scaleFactor = 25*/);
344
345
2
    std::shared_ptr<Aws::S3::S3Client> new_client = std::make_shared<Aws::S3::S3Client>(
346
2
            get_aws_credentials_provider(s3_conf), std::move(aws_config),
347
2
            Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never,
348
2
            s3_conf.use_virtual_addressing);
349
350
2
    auto obj_client = std::make_shared<io::S3ObjStorageClient>(std::move(new_client));
351
2
    LOG_INFO("create one s3 client with {}", s3_conf.to_string());
352
2
    return obj_client;
353
3
}
354
355
Status S3ClientFactory::convert_properties_to_s3_conf(
356
0
        const std::map<std::string, std::string>& prop, const S3URI& s3_uri, S3Conf* s3_conf) {
357
0
    StringCaseMap<std::string> properties(prop.begin(), prop.end());
358
0
    if (auto it = properties.find(S3_AK); it != properties.end()) {
359
0
        s3_conf->client_conf.ak = it->second;
360
0
    }
361
0
    if (auto it = properties.find(S3_SK); it != properties.end()) {
362
0
        s3_conf->client_conf.sk = it->second;
363
0
    }
364
0
    if (auto it = properties.find(S3_TOKEN); it != properties.end()) {
365
0
        s3_conf->client_conf.token = it->second;
366
0
    }
367
0
    if (auto it = properties.find(S3_ENDPOINT); it != properties.end()) {
368
0
        s3_conf->client_conf.endpoint = it->second;
369
0
    }
370
0
    if (auto it = properties.find(S3_NEED_OVERRIDE_ENDPOINT); it != properties.end()) {
371
0
        s3_conf->client_conf.need_override_endpoint = (it->second == "true");
372
0
    }
373
0
    if (auto it = properties.find(S3_REGION); it != properties.end()) {
374
0
        s3_conf->client_conf.region = it->second;
375
0
    }
376
0
    if (auto it = properties.find(S3_MAX_CONN_SIZE); it != properties.end()) {
377
0
        if (!to_int(it->second, s3_conf->client_conf.max_connections)) {
378
0
            return Status::InvalidArgument("invalid {} value \"{}\"", S3_MAX_CONN_SIZE, it->second);
379
0
        }
380
0
    }
381
0
    if (auto it = properties.find(S3_REQUEST_TIMEOUT_MS); it != properties.end()) {
382
0
        if (!to_int(it->second, s3_conf->client_conf.request_timeout_ms)) {
383
0
            return Status::InvalidArgument("invalid {} value \"{}\"", S3_REQUEST_TIMEOUT_MS,
384
0
                                           it->second);
385
0
        }
386
0
    }
387
0
    if (auto it = properties.find(S3_CONN_TIMEOUT_MS); it != properties.end()) {
388
0
        if (!to_int(it->second, s3_conf->client_conf.connect_timeout_ms)) {
389
0
            return Status::InvalidArgument("invalid {} value \"{}\"", S3_CONN_TIMEOUT_MS,
390
0
                                           it->second);
391
0
        }
392
0
    }
393
0
    if (auto it = properties.find(S3_PROVIDER); it != properties.end()) {
394
        // S3 Provider properties should be case insensitive.
395
0
        if (0 == strcasecmp(it->second.c_str(), AZURE_PROVIDER_STRING)) {
396
0
            s3_conf->client_conf.provider = io::ObjStorageType::AZURE;
397
0
        }
398
0
    }
399
400
0
    if (s3_uri.get_bucket().empty()) {
401
0
        return Status::InvalidArgument("Invalid S3 URI {}, bucket is not specified",
402
0
                                       s3_uri.to_string());
403
0
    }
404
0
    s3_conf->bucket = s3_uri.get_bucket();
405
    // For azure's compatibility
406
0
    s3_conf->client_conf.bucket = s3_uri.get_bucket();
407
0
    s3_conf->prefix = "";
408
409
    // See https://sdk.amazonaws.com/cpp/api/LATEST/class_aws_1_1_s3_1_1_s3_client.html
410
0
    s3_conf->client_conf.use_virtual_addressing = true;
411
0
    if (auto it = properties.find(USE_PATH_STYLE); it != properties.end()) {
412
0
        s3_conf->client_conf.use_virtual_addressing = it->second != "true";
413
0
    }
414
415
0
    if (auto it = properties.find(S3_ROLE_ARN); it != properties.end()) {
416
0
        s3_conf->client_conf.cred_provider_type = CredProviderType::InstanceProfile;
417
0
        s3_conf->client_conf.role_arn = it->second;
418
0
    }
419
420
0
    if (auto it = properties.find(S3_EXTERNAL_ID); it != properties.end()) {
421
0
        s3_conf->client_conf.external_id = it->second;
422
0
    }
423
424
0
    if (auto st = is_s3_conf_valid(s3_conf->client_conf); !st.ok()) {
425
0
        return st;
426
0
    }
427
0
    return Status::OK();
428
0
}
429
430
0
static CredProviderType cred_provider_type_from_thrift(TCredProviderType::type cred_provider_type) {
431
0
    switch (cred_provider_type) {
432
0
    case TCredProviderType::DEFAULT:
433
0
        return CredProviderType::Default;
434
0
    case TCredProviderType::SIMPLE:
435
0
        return CredProviderType::Simple;
436
0
    case TCredProviderType::INSTANCE_PROFILE:
437
0
        return CredProviderType::InstanceProfile;
438
0
    default:
439
0
        __builtin_unreachable();
440
0
        LOG(WARNING) << "Invalid TCredProviderType value: " << cred_provider_type
441
0
                     << ", use default instead.";
442
0
        return CredProviderType::Default;
443
0
    }
444
0
}
445
446
0
S3Conf S3Conf::get_s3_conf(const cloud::ObjectStoreInfoPB& info) {
447
0
    S3Conf ret {
448
0
            .bucket = info.bucket(),
449
0
            .prefix = info.prefix(),
450
0
            .client_conf {
451
0
                    .endpoint = info.endpoint(),
452
0
                    .region = info.region(),
453
0
                    .ak = info.ak(),
454
0
                    .sk = info.sk(),
455
0
                    .token {},
456
0
                    .bucket = info.bucket(),
457
0
                    .provider = io::ObjStorageType::AWS,
458
0
                    .use_virtual_addressing =
459
0
                            info.has_use_path_style() ? !info.use_path_style() : true,
460
461
0
                    .role_arn = info.role_arn(),
462
0
                    .external_id = info.external_id(),
463
0
            },
464
0
            .sse_enabled = info.sse_enabled(),
465
0
    };
466
467
0
    if (info.has_cred_provider_type()) {
468
0
        ret.client_conf.cred_provider_type = cred_provider_type_from_pb(info.cred_provider_type());
469
0
    }
470
471
0
    io::ObjStorageType type = io::ObjStorageType::AWS;
472
0
    switch (info.provider()) {
473
0
    case cloud::ObjectStoreInfoPB_Provider_OSS:
474
0
        type = io::ObjStorageType::OSS;
475
0
        break;
476
0
    case cloud::ObjectStoreInfoPB_Provider_S3:
477
0
        type = io::ObjStorageType::AWS;
478
0
        break;
479
0
    case cloud::ObjectStoreInfoPB_Provider_COS:
480
0
        type = io::ObjStorageType::COS;
481
0
        break;
482
0
    case cloud::ObjectStoreInfoPB_Provider_OBS:
483
0
        type = io::ObjStorageType::OBS;
484
0
        break;
485
0
    case cloud::ObjectStoreInfoPB_Provider_BOS:
486
0
        type = io::ObjStorageType::BOS;
487
0
        break;
488
0
    case cloud::ObjectStoreInfoPB_Provider_GCP:
489
0
        type = io::ObjStorageType::GCP;
490
0
        break;
491
0
    case cloud::ObjectStoreInfoPB_Provider_AZURE:
492
0
        type = io::ObjStorageType::AZURE;
493
0
        break;
494
0
    case cloud::ObjectStoreInfoPB_Provider_TOS:
495
0
        type = io::ObjStorageType::TOS;
496
0
        break;
497
0
    default:
498
0
        __builtin_unreachable();
499
0
        LOG_FATAL("unknown provider type {}, info {}", info.provider(), ret.to_string());
500
0
    }
501
0
    ret.client_conf.provider = type;
502
0
    return ret;
503
0
}
504
505
0
S3Conf S3Conf::get_s3_conf(const TS3StorageParam& param) {
506
0
    S3Conf ret {
507
0
            .bucket = param.bucket,
508
0
            .prefix = param.root_path,
509
0
            .client_conf = {
510
0
                    .endpoint = param.endpoint,
511
0
                    .region = param.region,
512
0
                    .ak = param.ak,
513
0
                    .sk = param.sk,
514
0
                    .token = param.token,
515
0
                    .bucket = param.bucket,
516
0
                    .provider = io::ObjStorageType::AWS,
517
0
                    .max_connections = param.max_conn,
518
0
                    .request_timeout_ms = param.request_timeout_ms,
519
0
                    .connect_timeout_ms = param.conn_timeout_ms,
520
                    // When using cold heat separation in minio, user might use ip address directly,
521
                    // which needs enable use_virtual_addressing to true
522
0
                    .use_virtual_addressing = !param.use_path_style,
523
0
                    .role_arn = param.role_arn,
524
0
                    .external_id = param.external_id,
525
0
            }};
526
527
0
    if (param.__isset.cred_provider_type) {
528
0
        ret.client_conf.cred_provider_type =
529
0
                cred_provider_type_from_thrift(param.cred_provider_type);
530
0
    }
531
532
0
    io::ObjStorageType type = io::ObjStorageType::AWS;
533
0
    switch (param.provider) {
534
0
    case TObjStorageType::UNKNOWN:
535
0
        LOG_INFO("Receive one legal storage resource, set provider type to aws, param detail {}",
536
0
                 ret.to_string());
537
0
        type = io::ObjStorageType::AWS;
538
0
        break;
539
0
    case TObjStorageType::AWS:
540
0
        type = io::ObjStorageType::AWS;
541
0
        break;
542
0
    case TObjStorageType::AZURE:
543
0
        type = io::ObjStorageType::AZURE;
544
0
        break;
545
0
    case TObjStorageType::BOS:
546
0
        type = io::ObjStorageType::BOS;
547
0
        break;
548
0
    case TObjStorageType::COS:
549
0
        type = io::ObjStorageType::COS;
550
0
        break;
551
0
    case TObjStorageType::OBS:
552
0
        type = io::ObjStorageType::OBS;
553
0
        break;
554
0
    case TObjStorageType::OSS:
555
0
        type = io::ObjStorageType::OSS;
556
0
        break;
557
0
    case TObjStorageType::GCP:
558
0
        type = io::ObjStorageType::GCP;
559
0
        break;
560
0
    case TObjStorageType::TOS:
561
0
        type = io::ObjStorageType::TOS;
562
0
        break;
563
0
    default:
564
0
        LOG_FATAL("unknown provider type {}, info {}", param.provider, ret.to_string());
565
0
        __builtin_unreachable();
566
0
    }
567
0
    ret.client_conf.provider = type;
568
0
    return ret;
569
0
}
570
571
13
std::string hide_access_key(const std::string& ak) {
572
13
    std::string key = ak;
573
13
    size_t key_len = key.length();
574
13
    size_t reserved_count;
575
13
    if (key_len > 7) {
576
3
        reserved_count = 6;
577
10
    } else if (key_len > 2) {
578
6
        reserved_count = key_len - 2;
579
6
    } else {
580
4
        reserved_count = 0;
581
4
    }
582
583
13
    size_t x_count = key_len - reserved_count;
584
13
    size_t left_x_count = (x_count + 1) / 2;
585
586
13
    if (left_x_count > 0) {
587
12
        key.replace(0, left_x_count, left_x_count, 'x');
588
12
    }
589
590
13
    if (x_count - left_x_count > 0) {
591
11
        key.replace(key_len - (x_count - left_x_count), x_count - left_x_count,
592
11
                    x_count - left_x_count, 'x');
593
11
    }
594
13
    return key;
595
13
}
596
597
} // end namespace doris