Skip to content

Commit 2112b46

Browse files
committed
refactor code to use defaults
1 parent ff1e153 commit 2112b46

File tree

2 files changed

+76
-71
lines changed

2 files changed

+76
-71
lines changed

src/aws-cpp-sdk-core/include/aws/core/config/EndpointResolver.h

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -38,77 +38,7 @@ namespace Aws
3838
* @return Optional endpoint URL if found, empty if not configured
3939
*/
4040
AWS_CORE_API Aws::String EndpointSource(const Aws::String& serviceId,
41-
const Aws::String& profileName)
42-
{
43-
const Aws::String serviceKey = ToEnvSuffix(serviceId);
44-
45-
// 1) Check ignore flag from environment variable
46-
Aws::String ignoreEnv = Aws::Environment::GetEnv("AWS_IGNORE_CONFIGURED_ENDPOINT_URLS");
47-
if (!ignoreEnv.empty() && Utils::StringUtils::ConvertToBool(ignoreEnv.c_str())) {
48-
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Configured endpoints ignored due to AWS_IGNORE_CONFIGURED_ENDPOINT_URLS=true");
49-
return "";
50-
}
51-
52-
// 1b) Check ignore flag from profile (early check)
53-
if (!profileName.empty() && HasCachedConfigProfile(profileName)) {
54-
Profile profile = GetCachedConfigProfile(profileName);
55-
const Aws::String ignoreVal = profile.GetValue("ignore_configured_endpoint_urls");
56-
if (!ignoreVal.empty() && Utils::StringUtils::ConvertToBool(ignoreVal.c_str())) {
57-
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Configured endpoints ignored due to ignore_configured_endpoint_urls=true in profile: " << profileName);
58-
return "";
59-
}
60-
}
61-
62-
// 2) Service-specific environment variable
63-
{
64-
Aws::String service = "AWS_ENDPOINT_URL_";
65-
service += serviceKey;
66-
Aws::String fromEnv = Aws::Environment::GetEnv(service.c_str());
67-
if (!fromEnv.empty()) {
68-
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Resolved configured endpoint from service-specific environment variable: " << service);
69-
AWS_LOGSTREAM_TRACE(ENDPOINT_RESOLVER_TAG, "Configured endpoint URL: " << fromEnv);
70-
return fromEnv;
71-
}
72-
}
73-
74-
// 3) Global environment variable
75-
{
76-
Aws::String fromEnv = Aws::Environment::GetEnv("AWS_ENDPOINT_URL");
77-
if (!fromEnv.empty()) {
78-
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Resolved configured endpoint from global environment variable: AWS_ENDPOINT_URL");
79-
AWS_LOGSTREAM_TRACE(ENDPOINT_RESOLVER_TAG, "Configured endpoint URL: " << fromEnv);
80-
return fromEnv;
81-
}
82-
}
83-
84-
// Skip profile resolution no profile available
85-
if (profileName.empty() || !HasCachedConfigProfile(profileName)) {
86-
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "No configured endpoint found - no profile available or profile not cached");
87-
return "";
88-
}
89-
90-
Profile profile = GetCachedConfigProfile(profileName);
91-
92-
// 4) Service-specific endpoint from shared config profile
93-
const auto& endpoints = profile.GetServices().GetEndpoints();
94-
auto it = endpoints.find(serviceKey);
95-
if (it != endpoints.end() && !it->second.empty()) {
96-
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Resolved configured endpoint from service-specific profile setting for service: " << serviceKey << " in profile: " << profileName);
97-
AWS_LOGSTREAM_TRACE(ENDPOINT_RESOLVER_TAG, "Configured endpoint URL: " << it->second);
98-
return it->second;
99-
}
100-
101-
// 5) Global profile endpoint
102-
auto endpoint = profile.GetGlobalEndpointUrl();
103-
if (!endpoint.empty()) {
104-
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Resolved configured endpoint from global profile setting in profile: " << profileName);
105-
AWS_LOGSTREAM_TRACE(ENDPOINT_RESOLVER_TAG, "Configured endpoint URL: " << endpoint);
106-
return endpoint;
107-
}
108-
109-
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "No configured endpoint found for service: " << serviceId);
110-
return "";
111-
}
41+
const Aws::String& profileName);
11242
}
11343

11444
} // namespace Config

src/aws-cpp-sdk-core/source/config/EndpointResolver.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#include <aws/core/config/EndpointResolver.h>
77
#include <aws/core/utils/StringUtils.h>
8+
#include <aws/core/config/ConfigAndCredentialsCacheManager.h>
9+
#include <aws/core/platform/Environment.h>
10+
#include <aws/core/utils/logging/LogMacros.h>
811

912
namespace Aws
1013
{
@@ -20,6 +23,78 @@ namespace Aws
2023
std::replace(result.begin(), result.end(), '-', '_');
2124
return result;
2225
}
26+
27+
Aws::String EndpointSource(const Aws::String& serviceId, const Aws::String& profileName)
28+
{
29+
const Aws::String serviceKey = ToEnvSuffix(serviceId);
30+
31+
// 1) Check ignore flag from environment variable
32+
Aws::String ignoreEnv = Aws::Environment::GetEnv("AWS_IGNORE_CONFIGURED_ENDPOINT_URLS");
33+
if (!ignoreEnv.empty() && Utils::StringUtils::ConvertToBool(ignoreEnv.c_str())) {
34+
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Configured endpoints ignored due to AWS_IGNORE_CONFIGURED_ENDPOINT_URLS=true");
35+
return "";
36+
}
37+
38+
// 1b) Check ignore flag from profile (early check)
39+
if (!profileName.empty() && HasCachedConfigProfile(profileName)) {
40+
Profile profile = GetCachedConfigProfile(profileName);
41+
const Aws::String ignoreVal = profile.GetValue("ignore_configured_endpoint_urls");
42+
if (!ignoreVal.empty() && Utils::StringUtils::ConvertToBool(ignoreVal.c_str())) {
43+
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Configured endpoints ignored due to ignore_configured_endpoint_urls=true in profile: " << profileName);
44+
return "";
45+
}
46+
}
47+
48+
// 2) Service-specific environment variable
49+
{
50+
Aws::String service = "AWS_ENDPOINT_URL_";
51+
service += serviceKey;
52+
Aws::String fromEnv = Aws::Environment::GetEnv(service.c_str());
53+
if (!fromEnv.empty()) {
54+
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Resolved configured endpoint from service-specific environment variable: " << service);
55+
AWS_LOGSTREAM_TRACE(ENDPOINT_RESOLVER_TAG, "Configured endpoint URL: " << fromEnv);
56+
return fromEnv;
57+
}
58+
}
59+
60+
// 3) Global environment variable
61+
{
62+
Aws::String fromEnv = Aws::Environment::GetEnv("AWS_ENDPOINT_URL");
63+
if (!fromEnv.empty()) {
64+
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Resolved configured endpoint from global environment variable: AWS_ENDPOINT_URL");
65+
AWS_LOGSTREAM_TRACE(ENDPOINT_RESOLVER_TAG, "Configured endpoint URL: " << fromEnv);
66+
return fromEnv;
67+
}
68+
}
69+
70+
// Skip profile resolution no profile available
71+
if (profileName.empty() || !HasCachedConfigProfile(profileName)) {
72+
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "No configured endpoint found - no profile available or profile not cached");
73+
return "";
74+
}
75+
76+
Profile profile = GetCachedConfigProfile(profileName);
77+
78+
// 4) Service-specific endpoint from shared config profile
79+
const auto& endpoints = profile.GetServices().GetEndpoints();
80+
auto it = endpoints.find(serviceKey);
81+
if (it != endpoints.end() && !it->second.empty()) {
82+
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Resolved configured endpoint from service-specific profile setting for service: " << serviceKey << " in profile: " << profileName);
83+
AWS_LOGSTREAM_TRACE(ENDPOINT_RESOLVER_TAG, "Configured endpoint URL: " << it->second);
84+
return it->second;
85+
}
86+
87+
// 5) Global profile endpoint
88+
auto endpoint = profile.GetGlobalEndpointUrl();
89+
if (!endpoint.empty()) {
90+
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "Resolved configured endpoint from global profile setting in profile: " << profileName);
91+
AWS_LOGSTREAM_TRACE(ENDPOINT_RESOLVER_TAG, "Configured endpoint URL: " << endpoint);
92+
return endpoint;
93+
}
94+
95+
AWS_LOGSTREAM_DEBUG(ENDPOINT_RESOLVER_TAG, "No configured endpoint found for service: " << serviceId);
96+
return "";
97+
}
2398
}
2499
}
25100
}

0 commit comments

Comments
 (0)