ClientConfiguration ClientConfigurationProvider::GetClientConfiguration()

in aws_common/src/sdk_utils/client_configuration_provider.cpp [105:164]


ClientConfiguration ClientConfigurationProvider::GetClientConfiguration(
  const std::string & ros_version_override)
{
  ClientConfiguration config;
  Aws::Config::AWSProfileProvider profile_provider;
  /**
   * Give priority to region parameter from the parameter reader if exists, otherwise use the AWS
   * SDK/CLI config file (defaults to ~/.aws/config). The latter is needed because unlike
   * credentials, region does not get loaded automatically from the profile by the SDK (it simply
   * defaults to us-east-1).
   */
  config.region = profile_provider.GetProfile().GetRegion();
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "region"), config.region);
  PopulateUserAgent(config.userAgent, ros_version_override);
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "user_agent"), config.userAgent);
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "endpoint_override"), config.endpointOverride);
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "proxy_host"), config.proxyHost);
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "proxy_user_name"), config.proxyUserName);
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "proxy_password"), config.proxyPassword);
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "ca_path"), config.caPath);
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "ca_file"), config.caFile);

  int temp;
  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "request_timeout_ms"), temp)) {
    config.requestTimeoutMs = temp;
  }
  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "connect_timeout_ms"), temp)) {
    config.connectTimeoutMs = temp;
  }
  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "max_connections"), temp)) {
    config.maxConnections = temp;
  }
  if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "proxy_port"), temp)) {
    config.proxyPort = temp;
  }

  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "use_dual_stack"), config.useDualStack);
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "enable_clock_skew_adjustment"),
                    config.enableClockSkewAdjustment);
  bool followRedirects;
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "follow_redirects"), followRedirects);
  config.followRedirects = followRedirects ? Aws::Client::FollowRedirectsPolicy::ALWAYS : Aws::Client::FollowRedirectsPolicy::NEVER;
  reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "verify_SSL"), config.verifySSL);

  // check for non-default strategy
  bool strategy = false;
  auto error = reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "no_retry_strategy"), strategy);

  if (AWS_ERR_OK == error && strategy) {
    config.retryStrategy = std::make_shared<NoRetryStrategy>();
  } else {
    // if max retries is set use the DefaultRetryStrategy
    int max_retries;
    if (AWS_ERR_OK == reader_->ReadParam(ParameterPath(CLIENT_CONFIG_PREFIX, "max_retries"), max_retries)) {
      config.retryStrategy = std::make_shared<Aws::Client::DefaultRetryStrategy>(max_retries);
    }
  }

  return config;
}