Skip to content

Commit 2627fe9

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 added a test for multiple services definition updated test to use .find before creatng the profile update to use a service object instead of using getvalue added 3 more tests verifying duplication urls, modify the services object with more encapsulation
1 parent a1d3e94 commit 2627fe9

File tree

5 files changed

+237
-158
lines changed

5 files changed

+237
-158
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <aws/core/config/AWSProfileConfigLoaderBase.h>
99

1010
#include <aws/core/utils/memory/stl/AWSString.h>
11-
#include <aws/core/utils/memory/stl/AWSMap.h>
1211

1312
namespace Aws
1413
{
@@ -40,19 +39,13 @@ namespace Aws
4039
*/
4140
void SetFileName(const Aws::String& fileName) { m_fileName = fileName; }
4241

43-
/**
44-
* Get services map for endpoint resolution.
45-
*/
46-
const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& GetServices() const;
47-
4842
protected:
4943
virtual bool LoadInternal() override;
5044
virtual bool PersistInternal(const Aws::Map<Aws::String, Aws::Config::Profile>&) override;
5145

5246
private:
5347
Aws::String m_fileName;
5448
bool m_useProfilePrefix;
55-
Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>> m_services;
5649
};
5750
}
5851
}

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@ namespace Aws
2020
class Profile
2121
{
2222
public:
23+
/*
24+
* Data container for service endpoints.
25+
*/
26+
class Services
27+
{
28+
public:
29+
Services() = default;
30+
Services(Aws::Map<Aws::String, Aws::String>&& endpoints, Aws::String name)
31+
: m_endpoints(std::move(endpoints)), m_name(std::move(name)) {}
32+
33+
inline Aws::Map<Aws::String, Aws::String> GetEndpoints() const { return m_endpoints; }
34+
inline Aws::String GetServiceBlockName() const { return m_name; }
35+
inline bool IsSet() const { return !m_name.empty(); }
36+
private:
37+
Aws::Map<Aws::String, Aws::String> m_endpoints;
38+
Aws::String m_name;
39+
};
40+
2341
/*
2442
* Data container for a sso-session config entry.
2543
* This is independent of the general profile configuration and used by a bearer auth token provider.
@@ -94,24 +112,14 @@ namespace Aws
94112
return iter->second;
95113
}
96114

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-
}
115+
inline const Services& GetServices() const { return m_services; }
116+
inline void SetServices(Services&& services) { m_services = std::move(services); }
101117

102-
inline Aws::Crt::Optional<Aws::String> GetEndpointUrl() const {
118+
inline Aws::Crt::Optional<Aws::String> GetGlobalEndpointUrl() const {
103119
const Aws::String& endpoint = GetValue("endpoint_url");
104120
return endpoint.empty() ? Aws::Crt::Optional<Aws::String>() : Aws::Crt::Optional<Aws::String>(endpoint);
105121
}
106122

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);
114-
115123
inline bool IsSsoSessionSet() const { return m_ssoSessionSet; }
116124
inline const SsoSession& GetSsoSession() const { return m_ssoSession; }
117125
inline void SetSsoSession(const SsoSession& value) { m_ssoSessionSet = true; m_ssoSession = value; }
@@ -131,6 +139,7 @@ namespace Aws
131139
Aws::String m_ssoRoleName;
132140
Aws::String m_defaultsMode;
133141
Aws::Map<Aws::String, Aws::String> m_allKeyValPairs;
142+
Services m_services;
134143

135144
bool m_ssoSessionSet = false;
136145
SsoSession m_ssoSession;

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ namespace Aws
116116
{}
117117

118118
const Aws::Map<String, Profile>& GetProfiles() const { return m_foundProfiles; }
119-
const Aws::Map<String, Aws::Map<String, String>>& GetServices() const { return m_services; }
120119

121120
void ParseStream(Aws::IStream& stream)
122121
{
@@ -207,6 +206,22 @@ namespace Aws
207206

208207
FlushSection(currentState, currentSectionName, currentKeyValues);
209208

209+
// Resolve service endpoints
210+
for (auto& profilePair : m_foundProfiles)
211+
{
212+
Profile& profile = profilePair.second;
213+
const Aws::String& servicesRef = profile.GetValue("services");
214+
if (!servicesRef.empty())
215+
{
216+
auto servicesBlk = m_services.find(servicesRef);
217+
Aws::Map<Aws::String, Aws::String> endpoints;
218+
if (servicesBlk != m_services.end()) {
219+
endpoints = servicesBlk->second;
220+
}
221+
profile.SetServices(Profile::Services(std::move(endpoints), servicesRef));
222+
}
223+
}
224+
210225
// Put sso-sessions into profiles
211226
for(auto& profile : m_foundProfiles)
212227
{
@@ -641,15 +656,13 @@ namespace Aws
641656
bool AWSConfigFileProfileConfigLoader::LoadInternal()
642657
{
643658
m_profiles.clear();
644-
m_services.clear();
645659

646660
Aws::IFStream inputFile(m_fileName.c_str());
647661
if(inputFile)
648662
{
649663
ConfigFileProfileFSM parser(m_useProfilePrefix);
650664
parser.ParseStream(inputFile);
651665
m_profiles = parser.GetProfiles();
652-
m_services = parser.GetServices();
653666
return m_profiles.size() > 0;
654667
}
655668

@@ -737,10 +750,5 @@ namespace Aws
737750

738751
return false;
739752
}
740-
741-
const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& AWSConfigFileProfileConfigLoader::GetServices() const
742-
{
743-
return m_services;
744-
}
745753
} // Config namespace
746754
} // Aws namespace

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

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)