Coverage Report

Created: 2026-10-27 08:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/s3_util.h
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
#pragma once
19
20
#include <aws/core/Aws.h>
21
#include <aws/core/client/ClientConfiguration.h>
22
#include <aws/s3/S3Errors.h>
23
#include <bvar/bvar.h>
24
#include <fmt/format.h>
25
#include <gen_cpp/AgentService_types.h>
26
#include <gen_cpp/cloud.pb.h>
27
#ifdef BE_TEST
28
#include <gtest/gtest_prod.h>
29
#endif
30
31
#include <functional>
32
#include <map>
33
#include <memory>
34
#include <mutex>
35
#include <string>
36
#include <unordered_map>
37
38
#include "common/status.h"
39
#include "core/string_ref.h"
40
#include "cpp/aws_common.h"
41
#include "cpp/obj-client/auth/aws_credential_factory.h"
42
#include "cpp/obj-client/auth/obj_credential.h"
43
#include "cpp/obj-client/obj_storage_client.h"
44
45
namespace Aws::S3 {
46
class S3Client;
47
} // namespace Aws::S3
48
49
namespace bvar {
50
template <typename T>
51
class Adder;
52
}
53
54
namespace doris::io {
55
struct S3AuthConfig;
56
} // namespace doris::io
57
58
namespace doris {
59
60
std::string hide_access_key(const std::string& ak);
61
62
// Owns the AWS SDK lifetime and the AWS helpers shared by object storage clients and other AWS
63
// users (e.g. Kinesis). Object storage clients themselves come from io::ObjClientFactory.
64
class AwsSdkManager {
65
public:
66
    ~AwsSdkManager();
67
68
    static AwsSdkManager& instance();
69
70
88
    static Aws::Client::ClientConfiguration& getClientConfiguration() {
71
        // The default constructor of ClientConfiguration will do some http call
72
        // such as Aws::Internal::GetEC2MetadataClient and other init operation,
73
        // which is unnecessary.
74
        // So here we use a static instance, and deep copy every time
75
        // to avoid unnecessary operations.
76
88
        static Aws::Client::ClientConfiguration instance;
77
88
        instance.requestTimeoutMs = config::aws_client_request_timeout_ms;
78
88
        return instance;
79
88
    }
80
81
    AwsCredentialResult create_aws_credentials_provider(const io::S3AuthConfig& auth);
82
83
    // The first valid path of config::ca_cert_file_paths, resolved lazily and cached; empty
84
    // when none is valid yet, in which case the next call resolves it again.
85
32
    std::string ca_cert_file_path() { return _get_ca_cert_file_path(); }
86
87
private:
88
#ifdef BE_TEST
89
    FRIEND_TEST(S3ClientFactoryTest, RefreshCaCertForCredentialsProvider);
90
#endif
91
    std::string _get_ca_cert_file_path();
92
    AwsSdkManager();
93
94
    Aws::SDKOptions _aws_options;
95
    std::mutex _ca_cert_lock;
96
    std::string _ca_cert_file_path;
97
};
98
99
} // end namespace doris