aws_profile_provider.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #include <aws/core/platform/Environment.h>
17 
21 static const char * const kProfileLogTag = "ProfileConfigFileAWSCredentialsProvider";
22 static const char * const kAwsProfileEnvironmentVariable = "AWS_DEFAULT_PROFILE";
23 static const char * const kDefaultProfile = "default";
24 
25 namespace Aws {
26 namespace Config {
28 {
30  std::shared_ptr<AWSProfileConfigLoader>(Aws::MakeShared<AWSConfigFileProfileConfigLoader>(
31  kProfileLogTag, GetConfigProfileFilename(), true));
32  config_file_loader_->Load();
34  std::shared_ptr<AWSProfileConfigLoader>(Aws::MakeShared<AWSConfigFileProfileConfigLoader>(
35  kProfileLogTag, GetCredentialsProfileFilename()));
37 
38  auto profile_from_env = Aws::Environment::GetEnv(kAwsProfileEnvironmentVariable);
39  if (!profile_from_env.empty()) {
40  profile_to_use_ = profile_from_env;
41  } else {
43  }
44 }
45 
47 {
48  auto credentials_file_iter = credentials_file_loader_->GetProfiles().find(profile_to_use_);
49  if (credentials_file_iter != credentials_file_loader_->GetProfiles().end()) {
50  return credentials_file_iter->second;
51  }
52  auto config_file_iter = config_file_loader_->GetProfiles().find(profile_to_use_);
53  if (config_file_iter != config_file_loader_->GetProfiles().end()) {
54  return config_file_iter->second;
55  }
56  return Profile();
57 }
58 } // namespace Config
59 } // namespace Aws
std::shared_ptr< AWSProfileConfigLoader > credentials_file_loader_
static const char *const kAwsProfileEnvironmentVariable
static const char *const kDefaultProfile
static const char *const kProfileLogTag
const Aws::Config::Profile GetProfile()
std::shared_ptr< AWSProfileConfigLoader > config_file_loader_


aws_common
Author(s): AWS RoboMaker
autogenerated on Sat Mar 6 2021 03:11:38