/root/doris/be/src/util/obj_credential.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 "cpp/obj-client/auth/obj_credential.h" |
19 | | |
20 | | #include <gen_cpp/AgentService_types.h> |
21 | | #include <gen_cpp/cloud.pb.h> |
22 | | |
23 | | namespace doris { |
24 | | namespace { |
25 | | |
26 | 0 | GcpCredentialConfig to_gcp_credential_config(const cloud::GcpCredentialPB& credential) { |
27 | 0 | GcpCredentialConfig config; |
28 | 0 | switch (credential.credential_provider_type()) { |
29 | 0 | case cloud::GcpCredentialPB::DEFAULT: |
30 | 0 | config.provider_type = GcpCredentialProviderType::Default; |
31 | 0 | break; |
32 | 0 | case cloud::GcpCredentialPB::COMPUTE_ENGINE: |
33 | 0 | config.provider_type = GcpCredentialProviderType::ComputeEngine; |
34 | 0 | break; |
35 | 0 | } |
36 | 0 | config.impersonation_service_account = credential.impersonation_service_account(); |
37 | 0 | return config; |
38 | 0 | } |
39 | | |
40 | 0 | GcpCredentialConfig to_gcp_credential_config(const TGcpCredential& credential) { |
41 | 0 | GcpCredentialConfig config; |
42 | 0 | if (credential.__isset.credential_provider_type) { |
43 | 0 | switch (credential.credential_provider_type) { |
44 | 0 | case TGcpCredentialProviderType::DEFAULT: |
45 | 0 | config.provider_type = GcpCredentialProviderType::Default; |
46 | 0 | break; |
47 | 0 | case TGcpCredentialProviderType::COMPUTE_ENGINE: |
48 | 0 | config.provider_type = GcpCredentialProviderType::ComputeEngine; |
49 | 0 | break; |
50 | 0 | } |
51 | 0 | } |
52 | 0 | if (credential.__isset.impersonation_service_account) { |
53 | 0 | config.impersonation_service_account = credential.impersonation_service_account; |
54 | 0 | } |
55 | 0 | return config; |
56 | 0 | } |
57 | | |
58 | | } // namespace |
59 | | |
60 | 0 | void convert_obj_credential(const cloud::ObjectStoreInfoPB& source, CredentialConfig* credential) { |
61 | 0 | if (!source.has_credential() || !source.credential().has_gcp_credential()) { |
62 | 0 | *credential = std::monostate {}; |
63 | 0 | return; |
64 | 0 | } |
65 | 0 | *credential = to_gcp_credential_config(source.credential().gcp_credential()); |
66 | 0 | } |
67 | | |
68 | 0 | void convert_obj_credential(const TCredential& source, CredentialConfig* credential) { |
69 | 0 | if (!source.__isset.gcp_credential) { |
70 | 0 | *credential = std::monostate {}; |
71 | 0 | return; |
72 | 0 | } |
73 | 0 | *credential = to_gcp_credential_config(source.gcp_credential); |
74 | 0 | } |
75 | | |
76 | | } // namespace doris |