Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors MinimalIamCredentialsRestStub to handle potential errors when retrieving the universe domain. Specifically, IamCredentialsEndpoint and MakeRequestPath now return StatusOr<std::string>, and AllowedLocationsHelper has been updated to accept a relative path and construct the full path internally after validating the universe domain endpoint. Unit tests have been added to cover these failure scenarios. Feedback on the changes suggests passing the universe_domain parameter in IamCredentialsEndpoint by const& instead of by value to avoid unnecessary copies of StatusOr<std::string>, as it is not a sink parameter.
| StatusOr<std::string> IamCredentialsEndpoint( | ||
| StatusOr<std::string> universe_domain) { | ||
| if (!universe_domain) return std::move(universe_domain).status(); | ||
| return absl::StrCat("https://iamcredentials.", *universe_domain); | ||
| } |
There was a problem hiding this comment.
The universe_domain parameter is not a sink parameter because its value is only read to construct the endpoint URL and is not stored or moved into another object on the happy path. Passing it by const& avoids unnecessary moves or copies of StatusOr<std::string> when the function is called.
StatusOr<std::string> IamCredentialsEndpoint(
StatusOr<std::string> const& universe_domain) {
if (!universe_domain) return universe_domain.status();
return absl::StrCat("https://iamcredentials.", *universe_domain);
}References
- Scrutinize copies of non-fundamental C++ types. Since
universe_domainis not a sink parameter, passing it by const reference avoids unnecessary moves/copies on the happy path. (link)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v3.14.x #16700 +/- ##
===========================================
- Coverage 92.63% 92.61% -0.02%
===========================================
Files 2271 2271
Lines 224833 224902 +69
===========================================
+ Hits 208272 208293 +21
- Misses 16561 16609 +48 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
No description provided.