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
912namespace 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