1 | /* |
2 | * Copyright 2010-2017 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 | |
16 | #include <aws/core/client/ClientConfiguration.h> |
17 | #include <aws/core/auth/AWSCredentialsProvider.h> |
18 | #include <aws/core/client/DefaultRetryStrategy.h> |
19 | #include <aws/core/platform/OSVersionInfo.h> |
20 | #include <aws/core/utils/memory/AWSMemory.h> |
21 | #include <aws/core/utils/threading/Executor.h> |
22 | #include <aws/core/utils/memory/stl/AWSStringStream.h> |
23 | #include <aws/core/Version.h> |
24 | #include <aws/core/config/AWSProfileConfigLoader.h> |
25 | #include <aws/core/utils/logging/LogMacros.h> |
26 | |
27 | namespace Aws |
28 | { |
29 | namespace Auth |
30 | { |
31 | AWS_CORE_API Aws::String GetConfigProfileFilename(); |
32 | } |
33 | namespace Client |
34 | { |
35 | |
36 | static const char* CLIENT_CONFIG_TAG = "ClientConfiguration" ; |
37 | |
38 | AWS_CORE_API Aws::String ComputeUserAgentString() |
39 | { |
40 | Aws::StringStream ss; |
41 | ss << "aws-sdk-cpp/" << Version::GetVersionString() << " " << Aws::OSVersionInfo::ComputeOSVersionString() |
42 | << " " << Version::GetCompilerVersionString(); |
43 | return ss.str(); |
44 | } |
45 | |
46 | ClientConfiguration::ClientConfiguration() : |
47 | userAgent(ComputeUserAgentString()), |
48 | scheme(Aws::Http::Scheme::HTTPS), |
49 | region(Region::US_EAST_1), |
50 | useDualStack(false), |
51 | maxConnections(25), |
52 | httpRequestTimeoutMs(0), |
53 | requestTimeoutMs(3000), |
54 | connectTimeoutMs(1000), |
55 | enableTcpKeepAlive(true), |
56 | tcpKeepAliveIntervalMs(30000), |
57 | lowSpeedLimit(1), |
58 | retryStrategy(Aws::MakeShared<DefaultRetryStrategy>(CLIENT_CONFIG_TAG)), |
59 | proxyScheme(Aws::Http::Scheme::HTTP), |
60 | proxyPort(0), |
61 | executor(Aws::MakeShared<Aws::Utils::Threading::DefaultExecutor>(CLIENT_CONFIG_TAG)), |
62 | verifySSL(true), |
63 | writeRateLimiter(nullptr), |
64 | readRateLimiter(nullptr), |
65 | httpLibOverride(Aws::Http::TransferLibType::DEFAULT_CLIENT), |
66 | followRedirects(true), |
67 | disableExpectHeader(false), |
68 | enableClockSkewAdjustment(true), |
69 | enableHostPrefixInjection(true), |
70 | enableEndpointDiscovery(false), |
71 | profileName(Aws::Auth::GetConfigProfileName()) |
72 | { |
73 | AWS_LOGSTREAM_DEBUG(CLIENT_CONFIG_TAG, "ClientConfiguration will use SDK Auto Resolved profile: [" << profileName << "] if not specified by users." ); |
74 | } |
75 | |
76 | ClientConfiguration::ClientConfiguration(const char* profileName) : ClientConfiguration() |
77 | { |
78 | if (profileName && Aws::Config::HasCachedConfigProfile(profileName)) |
79 | { |
80 | this->profileName = Aws::String(profileName); |
81 | AWS_LOGSTREAM_DEBUG(CLIENT_CONFIG_TAG, "Use user specified profile: [" << this->profileName << "] for ClientConfiguration." ); |
82 | auto tmpRegion = Aws::Config::GetCachedConfigProfile(this->profileName).GetRegion(); |
83 | if (!tmpRegion.empty()) |
84 | { |
85 | region = tmpRegion; |
86 | } |
87 | return; |
88 | } |
89 | AWS_LOGSTREAM_WARN(CLIENT_CONFIG_TAG, "User specified profile: [" << profileName << "] is not found, will use the SDK resolved one." ); |
90 | } |
91 | |
92 | } // namespace Client |
93 | } // namespace Aws |
94 | |