Coverage Report

Created: 2026-07-27 19:33

/root/doris/common/cpp/aws_common.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 "aws_common.h"
19
20
#include <aws/core/client/ClientConfiguration.h>
21
#include <glog/logging.h>
22
23
namespace doris {
24
25
0
CredProviderType cred_provider_type_from_pb(cloud::CredProviderTypePB cred_provider_type) {
26
0
    switch (cred_provider_type) {
27
0
    case cloud::CredProviderTypePB::DEFAULT:
28
0
        return CredProviderType::Default;
29
0
    case cloud::CredProviderTypePB::SIMPLE:
30
0
        return CredProviderType::Simple;
31
0
    case cloud::CredProviderTypePB::INSTANCE_PROFILE:
32
0
        return CredProviderType::InstanceProfile;
33
0
    case cloud::CredProviderTypePB::ENV:
34
0
        return CredProviderType::Env;
35
0
    case cloud::CredProviderTypePB::SYSTEM_PROPERTIES:
36
0
        return CredProviderType::SystemProperties;
37
0
    case cloud::CredProviderTypePB::WEB_IDENTITY:
38
0
        return CredProviderType::WebIdentity;
39
0
    case cloud::CredProviderTypePB::CONTAINER:
40
0
        return CredProviderType::Container;
41
0
    case cloud::CredProviderTypePB::ANONYMOUS:
42
0
        return CredProviderType::Anonymous;
43
0
    default:
44
0
        __builtin_unreachable();
45
0
        LOG(WARNING) << "Invalid CredProviderTypePB value: " << cred_provider_type
46
0
                     << ", use default instead.";
47
0
        return CredProviderType::Default;
48
0
    }
49
0
}
50
51
0
CredProviderType cred_provider_type_from_string(const std::string& type) {
52
0
    if (type.empty() || type == "DEFAULT") {
53
0
        return CredProviderType::Default;
54
0
    }
55
0
    if (type == "SIMPLE") {
56
0
        return CredProviderType::Simple;
57
0
    }
58
0
    if (type == "INSTANCE_PROFILE") {
59
0
        return CredProviderType::InstanceProfile;
60
0
    }
61
0
    if (type == "ENV") {
62
0
        return CredProviderType::Env;
63
0
    }
64
0
    if (type == "SYSTEM_PROPERTIES") {
65
0
        return CredProviderType::SystemProperties;
66
0
    }
67
0
    if (type == "WEB_IDENTITY") {
68
0
        return CredProviderType::WebIdentity;
69
0
    }
70
0
    if (type == "CONTAINER") {
71
0
        return CredProviderType::Container;
72
0
    }
73
0
    if (type == "ANONYMOUS") {
74
0
        return CredProviderType::Anonymous;
75
0
    }
76
0
    LOG(WARNING) << "Unknown credentials provider type: " << type << ", use default instead.";
77
0
    return CredProviderType::Default;
78
0
}
79
80
7
std::string get_valid_ca_cert_path(const std::vector<std::string>& ca_cert_file_paths) {
81
7
    for (const auto& path : ca_cert_file_paths) {
82
7
        if (std::filesystem::exists(path)) {
83
7
            return path;
84
7
        }
85
7
    }
86
0
    return "";
87
7
}
88
89
void set_s3_client_default_http_scheme(Aws::Client::ClientConfiguration& client_config,
90
10
                                       const std::string& scheme) {
91
10
    if (client_config.endpointOverride.starts_with("http://") ||
92
10
        client_config.endpointOverride.starts_with("https://")) {
93
2
        return;
94
2
    }
95
8
    client_config.scheme = scheme == "http" ? Aws::Http::Scheme::HTTP : Aws::Http::Scheme::HTTPS;
96
8
}
97
} // namespace doris