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/obj_storage_client.h" |
43 | | |
44 | | namespace Aws::S3 { |
45 | | class S3Client; |
46 | | } // namespace Aws::S3 |
47 | | |
48 | | namespace bvar { |
49 | | template <typename T> |
50 | | class Adder; |
51 | | } |
52 | | |
53 | | namespace doris::io { |
54 | | struct S3AuthConfig; |
55 | | } // namespace doris::io |
56 | | |
57 | | namespace doris { |
58 | | |
59 | | std::string hide_access_key(const std::string& ak); |
60 | | |
61 | | // Owns the AWS SDK lifetime and the AWS helpers shared by object storage clients and other AWS |
62 | | // users (e.g. Kinesis). Object storage clients themselves come from io::ObjClientFactory. |
63 | | class S3ClientFactory { |
64 | | public: |
65 | | ~S3ClientFactory(); |
66 | | |
67 | | static S3ClientFactory& instance(); |
68 | | |
69 | 88 | static Aws::Client::ClientConfiguration& getClientConfiguration() { |
70 | | // The default constructor of ClientConfiguration will do some http call |
71 | | // such as Aws::Internal::GetEC2MetadataClient and other init operation, |
72 | | // which is unnecessary. |
73 | | // So here we use a static instance, and deep copy every time |
74 | | // to avoid unnecessary operations. |
75 | 88 | static Aws::Client::ClientConfiguration instance; |
76 | 88 | instance.requestTimeoutMs = config::aws_client_request_timeout_ms; |
77 | 88 | return instance; |
78 | 88 | } |
79 | | |
80 | | AwsCredentialResult create_aws_credentials_provider(const io::S3AuthConfig& auth); |
81 | | |
82 | | // The first valid path of config::ca_cert_file_paths, resolved lazily and cached; empty |
83 | | // when none is valid yet, in which case the next call resolves it again. |
84 | 32 | std::string ca_cert_file_path() { return _get_ca_cert_file_path(); } |
85 | | |
86 | | private: |
87 | | #ifdef BE_TEST |
88 | | FRIEND_TEST(S3ClientFactoryTest, RefreshCaCertForCredentialsProvider); |
89 | | #endif |
90 | | std::string _get_ca_cert_file_path(); |
91 | | S3ClientFactory(); |
92 | | |
93 | | Aws::SDKOptions _aws_options; |
94 | | std::mutex _ca_cert_lock; |
95 | | std::string _ca_cert_file_path; |
96 | | }; |
97 | | |
98 | | } // end namespace doris |