-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add constructor overload to STSProfileCredentialsProvider
where the client factory returns a shared pointer.
#2830
base: main
Are you sure you want to change the base?
Conversation
… client factory returns a shared pointer.
@@ -313,7 +313,7 @@ TEST_F(STSProfileCredentialsProviderTest, AssumeRoleWithoutRoleARN) | |||
|
|||
STSProfileCredentialsProvider credsProvider("default", roleSessionDuration, [](const AWSCredentials&) { | |||
ADD_FAILURE() << "STS Service client should not be used in this scenario."; | |||
return nullptr; | |||
return (STSClient*)nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new constructor overload caused return nullptr;
to be ambiguous. This is a source-breaking change but I don't think returning nullptr
is likely in non-test code.
Can you update your PR to remove the .gitignore file change? |
It was a good change but sure. Done. |
STSProfileCredentialsProvider::STSProfileCredentialsProvider(const Aws::String& profileName, std::chrono::minutes duration, const std::function<Aws::STS::STSClient*(const AWSCredentials&)> &stsClientFactory) | ||
: m_profileName(profileName), | ||
m_duration(duration), | ||
m_reloadFrequency(std::chrono::minutes(std::max(int64_t(5), static_cast<int64_t>(duration.count()))) - std::chrono::minutes(5)), | ||
m_stsClientFactory([=](const auto& credentials) {return std::shared_ptr<Aws::STS::STSClient>(stsClientFactory(credentials), NoOpDeleter<Aws::STS::STSClient>()); }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuing discussion from #2839 (comment)
should use MakeShared for allocator awareness?
@sbera87 because we cannot safely delete
an arbitrary pointer we have to create the shared pointer with a special deleter that does nothing.
Issue #, if available:
Description of changes:
The
STSProfileCredentialProvider
class has a constructor overload that accepts anSTSClient
factory function. The problem with this function is that it returns anSTSClient*
, making lifetime management tricky in certain cases.This PR introduces an additional overload that accepts an factory that returns a
shared_ptr<STSClient>
. This will enable the client to be freed automatically when the credentials provider no longer needs it.The existing constructor overload wraps the
STSClient*
into a shared pointer with a deleter that does nothing, maintaining compatibility. I also added an overload to disambiguate between creating a credential provider with anullptr
factory.Check all that applies:
Check which platforms you have built SDK on to verify the correctness of this PR.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.