common/cpp/custom_aws_credentials_provider_chain.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 "custom_aws_credentials_provider_chain.h" |
19 | | |
20 | | #include <aws/core/auth/AWSCredentialsProviderChain.h> |
21 | | #include <aws/core/auth/SSOCredentialsProvider.h> |
22 | | #include <aws/core/auth/STSCredentialsProvider.h> |
23 | | #include <aws/core/platform/Environment.h> |
24 | | #include <aws/core/utils/StringUtils.h> |
25 | | #include <aws/core/utils/logging/LogMacros.h> |
26 | | #include <aws/core/utils/memory/AWSMemory.h> |
27 | | |
28 | | #include "aws_common.h" |
29 | | |
30 | | namespace doris { |
31 | | |
32 | | using namespace Aws::Auth; |
33 | | using namespace Aws::Utils::Threading; |
34 | | |
35 | | static const char AWS_EC2_METADATA_DISABLED[] = "AWS_EC2_METADATA_DISABLED"; |
36 | | static const char DefaultCredentialsProviderChainTag[] = "DefaultAWSCredentialsProviderChain"; |
37 | | |
38 | | CustomAwsCredentialsProviderChain::CustomAwsCredentialsProviderChain() |
39 | 6 | : AWSCredentialsProviderChain() { |
40 | 6 | AddProvider(Aws::MakeShared<STSAssumeRoleWebIdentityCredentialsProvider>( |
41 | 6 | DefaultCredentialsProviderChainTag)); |
42 | | |
43 | 6 | const auto ec2MetadataDisabled = Aws::Environment::GetEnv(AWS_EC2_METADATA_DISABLED); |
44 | 6 | AWS_LOGSTREAM_DEBUG(DefaultCredentialsProviderChainTag, |
45 | 6 | "The environment variable value " << AWS_EC2_METADATA_DISABLED << " is " |
46 | 6 | << ec2MetadataDisabled); |
47 | | |
48 | | // One provider serves both container platforms: create_container_credentials_provider() reads |
49 | | // all four AWS_CONTAINER_* variables, applies the provider's own relative-then-absolute |
50 | | // precedence, and logs which variable supplied the endpoint. |
51 | 6 | if (container_credentials_available()) { |
52 | 1 | AddProvider(create_container_credentials_provider()); |
53 | 1 | } |
54 | | |
55 | 6 | AddProvider(Aws::MakeShared<InstanceProfileCredentialsProvider>( |
56 | 6 | DefaultCredentialsProviderChainTag)); |
57 | 6 | AWS_LOGSTREAM_INFO(DefaultCredentialsProviderChainTag, |
58 | 6 | "Added EC2 metadata service credentials provider to the provider chain."); |
59 | | |
60 | 6 | AddProvider( |
61 | 6 | Aws::MakeShared<EnvironmentAWSCredentialsProvider>(DefaultCredentialsProviderChainTag)); |
62 | 6 | AddProvider(Aws::MakeShared<ProfileConfigFileAWSCredentialsProvider>( |
63 | 6 | DefaultCredentialsProviderChainTag)); |
64 | 6 | AddProvider(Aws::MakeShared<ProcessCredentialsProvider>(DefaultCredentialsProviderChainTag)); |
65 | | |
66 | 6 | AddProvider(Aws::MakeShared<SSOCredentialsProvider>(DefaultCredentialsProviderChainTag)); |
67 | | |
68 | 6 | AddProvider( |
69 | 6 | Aws::MakeShared<AnonymousAWSCredentialsProvider>(DefaultCredentialsProviderChainTag)); |
70 | 6 | } |
71 | | |
72 | | CustomAwsCredentialsProviderChain::CustomAwsCredentialsProviderChain( |
73 | 0 | const CustomAwsCredentialsProviderChain& chain) { |
74 | 0 | for (const auto& provider : chain.GetProviders()) { |
75 | 0 | AddProvider(provider); |
76 | 0 | } |
77 | 0 | } |
78 | | } |