Skip to content

Commit 153fdff

Browse files
committed
Address PR feedback and clean-up.
1 parent 1351715 commit 153fdff

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

src/aws-cpp-sdk-core/source/auth/SSOCredentialsProvider.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@ SSOCredentialsProvider::SSOCredentialsProvider(const Aws::String& profile) : SSO
3636
{
3737
}
3838

39-
SSOCredentialsProvider::SSOCredentialsProvider(const Aws::String& profile, const std::shared_ptr<const Client::ClientConfiguration> config) :
39+
SSOCredentialsProvider::SSOCredentialsProvider(const Aws::String& profile, std::shared_ptr<const Client::ClientConfiguration> config) :
4040
m_profileToUse(profile),
4141
m_bearerTokenProvider(profile),
42-
m_config(config)
42+
m_config(std::move(config))
4343
{
4444
AWS_LOGSTREAM_INFO(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Setting sso credentials provider to read config from " << m_profileToUse);
45+
if (!m_config)
46+
{
47+
auto defaultConfig = Aws::MakeShared<Client::ClientConfiguration>(SSO_CREDENTIALS_PROVIDER_LOG_TAG);
48+
defaultConfig->scheme = Aws::Http::Scheme::HTTPS;
49+
// We cannot set region to m_ssoRegion because it is not yet known at this point. But it's not obtained from the client config either way.
50+
Aws::Vector<Aws::String> retryableErrors{ "TooManyRequestsException" };
51+
defaultConfig->retryStrategy = Aws::MakeShared<SpecifiedRetryableErrorsRetryStrategy>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, std::move(retryableErrors), 3/*maxRetries*/);
52+
m_config = std::move(defaultConfig);
53+
}
4554
}
4655

4756
AWSCredentials SSOCredentialsProvider::GetAWSCredentials()
@@ -85,20 +94,7 @@ void SSOCredentialsProvider::Reload()
8594
request.m_ssoRoleName = profile.GetSsoRoleName();
8695
request.m_accessToken = accessToken;
8796

88-
Aws::Client::ClientConfiguration defaultConfig;
89-
if (!m_config)
90-
{
91-
defaultConfig.scheme = Aws::Http::Scheme::HTTPS;
92-
defaultConfig.region = m_ssoRegion;
93-
AWS_LOGSTREAM_DEBUG(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Passing config to client for region: " << m_ssoRegion);
94-
95-
Aws::Vector<Aws::String> retryableErrors;
96-
retryableErrors.push_back("TooManyRequestsException");
97-
98-
defaultConfig.retryStrategy = Aws::MakeShared<SpecifiedRetryableErrorsRetryStrategy>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, retryableErrors, 3/*maxRetries*/);
99-
}
100-
const Aws::Client::ClientConfiguration& config = m_config ? *m_config : defaultConfig;
101-
m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, config, Aws::Http::Scheme::HTTPS, m_ssoRegion);
97+
m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, *m_config, Aws::Http::Scheme::HTTPS, m_ssoRegion);
10298

10399
AWS_LOGSTREAM_TRACE(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Requesting credentials with AWS_ACCESS_KEY: " << m_ssoAccountId);
104100
auto result = m_client->GetSSOCredentials(request);

src/aws-cpp-sdk-core/source/auth/bearer-token-provider/SSOBearerTokenProvider.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,18 @@ static const char SSO_GRANT_TYPE[] = "refresh_token";
2727
const size_t SSOBearerTokenProvider::REFRESH_WINDOW_BEFORE_EXPIRATION_S = 600;
2828
const size_t SSOBearerTokenProvider::REFRESH_ATTEMPT_INTERVAL_S = 30;
2929

30-
SSOBearerTokenProvider::SSOBearerTokenProvider()
31-
: m_profileToUse(Aws::Auth::GetConfigProfileName()),
32-
m_lastUpdateAttempt((int64_t) 0)
30+
SSOBearerTokenProvider::SSOBearerTokenProvider() : SSOBearerTokenProvider(Aws::Auth::GetConfigProfileName(), nullptr)
3331
{
34-
AWS_LOGSTREAM_INFO(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, "Setting sso bearerToken provider to read config from " << m_profileToUse);
3532
}
3633

37-
SSOBearerTokenProvider::SSOBearerTokenProvider(const Aws::String& awsProfile)
38-
: m_profileToUse(awsProfile),
39-
m_lastUpdateAttempt((int64_t) 0)
34+
SSOBearerTokenProvider::SSOBearerTokenProvider(const Aws::String& awsProfile) : SSOBearerTokenProvider(awsProfile, nullptr)
4035
{
41-
AWS_LOGSTREAM_INFO(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, "Setting sso bearerToken provider to read config from " << m_profileToUse);
4236
}
4337

4438
SSOBearerTokenProvider::SSOBearerTokenProvider(const Aws::String& awsProfile, std::shared_ptr<const Client::ClientConfiguration> config)
4539
: m_profileToUse(awsProfile),
46-
m_lastUpdateAttempt((int64_t)0),
47-
m_config(config)
40+
m_config(config ? std::move(config) : Aws::MakeShared<Client::ClientConfiguration>(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG)),
41+
m_lastUpdateAttempt((int64_t)0)
4842
{
4943
AWS_LOGSTREAM_INFO(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, "Setting sso bearerToken provider to read config from " << m_profileToUse);
5044
}
@@ -105,16 +99,10 @@ void SSOBearerTokenProvider::RefreshFromSso()
10599
/* The SSO token provider must not resolve if any SSO configuration values are present directly on the profile
106100
* instead of an `sso-session` section. The SSO token provider must ignore these configuration values if these
107101
* values are present directly on the profile instead of an `sso-session` section. */
108-
// config.region = m_profile.GetSsoRegion(); // <- intentionally not used per comment above
102+
// auto& region = m_profile.GetSsoRegion(); // <- intentionally not used per comment above
109103
auto& region = cachedSsoToken.region;
110-
Aws::Client::ClientConfiguration defaultConfig;
111-
if (!m_config)
112-
{
113-
defaultConfig.scheme = scheme;
114-
defaultConfig.region = region;
115-
}
116-
const Aws::Client::ClientConfiguration& config = m_config ? *m_config : defaultConfig;
117-
m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, config, scheme, cachedSsoToken.region);
104+
// m_config->region might not be the same as the SSO region, but the former is not used by the SSO client.
105+
m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, *m_config, scheme, region);
118106
}
119107

120108
Aws::Internal::SSOCredentialsClient::SSOCreateTokenRequest ssoCreateTokenRequest;

0 commit comments

Comments
 (0)