client_configuration_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/Version.h>
16 #include <aws/core/client/DefaultRetryStrategy.h>
17 #include <aws/core/platform/OSVersionInfo.h>
21 
22 #include <utility>
23 
24 #ifndef CLIENT_CONFIG_PREFIX
25 #define CLIENT_CONFIG_PREFIX "aws_client_configuration"
26 #endif
27 
28 namespace Aws {
29 namespace Client {
30 
34 class NoRetryStrategy : public RetryStrategy
35 {
36 public:
37  NoRetryStrategy() = default;
38 
39  // NOLINTNEXTLINE(google-runtime-int)
40  bool ShouldRetry(const AWSError<CoreErrors> & error, long attemptedRetries) const override
41  {
42  AWS_UNREFERENCED_PARAM(error);
43  AWS_UNREFERENCED_PARAM(attemptedRetries);
44  return false;
45  }
46 
47  // NOLINTNEXTLINE(google-runtime-int)
48  long CalculateDelayBeforeNextRetry(const AWSError<CoreErrors> & error, long attemptedRetries) const override
49  {
50  AWS_UNREFERENCED_PARAM(error);
51  AWS_UNREFERENCED_PARAM(attemptedRetries);
52  return 0;
53  }
54 };
55 
56 
57 bool operator==(const ClientConfiguration & left, const ClientConfiguration & right)
58 {
59  bool result = true;
60 
61  result &= (right.region == left.region);
62  result &= (right.userAgent == left.userAgent);
63  result &= (right.endpointOverride == left.endpointOverride);
64  result &= (right.proxyHost == left.proxyHost);
65  result &= (right.proxyUserName == left.proxyUserName);
66  result &= (right.proxyPassword == left.proxyPassword);
67  result &= (right.caPath == left.caPath);
68  result &= (right.caFile == left.caFile);
69 
70  result &= (left.requestTimeoutMs == right.requestTimeoutMs);
71  result &= (left.connectTimeoutMs == right.connectTimeoutMs);
72  result &= (left.maxConnections == right.maxConnections);
73  result &= (left.proxyPort == right.proxyPort);
74  result &= (left.useDualStack == right.useDualStack);
75  result &= (left.enableClockSkewAdjustment == right.enableClockSkewAdjustment);
76  result &= (left.followRedirects == right.followRedirects);
77  result &= (left.verifySSL == right.verifySSL);
78 
79  return result;
80 }
81 
82 bool operator!=(const ClientConfiguration & left, const ClientConfiguration & right)
83 {
84  return !(left == right);
85 }
86 
88  std::shared_ptr<ParameterReaderInterface> reader)
89 {
90  this->reader_ = std::move(reader);
91 }
92 
93 void ClientConfigurationProvider::PopulateUserAgent(Aws::String & user_agent,
94  const std::string & ros_version_override)
95 {
96  Aws::String ros_user_agent_suffix = " exec-env/AWS_RoboMaker ros-" CMAKE_ROS_DISTRO "/";
97  if (ros_version_override.empty()) {
98  ros_user_agent_suffix += CMAKE_ROS_VERSION;
99  } else {
100  ros_user_agent_suffix += ros_version_override.c_str();
101  }
102  user_agent += ros_user_agent_suffix;
103 }
104 
106  const std::string & ros_version_override)
107 {
108  ClientConfiguration config;
109  Aws::Config::AWSProfileProvider profile_provider;
116  config.region = profile_provider.GetProfile().GetRegion();
117  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "region"), config.region);
118  PopulateUserAgent(config.userAgent, ros_version_override);
119  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "user_agent"), config.userAgent);
120  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "endpoint_override"), config.endpointOverride);
121  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "proxy_host"), config.proxyHost);
122  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "proxy_user_name"), config.proxyUserName);
123  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "proxy_password"), config.proxyPassword);
124  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "ca_path"), config.caPath);
125  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "ca_file"), config.caFile);
126 
127  int temp;
128  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "request_timeout_ms"), temp)) {
129  config.requestTimeoutMs = temp;
130  }
131  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "connect_timeout_ms"), temp)) {
132  config.connectTimeoutMs = temp;
133  }
134  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "max_connections"), temp)) {
135  config.maxConnections = temp;
136  }
137  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "proxy_port"), temp)) {
138  config.proxyPort = temp;
139  }
140 
141  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "use_dual_stack"), config.useDualStack);
142  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "enable_clock_skew_adjustment"),
143  config.enableClockSkewAdjustment);
144  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "follow_redirects"), config.followRedirects);
145  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "verify_SSL"), config.verifySSL);
146 
147  // check for non-default strategy
148  bool strategy = false;
149  auto error = reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "no_retry_strategy"), strategy);
150 
151  if (AWS_ERR_OK == error && strategy) {
152  config.retryStrategy = std::make_shared<NoRetryStrategy>();
153  } else {
154  // if max retries is set use the DefaultRetryStrategy
155  int max_retries;
156  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "max_retries"), max_retries)) {
157  config.retryStrategy = std::make_shared<Aws::Client::DefaultRetryStrategy>(max_retries);
158  }
159  }
160 
161  return config;
162 }
163 
164 } // namespace Client
165 } // namespace Aws
#define CLIENT_CONFIG_PREFIX
bool operator==(const ClientConfiguration &left, const ClientConfiguration &right)
void PopulateUserAgent(Aws::String &user_agent, const std::string &ros_version_override="")
bool operator!=(const ClientConfiguration &left, const ClientConfiguration &right)
bool ShouldRetry(const AWSError< CoreErrors > &error, long attemptedRetries) const override
const Aws::Config::Profile GetProfile()
ClientConfigurationProvider(std::shared_ptr< ParameterReaderInterface > reader)
Creates a new ClientConfigurationProvider that uses the provided reader for loading configuraiton...
long CalculateDelayBeforeNextRetry(const AWSError< CoreErrors > &error, long attemptedRetries) const override
ClientConfiguration GetClientConfiguration(const std::string &ros_version_override="")


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