Coverage Report

Created: 2026-08-06 12:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
common/cpp/aws_common.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 "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
22
CredProviderType cred_provider_type_from_string(const std::string& type) {
52
22
    if (type.empty() || type == "DEFAULT") {
53
1
        return CredProviderType::Default;
54
1
    }
55
21
    if (type == "SIMPLE") {
56
0
        return CredProviderType::Simple;
57
0
    }
58
21
    if (type == "INSTANCE_PROFILE") {
59
1
        return CredProviderType::InstanceProfile;
60
1
    }
61
20
    if (type == "ENV") {
62
1
        return CredProviderType::Env;
63
1
    }
64
19
    if (type == "SYSTEM_PROPERTIES") {
65
1
        return CredProviderType::SystemProperties;
66
1
    }
67
18
    if (type == "WEB_IDENTITY") {
68
2
        return CredProviderType::WebIdentity;
69
2
    }
70
16
    if (type == "CONTAINER") {
71
1
        return CredProviderType::Container;
72
1
    }
73
15
    if (type == "ANONYMOUS") {
74
15
        return CredProviderType::Anonymous;
75
15
    }
76
15
    LOG(WARNING) << "Unknown credentials provider type: " << type << ", use default instead.";
77
0
    return CredProviderType::Default;
78
15
}
79
80
9
std::string get_valid_ca_cert_path(const std::vector<std::string>& ca_cert_file_paths) {
81
9
    for (const auto& path : ca_cert_file_paths) {
82
9
        if (std::filesystem::exists(path)) {
83
9
            return path;
84
9
        }
85
9
    }
86
0
    return "";
87
9
}
88
89
void set_s3_client_default_http_scheme(Aws::Client::ClientConfiguration& client_config,
90
33
                                       const std::string& scheme) {
91
33
    if (client_config.endpointOverride.starts_with("http://") ||
92
33
        client_config.endpointOverride.starts_with("https://")) {
93
6
        return;
94
6
    }
95
27
    client_config.scheme = scheme == "http" ? Aws::Http::Scheme::HTTP : Aws::Http::Scheme::HTTPS;
96
27
}
97
} // namespace doris