Skip to content

Commit a1d3e94

Browse files
committed
Add Profile computed getters using Aws::Crt::Optional for proper null handling:
- GetServicesName() returns services definition name or empty Optional - GetEndpointUrl() returns global endpoint URL or empty Optional - Add static Profile::GetServiceEndpointUrl() helper for endpoint resolution - Takes profile, services map, and serviceId as parameters - Maintains Profile as stateless data container - Add AWSConfigFileProfileConfigLoader::GetServices() const accessor Uses Aws::Crt::Optional instead of empty strings to properly represent "no value" state. Static helper pattern keeps Profile ABI-stable while enabling service endpoint resolution without coupling to loader internals.
1 parent 5f61ca1 commit a1d3e94

File tree

5 files changed

+275
-91
lines changed

5 files changed

+275
-91
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,9 @@ namespace Aws
4141
void SetFileName(const Aws::String& fileName) { m_fileName = fileName; }
4242

4343
/**
44-
* Get service-specific endpoint URL for a given profile and service.
44+
* Get services map for endpoint resolution.
4545
*/
46-
const Aws::String* GetServiceEndpointUrl(const Aws::String& profileName, const Aws::String& serviceId) const;
47-
48-
/**
49-
* Get global endpoint URL for a given profile.
50-
*/
51-
const Aws::String* GetGlobalEndpointUrl(const Aws::String& profileName) const;
46+
const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& GetServices() const;
5247

5348
protected:
5449
virtual bool LoadInternal() override;
@@ -57,7 +52,7 @@ namespace Aws
5752
private:
5853
Aws::String m_fileName;
5954
bool m_useProfilePrefix;
60-
Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>> m_servicesDefinitions;
55+
Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>> m_services;
6156
};
6257
}
6358
}

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <aws/core/utils/memory/stl/AWSString.h>
99
#include <aws/core/utils/memory/stl/AWSMap.h>
10-
#include <aws/core/utils/StringUtils.h>
1110
#include <aws/core/auth/AWSCredentials.h>
11+
#include <aws/crt/Optional.h>
1212

1313
namespace Aws
1414
{
@@ -94,11 +94,23 @@ namespace Aws
9494
return iter->second;
9595
}
9696

97-
inline const Aws::String& GetServicesDefinitionName() const { return m_servicesDefinitionName; }
98-
inline void SetServicesDefinitionName(const Aws::String& value) { m_servicesDefinitionName = value; }
97+
inline Aws::Crt::Optional<Aws::String> GetServicesName() const {
98+
const Aws::String& service = GetValue("services");
99+
return service.empty() ? Aws::Crt::Optional<Aws::String>() : Aws::Crt::Optional<Aws::String>(service);
100+
}
101+
102+
inline Aws::Crt::Optional<Aws::String> GetEndpointUrl() const {
103+
const Aws::String& endpoint = GetValue("endpoint_url");
104+
return endpoint.empty() ? Aws::Crt::Optional<Aws::String>() : Aws::Crt::Optional<Aws::String>(endpoint);
105+
}
99106

100-
inline const Aws::String& GetEndpointUrl() const { return m_endpointUrl; }
101-
inline void SetEndpointUrl(const Aws::String& value) { m_endpointUrl = value; }
107+
/**
108+
* Static helper that get service-specific endpoint URL for a given service.
109+
*/
110+
static Aws::Crt::Optional<Aws::String> GetServiceEndpointUrl(
111+
const Profile& profile,
112+
const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& services,
113+
const Aws::String& serviceId);
102114

103115
inline bool IsSsoSessionSet() const { return m_ssoSessionSet; }
104116
inline const SsoSession& GetSsoSession() const { return m_ssoSession; }
@@ -118,8 +130,6 @@ namespace Aws
118130
Aws::String m_ssoAccountId;
119131
Aws::String m_ssoRoleName;
120132
Aws::String m_defaultsMode;
121-
Aws::String m_servicesDefinitionName;
122-
Aws::String m_endpointUrl;
123133
Aws::Map<Aws::String, Aws::String> m_allKeyValPairs;
124134

125135
bool m_ssoSessionSet = false;

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

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace Aws
4242
static const char SSO_SESSION_SECTION[] = "sso-session";
4343
static const char SERVICES_SECTION[] = "services";
4444
static const char ENDPOINT_URL_KEY[] = "endpoint_url";
45+
static const char IGNORE_CONFIGURED_ENDPOINT_URLS_KEY[] = "ignore_configured_endpoint_urls";
4546
static const char DEFAULTS_MODE_KEY[] = "defaults_mode";
4647
static const char EQ = '=';
4748
static const char LEFT_BRACKET = '[';
@@ -76,8 +77,6 @@ namespace Aws
7677
{EXTERNAL_ID_KEY, &Profile::SetExternalId, &Profile::GetExternalId},
7778
{CREDENTIAL_PROCESS_COMMAND, &Profile::SetCredentialProcess, &Profile::GetCredentialProcess},
7879
{SOURCE_PROFILE_KEY, &Profile::SetSourceProfile, &Profile::GetSourceProfile},
79-
{SERVICES_SECTION, &Profile::SetServicesDefinitionName, &Profile::GetServicesDefinitionName},
80-
{ENDPOINT_URL_KEY, &Profile::SetEndpointUrl, &Profile::GetEndpointUrl},
8180
{DEFAULTS_MODE_KEY, &Profile::SetDefaultsMode, &Profile::GetDefaultsMode}};
8281

8382
template<typename EntryT, size_t N>
@@ -117,7 +116,7 @@ namespace Aws
117116
{}
118117

119118
const Aws::Map<String, Profile>& GetProfiles() const { return m_foundProfiles; }
120-
const Aws::Map<String, Aws::Map<String, String>>& GetServicesDefinitions() const { return m_servicesDefinitions; }
119+
const Aws::Map<String, Aws::Map<String, String>>& GetServices() const { return m_services; }
121120

122121
void ParseStream(Aws::IStream& stream)
123122
{
@@ -177,20 +176,20 @@ namespace Aws
177176

178177
// New service block: "s3 =" (right hand side empty)
179178
if (!left.empty() && right.empty()) {
180-
activeServiceId = StringUtils::ToLower(left.c_str());
179+
activeServiceId = StringUtils::ToUpper(left.c_str());
181180
StringUtils::Replace(activeServiceId, " ", "_");
182181
continue;
183182
}
184183

185-
// Ignore top-level endpoint_url in [services name] section
184+
// Ignore global endpoint_url in [services name] section
186185
if (activeServiceId.empty() && StringUtils::CaselessCompare(left.c_str(), ENDPOINT_URL_KEY) == 0) {
187186
AWS_LOGSTREAM_DEBUG(PARSER_TAG, "Ignoring global endpoint_url in [services " << currentSectionName << "]");
188187
continue;
189188
}
190189

191190
// Property inside an active block: "endpoint_url = http://..."
192191
if (!activeServiceId.empty() && left == ENDPOINT_URL_KEY) {
193-
m_servicesDefinitions[currentSectionName][activeServiceId] = right;
192+
m_services[currentSectionName][activeServiceId] = right;
194193
continue;
195194
}
196195
}
@@ -627,7 +626,7 @@ namespace Aws
627626

628627
Aws::Map<String, Profile> m_foundProfiles;
629628
Aws::Map<String, Profile::SsoSession> m_foundSsoSessions;
630-
Aws::Map<String, Aws::Map<String, String>> m_servicesDefinitions;
629+
Aws::Map<String, Aws::Map<String, String>> m_services;
631630
};
632631

633632
static const char* const CONFIG_FILE_LOADER = "Aws::Config::AWSConfigFileProfileConfigLoader";
@@ -642,15 +641,15 @@ namespace Aws
642641
bool AWSConfigFileProfileConfigLoader::LoadInternal()
643642
{
644643
m_profiles.clear();
645-
m_servicesDefinitions.clear();
644+
m_services.clear();
646645

647646
Aws::IFStream inputFile(m_fileName.c_str());
648647
if(inputFile)
649648
{
650649
ConfigFileProfileFSM parser(m_useProfilePrefix);
651650
parser.ParseStream(inputFile);
652651
m_profiles = parser.GetProfiles();
653-
m_servicesDefinitions = parser.GetServicesDefinitions();
652+
m_services = parser.GetServices();
654653
return m_profiles.size() > 0;
655654
}
656655

@@ -739,39 +738,9 @@ namespace Aws
739738
return false;
740739
}
741740

742-
const Aws::String* AWSConfigFileProfileConfigLoader::GetServiceEndpointUrl(const Aws::String& profileName, const Aws::String& serviceId) const
741+
const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& AWSConfigFileProfileConfigLoader::GetServices() const
743742
{
744-
auto profileIter = m_profiles.find(profileName);
745-
if (profileIter == m_profiles.end())
746-
{
747-
return nullptr;
748-
}
749-
750-
const auto& servicesDefName = profileIter->second.GetServicesDefinitionName();
751-
if (servicesDefName.empty()) {
752-
return nullptr;
753-
}
754-
755-
auto servicesDefIter = m_servicesDefinitions.find(servicesDefName);
756-
if (servicesDefIter == m_servicesDefinitions.end()) {
757-
return nullptr;
758-
}
759-
760-
Aws::String key = StringUtils::ToLower(serviceId.c_str());
761-
StringUtils::Replace(key, " ", "_");
762-
auto serviceIter = servicesDefIter->second.find(key);
763-
return (serviceIter == servicesDefIter->second.end()) ? nullptr : &serviceIter->second;
764-
}
765-
766-
const Aws::String* AWSConfigFileProfileConfigLoader::GetGlobalEndpointUrl(const Aws::String& profileName) const
767-
{
768-
auto profileIter = m_profiles.find(profileName);
769-
if (profileIter == m_profiles.end())
770-
{
771-
return nullptr;
772-
}
773-
const Aws::String& endpointUrl = profileIter->second.GetEndpointUrl();
774-
return endpointUrl.empty() ? nullptr : &endpointUrl;
743+
return m_services;
775744
}
776745
} // Config namespace
777746
} // Aws namespace
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#include <aws/core/config/AWSProfileConfig.h>
7+
#include <aws/core/utils/StringUtils.h>
8+
9+
namespace Aws
10+
{
11+
namespace Config
12+
{
13+
using namespace Aws::Utils;
14+
15+
Aws::Crt::Optional<Aws::String> Profile::GetServiceEndpointUrl(
16+
const Profile& profile,
17+
const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& services,
18+
const Aws::String& serviceId)
19+
{
20+
auto servicesName = profile.GetServicesName();
21+
if (!servicesName.has_value()) {
22+
return Aws::Crt::Optional<Aws::String>();
23+
}
24+
25+
auto servicesIter = services.find(*servicesName);
26+
if (servicesIter == services.end()) {
27+
return Aws::Crt::Optional<Aws::String>();
28+
}
29+
30+
Aws::String key = StringUtils::ToUpper(serviceId.c_str());
31+
StringUtils::Replace(key, " ", "_");
32+
auto serviceIter = servicesIter->second.find(key);
33+
34+
return (serviceIter == servicesIter->second.end() || serviceIter->second.empty()) ?
35+
Aws::Crt::Optional<Aws::String>() :
36+
Aws::Crt::Optional<Aws::String>(serviceIter->second);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)