Skip to content

Commit

Permalink
Address PR feedback and clean-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
teo-tsirpanis committed Sep 17, 2024
1 parent 1351715 commit 153fdff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 35 deletions.
28 changes: 12 additions & 16 deletions src/aws-cpp-sdk-core/source/auth/SSOCredentialsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,21 @@ SSOCredentialsProvider::SSOCredentialsProvider(const Aws::String& profile) : SSO
{
}

SSOCredentialsProvider::SSOCredentialsProvider(const Aws::String& profile, const std::shared_ptr<const Client::ClientConfiguration> config) :
SSOCredentialsProvider::SSOCredentialsProvider(const Aws::String& profile, std::shared_ptr<const Client::ClientConfiguration> config) :
m_profileToUse(profile),
m_bearerTokenProvider(profile),
m_config(config)
m_config(std::move(config))
{
AWS_LOGSTREAM_INFO(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Setting sso credentials provider to read config from " << m_profileToUse);
if (!m_config)
{
auto defaultConfig = Aws::MakeShared<Client::ClientConfiguration>(SSO_CREDENTIALS_PROVIDER_LOG_TAG);
defaultConfig->scheme = Aws::Http::Scheme::HTTPS;
// 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.
Aws::Vector<Aws::String> retryableErrors{ "TooManyRequestsException" };
defaultConfig->retryStrategy = Aws::MakeShared<SpecifiedRetryableErrorsRetryStrategy>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, std::move(retryableErrors), 3/*maxRetries*/);
m_config = std::move(defaultConfig);
}
}

AWSCredentials SSOCredentialsProvider::GetAWSCredentials()
Expand Down Expand Up @@ -85,20 +94,7 @@ void SSOCredentialsProvider::Reload()
request.m_ssoRoleName = profile.GetSsoRoleName();
request.m_accessToken = accessToken;

Aws::Client::ClientConfiguration defaultConfig;
if (!m_config)
{
defaultConfig.scheme = Aws::Http::Scheme::HTTPS;
defaultConfig.region = m_ssoRegion;
AWS_LOGSTREAM_DEBUG(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Passing config to client for region: " << m_ssoRegion);

Aws::Vector<Aws::String> retryableErrors;
retryableErrors.push_back("TooManyRequestsException");

defaultConfig.retryStrategy = Aws::MakeShared<SpecifiedRetryableErrorsRetryStrategy>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, retryableErrors, 3/*maxRetries*/);
}
const Aws::Client::ClientConfiguration& config = m_config ? *m_config : defaultConfig;
m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, config, Aws::Http::Scheme::HTTPS, m_ssoRegion);
m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, *m_config, Aws::Http::Scheme::HTTPS, m_ssoRegion);

AWS_LOGSTREAM_TRACE(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Requesting credentials with AWS_ACCESS_KEY: " << m_ssoAccountId);
auto result = m_client->GetSSOCredentials(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,18 @@ static const char SSO_GRANT_TYPE[] = "refresh_token";
const size_t SSOBearerTokenProvider::REFRESH_WINDOW_BEFORE_EXPIRATION_S = 600;
const size_t SSOBearerTokenProvider::REFRESH_ATTEMPT_INTERVAL_S = 30;

SSOBearerTokenProvider::SSOBearerTokenProvider()
: m_profileToUse(Aws::Auth::GetConfigProfileName()),
m_lastUpdateAttempt((int64_t) 0)
SSOBearerTokenProvider::SSOBearerTokenProvider() : SSOBearerTokenProvider(Aws::Auth::GetConfigProfileName(), nullptr)
{
AWS_LOGSTREAM_INFO(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, "Setting sso bearerToken provider to read config from " << m_profileToUse);
}

SSOBearerTokenProvider::SSOBearerTokenProvider(const Aws::String& awsProfile)
: m_profileToUse(awsProfile),
m_lastUpdateAttempt((int64_t) 0)
SSOBearerTokenProvider::SSOBearerTokenProvider(const Aws::String& awsProfile) : SSOBearerTokenProvider(awsProfile, nullptr)
{
AWS_LOGSTREAM_INFO(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, "Setting sso bearerToken provider to read config from " << m_profileToUse);
}

SSOBearerTokenProvider::SSOBearerTokenProvider(const Aws::String& awsProfile, std::shared_ptr<const Client::ClientConfiguration> config)
: m_profileToUse(awsProfile),
m_lastUpdateAttempt((int64_t)0),
m_config(config)
m_config(config ? std::move(config) : Aws::MakeShared<Client::ClientConfiguration>(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG)),
m_lastUpdateAttempt((int64_t)0)
{
AWS_LOGSTREAM_INFO(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, "Setting sso bearerToken provider to read config from " << m_profileToUse);
}
Expand Down Expand Up @@ -105,16 +99,10 @@ void SSOBearerTokenProvider::RefreshFromSso()
/* The SSO token provider must not resolve if any SSO configuration values are present directly on the profile
* instead of an `sso-session` section. The SSO token provider must ignore these configuration values if these
* values are present directly on the profile instead of an `sso-session` section. */
// config.region = m_profile.GetSsoRegion(); // <- intentionally not used per comment above
// auto& region = m_profile.GetSsoRegion(); // <- intentionally not used per comment above
auto& region = cachedSsoToken.region;
Aws::Client::ClientConfiguration defaultConfig;
if (!m_config)
{
defaultConfig.scheme = scheme;
defaultConfig.region = region;
}
const Aws::Client::ClientConfiguration& config = m_config ? *m_config : defaultConfig;
m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, config, scheme, cachedSsoToken.region);
// m_config->region might not be the same as the SSO region, but the former is not used by the SSO client.
m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_BEARER_TOKEN_PROVIDER_LOG_TAG, *m_config, scheme, region);
}

Aws::Internal::SSOCredentialsClient::SSOCreateTokenRequest ssoCreateTokenRequest;
Expand Down

0 comments on commit 153fdff

Please sign in to comment.