Coverage Report

Created: 2025-07-25 20:31

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