Coverage Report

Created: 2025-06-17 13:30

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