Skip to content

Commit a9ed91e

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 AWSConfigFileProfileConfigLoader::GetServices() const accessor Uses Aws::Crt::Optional instead of empty strings to properly represent "no value" state.
1 parent a1d3e94 commit a9ed91e

File tree

5 files changed

+31
-120
lines changed

5 files changed

+31
-120
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ namespace Aws
3939
* This can avoid creating new loader object if the file changed.
4040
*/
4141
void SetFileName(const Aws::String& fileName) { m_fileName = fileName; }
42-
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;

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ namespace Aws
104104
return endpoint.empty() ? Aws::Crt::Optional<Aws::String>() : Aws::Crt::Optional<Aws::String>(endpoint);
105105
}
106106

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-
115107
inline bool IsSsoSessionSet() const { return m_ssoSessionSet; }
116108
inline const SsoSession& GetSsoSession() const { return m_ssoSession; }
117109
inline void SetSsoSession(const SsoSession& value) { m_ssoSessionSet = true; m_ssoSession = value; }

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,10 +737,5 @@ namespace Aws
737737

738738
return false;
739739
}
740-
741-
const Aws::Map<Aws::String, Aws::Map<Aws::String, Aws::String>>& AWSConfigFileProfileConfigLoader::GetServices() const
742-
{
743-
return m_services;
744-
}
745740
} // Config namespace
746741
} // Aws namespace

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

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

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

Lines changed: 31 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,10 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificEndpoints)
4444
ASSERT_TRUE(globalEndpoint.has_value());
4545
ASSERT_STREQ("https://global.example.com", globalEndpoint->c_str());
4646

47-
// Test service-specific endpoints
48-
auto s3Endpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "s3");
49-
ASSERT_TRUE(s3Endpoint.has_value());
50-
ASSERT_STREQ("http://localhost:9000", s3Endpoint->c_str());
51-
52-
auto dynamoEndpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "dynamodb");
53-
ASSERT_TRUE(dynamoEndpoint.has_value());
54-
ASSERT_STREQ("http://localhost:8000", dynamoEndpoint->c_str());
55-
56-
// Test case insensitive service lookup
57-
auto s3EndpointUpper = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "S3");
58-
ASSERT_TRUE(s3EndpointUpper.has_value());
59-
ASSERT_STREQ("http://localhost:9000", s3EndpointUpper->c_str());
60-
61-
// Test non-existent service
62-
auto nonExistent = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "nonexistent");
63-
ASSERT_FALSE(nonExistent.has_value());
47+
// Test services name is parsed correctly
48+
auto servicesName = profile.GetServicesName();
49+
ASSERT_TRUE(servicesName.has_value());
50+
ASSERT_STREQ("myservices", servicesName->c_str());
6451

6552
}
6653

@@ -85,15 +72,10 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificEndpointsOnly)
8572
auto globalEndpoint = profile.GetEndpointUrl();
8673
ASSERT_FALSE(globalEndpoint.has_value());
8774

88-
// Test service-specific endpoint
89-
auto s3Endpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "s3");
90-
ASSERT_TRUE(s3Endpoint.has_value());
91-
ASSERT_STREQ("https://play.min.io:9000", s3Endpoint->c_str());
92-
93-
// Test case insensitive lookup
94-
auto s3EndpointUpper = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "S3");
95-
ASSERT_TRUE(s3EndpointUpper.has_value());
96-
ASSERT_STREQ("https://play.min.io:9000", s3EndpointUpper->c_str());
75+
// Test services name is parsed correctly
76+
auto servicesName = profile.GetServicesName();
77+
ASSERT_TRUE(servicesName.has_value());
78+
ASSERT_STREQ("s3-minio", servicesName->c_str());
9779
}
9880

9981
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestGlobalEndpointOnly)
@@ -115,9 +97,9 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestGlobalEndpointOnly)
11597
ASSERT_TRUE(globalEndpoint.has_value());
11698
ASSERT_STREQ("https://play.min.io:9000", globalEndpoint->c_str());
11799

118-
// Test that service-specific endpoint is null when not set
119-
auto s3Endpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "s3");
120-
ASSERT_FALSE(s3Endpoint.has_value());
100+
// Test that services name is not set
101+
auto servicesName = profile.GetServicesName();
102+
ASSERT_FALSE(servicesName.has_value());
121103
}
122104

123105
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificAndGlobalEndpoints)
@@ -138,19 +120,15 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestServiceSpecificAndGlobalEndpoin
138120
auto profiles = loader.GetProfiles();
139121
const auto& profile = profiles["dev-s3-specific-and-global"];
140122

141-
// Test service-specific S3 endpoint
142-
auto s3Endpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "s3");
143-
ASSERT_TRUE(s3Endpoint.has_value());
144-
ASSERT_STREQ("https://play.min.io:9000", s3Endpoint->c_str());
123+
// Test services name is parsed correctly
124+
auto servicesName = profile.GetServicesName();
125+
ASSERT_TRUE(servicesName.has_value());
126+
ASSERT_STREQ("s3-specific-and-global", servicesName->c_str());
145127

146-
// Test global endpoint for other services
128+
// Test global endpoint
147129
auto globalEndpoint = profile.GetEndpointUrl();
148130
ASSERT_TRUE(globalEndpoint.has_value());
149131
ASSERT_STREQ("http://localhost:1234", globalEndpoint->c_str());
150-
151-
// Test that non-configured service returns null (would fall back to global)
152-
auto dynamoEndpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "dynamodb");
153-
ASSERT_FALSE(dynamoEndpoint.has_value());
154132
}
155133

156134
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestMultipleServicesInDefinition)
@@ -172,20 +150,10 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestMultipleServicesInDefinition)
172150
auto profiles = loader.GetProfiles();
173151
const auto& profile = profiles["dev"];
174152

175-
// Test S3 endpoint
176-
auto s3Endpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "s3");
177-
ASSERT_TRUE(s3Endpoint.has_value());
178-
ASSERT_STREQ("http://localhost:4567", s3Endpoint->c_str());
179-
180-
// Test Elastic Beanstalk endpoint with normalized service ID
181-
auto ebEndpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "Elastic Beanstalk");
182-
ASSERT_TRUE(ebEndpoint.has_value());
183-
ASSERT_STREQ("http://localhost:8000", ebEndpoint->c_str());
184-
185-
// Test direct normalized lookup
186-
auto ebEndpointDirect = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "elastic_beanstalk");
187-
ASSERT_TRUE(ebEndpointDirect.has_value());
188-
ASSERT_STREQ("http://localhost:8000", ebEndpointDirect->c_str());
153+
// Test services name is parsed correctly
154+
auto servicesName = profile.GetServicesName();
155+
ASSERT_TRUE(servicesName.has_value());
156+
ASSERT_STREQ("testing-s3-and-eb", servicesName->c_str());
189157
}
190158

191159
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestIgnoreGlobalEndpointInServicesSection)
@@ -208,9 +176,10 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestIgnoreGlobalEndpointInServicesS
208176
auto globalEndpoint = profile.GetEndpointUrl();
209177
ASSERT_FALSE(globalEndpoint.has_value());
210178

211-
// Test that service-specific endpoints return null (no services configured)
212-
auto s3Endpoint = Profile::GetServiceEndpointUrl(profile, loader.GetServices(), "s3");
213-
ASSERT_FALSE(s3Endpoint.has_value());
179+
// Test that services name is parsed correctly
180+
auto servicesName = profile.GetServicesName();
181+
ASSERT_TRUE(servicesName.has_value());
182+
ASSERT_STREQ("bad-service-definition", servicesName->c_str());
214183
}
215184

216185
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestSourceProfileEndpointIsolation)
@@ -236,10 +205,10 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestSourceProfileEndpointIsolation)
236205
const auto& profileB = profiles["B"];
237206
const auto& profileA = profiles["A"];
238207

239-
// Test that profile B gets EC2 endpoint from its own services definition
240-
auto ec2Endpoint = Profile::GetServiceEndpointUrl(profileB, loader.GetServices(), "ec2");
241-
ASSERT_TRUE(ec2Endpoint.has_value());
242-
ASSERT_STREQ("https://profile-b-ec2-endpoint.aws", ec2Endpoint->c_str());
208+
// Test that profile B has services name
209+
auto servicesBName = profileB.GetServicesName();
210+
ASSERT_TRUE(servicesBName.has_value());
211+
ASSERT_STREQ("profileB", servicesBName->c_str());
243212

244213
// Test that profile B has no global endpoint (doesn't inherit from profile A)
245214
auto globalEndpointB = profileB.GetEndpointUrl();
@@ -250,9 +219,9 @@ TEST_F(ServiceEndpointsConfigFileLoaderTest, TestSourceProfileEndpointIsolation)
250219
ASSERT_TRUE(globalEndpointA.has_value());
251220
ASSERT_STREQ("https://profile-a-endpoint.aws/", globalEndpointA->c_str());
252221

253-
// Test that other services in profile B return null (no chaining to profile A)
254-
auto s3Endpoint = Profile::GetServiceEndpointUrl(profileB, loader.GetServices(), "s3");
255-
ASSERT_FALSE(s3Endpoint.has_value());
222+
// Test that profile A has no services name
223+
auto servicesAName = profileA.GetServicesName();
224+
ASSERT_FALSE(servicesAName.has_value());
256225
}
257226
TEST_F(ServiceEndpointsConfigFileLoaderTest, TestIgnoreConfiguredEndpointUrls)
258227
{

0 commit comments

Comments
 (0)