Skip to content

Added CustomSSOCredentialsProvider to retain higher-level ClientConfiguration #3103

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#pragma once

#include <aws/core/auth/SSOCredentialsProvider.h>
#include <aws/core/client/ClientConfiguration.h>

namespace Aws {
namespace Auth {
class AWS_CORE_API CustomSSOCredentialsProvider : public SSOCredentialsProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class isnt needed we should just be adding a constructor the SSOCredentialsProvider itself, no need to create a indirection.

public:
CustomSSOCredentialsProvider(const Aws::Client::ClientConfiguration& clientConfig)
: SSOCredentialsProvider(), m_clientConfig(clientConfig)
{
}

void Reload() override {
Aws::Client::ClientConfiguration config = m_clientConfig;
config.scheme = Aws::Http::Scheme::HTTPS;
config.region = m_ssoRegion;

m_client = Aws::MakeUnique<Aws::Internal::SSOCredentialsClient>(SSO_CREDENTIALS_PROVIDER_LOG_TAG, config);

SSOCredentialsProvider::Reload();
}

private:
Aws::Client::ClientConfiguration m_clientConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a ClientConfiguration in the base SSO credentials provider. Is the duplication intentional?

};
} // namespace Auth
} // namespace Aws
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Aws {
public:
SSOCredentialsProvider();
explicit SSOCredentialsProvider(const Aws::String& profile);
explicit SSOCredentialsProvider(const Aws::Client::ClientConfiguration& clientConfig);
/**
* Retrieves the credentials if found, otherwise returns empty credential set.
*/
Expand All @@ -42,6 +43,8 @@ namespace Aws {
Aws::Utils::DateTime m_expiresAt;
// The SSO Token Provider
Aws::Auth::SSOBearerTokenProvider m_bearerTokenProvider;
// Custom ClientConfiguration used by the SSOCredentialsClient during Reload()
Aws::Client::ClientConfiguration m_clientConfig;

void Reload() override;
void RefreshIfExpired();
Expand Down
9 changes: 8 additions & 1 deletion src/aws-cpp-sdk-core/source/auth/SSOCredentialsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ SSOCredentialsProvider::SSOCredentialsProvider(const Aws::String& profile) : m_p
AWS_LOGSTREAM_INFO(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Setting sso credentials provider to read config from " << m_profileToUse);
}

SSOCredentialsProvider::SSOCredentialsProvider(const Aws::Client::ClientConfiguration& clientConfig)
: m_profileToUse(GetConfigProfileName()), m_clientConfig(clientConfig)
{
AWS_LOGSTREAM_INFO(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Setting sso credentials provider to read config from " << m_profileToUse);
}


AWSCredentials SSOCredentialsProvider::GetAWSCredentials()
{
RefreshIfExpired();
Expand Down Expand Up @@ -80,7 +87,7 @@ void SSOCredentialsProvider::Reload()
request.m_ssoRoleName = profile.GetSsoRoleName();
request.m_accessToken = accessToken;

Aws::Client::ClientConfiguration config;
Aws::Client::ClientConfiguration config = m_clientConfig;
config.scheme = Aws::Http::Scheme::HTTPS;
config.region = m_ssoRegion;
AWS_LOGSTREAM_DEBUG(SSO_CREDENTIALS_PROVIDER_LOG_TAG, "Passing config to client for region: " << m_ssoRegion);
Expand Down
Loading