Skip to content

Commit 4fd1886

Browse files
committed
update to use a service object instead of using getvalue
1 parent 03f7837 commit 4fd1886

File tree

3 files changed

+94
-38
lines changed

3 files changed

+94
-38
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ namespace Aws
2020
class Profile
2121
{
2222
public:
23+
/*
24+
* Data container for service endpoints.
25+
*/
26+
class Services
27+
{
28+
public:
29+
inline const Aws::Map<Aws::String, Aws::String>& GetEndpoints() const { return m_endpoints; }
30+
inline const Aws::String& GetServiceName() const { return m_name; }
31+
inline bool IsSet() const { return m_isSet; }
32+
private:
33+
friend class ConfigFileProfileFSM;
34+
void SetEndpoints(Aws::Map<Aws::String, Aws::String>&& endpoints, Aws::String name) {
35+
m_endpoints = std::move(endpoints);
36+
m_name = std::move(name);
37+
m_isSet = true;
38+
}
39+
Aws::Map<Aws::String, Aws::String> m_endpoints;
40+
Aws::String m_name;
41+
bool m_isSet = false;
42+
};
43+
2344
/*
2445
* Data container for a sso-session config entry.
2546
* This is independent of the general profile configuration and used by a bearer auth token provider.
@@ -94,10 +115,7 @@ namespace Aws
94115
return iter->second;
95116
}
96117

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-
}
118+
inline const Services& GetServiceEndpoints() const { return m_services; }
101119

102120
inline Aws::Crt::Optional<Aws::String> GetEndpointUrl() const {
103121
const Aws::String& endpoint = GetValue("endpoint_url");
@@ -110,6 +128,7 @@ namespace Aws
110128
inline void SetSsoSession(SsoSession&& value) { m_ssoSessionSet = true; m_ssoSession = std::move(value); }
111129

112130
private:
131+
friend class ConfigFileProfileFSM;
113132
Aws::String m_name;
114133
Aws::String m_region;
115134
Aws::Auth::AWSCredentials m_credentials;
@@ -123,6 +142,7 @@ namespace Aws
123142
Aws::String m_ssoRoleName;
124143
Aws::String m_defaultsMode;
125144
Aws::Map<Aws::String, Aws::String> m_allKeyValPairs;
145+
Services m_services;
126146

127147
bool m_ssoSessionSet = false;
128148
SsoSession m_ssoSession;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,27 @@ namespace Aws
206206

207207
FlushSection(currentState, currentSectionName, currentKeyValues);
208208

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+
if (servicesBlk == m_services.end())
218+
{
219+
// Services section exists but has no endpoints (all content was ignored)
220+
Aws::Map<Aws::String, Aws::String> emptyEndpoints;
221+
profile.m_services.SetEndpoints(std::move(emptyEndpoints), servicesRef);
222+
}
223+
else
224+
{
225+
profile.m_services.SetEndpoints(std::move(servicesBlk->second), servicesRef);
226+
}
227+
}
228+
}
229+
209230
// Put sso-sessions into profiles
210231
for(auto& profile : m_foundProfiles)
211232
{

tests/aws-cpp-sdk-core-tests/aws/config/ServiceEndpointsConfigFileLoaderTest.cpp

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificEndpoints)
4646
ASSERT_TRUE(globalEndpoint.has_value());
4747
ASSERT_STREQ("https://global.example.com", globalEndpoint->c_str());
4848

49-
// Test services name is parsed correctly
50-
auto servicesName = profile.GetServicesName();
51-
ASSERT_TRUE(servicesName.has_value());
52-
ASSERT_STREQ("myservices", servicesName->c_str());
53-
49+
// Test services endpoints are parsed correctly
50+
const auto& services = profile.GetServiceEndpoints();
51+
ASSERT_TRUE(services.IsSet());
52+
const auto& endpoints = services.GetEndpoints();
53+
ASSERT_EQ(2u, endpoints.size());
54+
ASSERT_EQ("http://localhost:9000", endpoints.at("S3"));
55+
ASSERT_EQ("http://localhost:8000", endpoints.at("DYNAMODB"));
5456
}
5557

5658
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificEndpointsOnly)
@@ -76,10 +78,12 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificEndpointsOnly)
7678
auto globalEndpoint = profile.GetEndpointUrl();
7779
ASSERT_FALSE(globalEndpoint.has_value());
7880

79-
// Test services name is parsed correctly
80-
auto servicesName = profile.GetServicesName();
81-
ASSERT_TRUE(servicesName.has_value());
82-
ASSERT_STREQ("s3-minio", servicesName->c_str());
81+
// Test services endpoints are parsed correctly
82+
const auto& services = profile.GetServiceEndpoints();
83+
ASSERT_TRUE(services.IsSet());
84+
const auto& endpoints = services.GetEndpoints();
85+
ASSERT_EQ(1u, endpoints.size());
86+
ASSERT_EQ("https://play.min.io:9000", endpoints.at("S3"));
8387
}
8488

8589
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestGlobalEndpointOnly)
@@ -103,9 +107,9 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestGlobalEndpointOnly)
103107
ASSERT_TRUE(globalEndpoint.has_value());
104108
ASSERT_STREQ("https://play.min.io:9000", globalEndpoint->c_str());
105109

106-
// Test that services name is not set
107-
auto servicesName = profile.GetServicesName();
108-
ASSERT_FALSE(servicesName.has_value());
110+
// Test that services endpoints are not set
111+
const auto& services = profile.GetServiceEndpoints();
112+
ASSERT_FALSE(services.IsSet());
109113
}
110114

111115
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificAndGlobalEndpoints)
@@ -128,10 +132,12 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificAndGlobalEndpoin
128132
ASSERT_NE(profiles.end(), profileIt);
129133
const auto& profile = profileIt->second;
130134

131-
// Test services name is parsed correctly
132-
auto servicesName = profile.GetServicesName();
133-
ASSERT_TRUE(servicesName.has_value());
134-
ASSERT_STREQ("s3-specific-and-global", servicesName->c_str());
135+
// Test services endpoints are parsed correctly
136+
const auto& services = profile.GetServiceEndpoints();
137+
ASSERT_TRUE(services.IsSet());
138+
const auto& endpoints = services.GetEndpoints();
139+
ASSERT_EQ(1u, endpoints.size());
140+
ASSERT_EQ("https://play.min.io:9000", endpoints.at("S3"));
135141

136142
// Test global endpoint
137143
auto globalEndpoint = profile.GetEndpointUrl();
@@ -160,10 +166,13 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestMultipleServicesInDefinition)
160166
ASSERT_NE(profiles.end(), profileIt);
161167
const auto& profile = profileIt->second;
162168

163-
// Test services name is parsed correctly
164-
auto servicesName = profile.GetServicesName();
165-
ASSERT_TRUE(servicesName.has_value());
166-
ASSERT_STREQ("testing-s3-and-eb", servicesName->c_str());
169+
// Test services endpoints are parsed correctly
170+
const auto& services = profile.GetServiceEndpoints();
171+
ASSERT_TRUE(services.IsSet());
172+
const auto& endpoints = services.GetEndpoints();
173+
ASSERT_EQ(2u, endpoints.size());
174+
ASSERT_EQ("http://localhost:4567", endpoints.at("S3"));
175+
ASSERT_EQ("http://localhost:8000", endpoints.at("ELASTIC_BEANSTALK"));
167176
}
168177

169178
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestIgnoreGlobalEndpointInServicesSection)
@@ -188,10 +197,11 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestIgnoreGlobalEndpointInServicesS
188197
auto globalEndpoint = profile.GetEndpointUrl();
189198
ASSERT_FALSE(globalEndpoint.has_value());
190199

191-
// Test that services name is parsed correctly
192-
auto servicesName = profile.GetServicesName();
193-
ASSERT_TRUE(servicesName.has_value());
194-
ASSERT_STREQ("bad-service-definition", servicesName->c_str());
200+
// Test that services endpoints are empty (global endpoint_url ignored)
201+
const auto& services = profile.GetServiceEndpoints();
202+
ASSERT_TRUE(services.IsSet());
203+
const auto& endpoints = services.GetEndpoints();
204+
ASSERT_EQ(0u, endpoints.size());
195205
}
196206

197207
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestSourceProfileEndpointIsolation)
@@ -221,10 +231,12 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestSourceProfileEndpointIsolation)
221231
ASSERT_NE(profiles.end(), profileAIt);
222232
const auto& profileA = profileAIt->second;
223233

224-
// Test that profile B has services name
225-
auto servicesBName = profileB.GetServicesName();
226-
ASSERT_TRUE(servicesBName.has_value());
227-
ASSERT_STREQ("profileB", servicesBName->c_str());
234+
// Test that profile B has services endpoints
235+
const auto& servicesB = profileB.GetServiceEndpoints();
236+
ASSERT_TRUE(servicesB.IsSet());
237+
const auto& endpointsB = servicesB.GetEndpoints();
238+
ASSERT_EQ(1u, endpointsB.size());
239+
ASSERT_EQ("https://profile-b-ec2-endpoint.aws", endpointsB.at("EC2"));
228240

229241
// Test that profile B has no global endpoint (doesn't inherit from profile A)
230242
auto globalEndpointB = profileB.GetEndpointUrl();
@@ -236,9 +248,10 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestSourceProfileEndpointIsolation)
236248
ASSERT_STREQ("https://profile-a-endpoint.aws/", globalEndpointA->c_str());
237249

238250
// Test that profile A has no services name
239-
auto servicesAName = profileA.GetServicesName();
240-
ASSERT_FALSE(servicesAName.has_value());
251+
const auto& servicesA = profileA.GetServiceEndpoints();
252+
ASSERT_FALSE(servicesA.IsSet());
241253
}
254+
242255
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestIgnoreConfiguredEndpointUrls)
243256
{
244257
TempFile configFile(std::ios_base::out | std::ios_base::trunc);
@@ -285,8 +298,10 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestMultipleServicesDefinitions)
285298
ASSERT_NE(profiles.end(), profileIt);
286299
const auto& profile = profileIt->second;
287300

288-
// Test services name is parsed correctly
289-
auto servicesName = profile.GetServicesName();
290-
ASSERT_TRUE(servicesName.has_value());
291-
ASSERT_STREQ("foo", servicesName->c_str());
301+
// Test services endpoints are parsed correctly
302+
const auto& services = profile.GetServiceEndpoints();
303+
ASSERT_TRUE(services.IsSet());
304+
const auto& endpoints = services.GetEndpoints();
305+
ASSERT_EQ(1u, endpoints.size());
306+
ASSERT_EQ("http://foo.com", endpoints.at("S3"));
292307
}

0 commit comments

Comments
 (0)