Skip to content

Commit

Permalink
Fix smithy signer ctors for older gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed Aug 28, 2024
1 parent 6499c31 commit 6dd34e1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ namespace smithy {

//This allows to override the identity resolver
explicit SigV4AuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver,
const SigV4AuthSchemeParameters& parameters)
const Aws::String& serviceName,
const Aws::String& region)
: AuthScheme(SIGV4),
m_identityResolver{identityResolver},
m_signer{Aws::MakeShared<AwsSigV4Signer>("SigV4AuthScheme", parameters)}
m_signer{Aws::MakeShared<AwsSigV4Signer>("SigV4AuthScheme", serviceName, region)}
{
assert(m_identityResolver);
assert(m_signer);
}

//delegate constructor
explicit SigV4AuthScheme(const SigV4AuthSchemeParameters& parameters)
explicit SigV4AuthScheme(const Aws::String& serviceName,
const Aws::String& region)
: SigV4AuthScheme(Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4AuthScheme"),
parameters)
serviceName,
region)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ namespace smithy {

//This allows to override the identity resolver
explicit SigV4aAuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver,
const SigV4aAuthSchemeParameters& parameters)
const Aws::String& serviceName,
const Aws::String& region)
: AuthScheme(SIGV4A),
m_identityResolver{identityResolver},
m_signer{Aws::MakeShared<AwsSigV4aSigner>("SigV4aAuthScheme", parameters)}
m_signer{Aws::MakeShared<AwsSigV4aSigner>("SigV4aAuthScheme", serviceName, region)}
{
assert(m_identityResolver);
assert(m_signer);
}

explicit SigV4aAuthScheme(const SigV4aAuthSchemeParameters& parameters)
: SigV4aAuthScheme(Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4aAuthScheme"),parameters )
explicit SigV4aAuthScheme(const Aws::String& serviceName,
const Aws::String& region)
: SigV4aAuthScheme(Aws::MakeShared<DefaultAwsCredentialIdentityResolver>("SigV4aAuthScheme"), serviceName, region)
{
assert(m_identityResolver);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ namespace smithy {

public:
using SigV4AuthSchemeParameters = DefaultAuthSchemeResolverParameters;
explicit AwsSigV4Signer(const SigV4AuthSchemeParameters& parameters)
: m_parameters{parameters},legacySigner{nullptr, parameters.serviceName.c_str(), *parameters.region}
explicit AwsSigV4Signer(const Aws::String& serviceName, const Aws::String& region)
: m_serviceName(serviceName),
m_region(region),
legacySigner(nullptr, serviceName.c_str(), region, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Always)
{
}

Expand All @@ -45,7 +47,7 @@ namespace smithy {
bool signPayload = signPayloadIt != properties.end() ? signPayloadIt->second.get<Aws::String>() == "true" : false;

assert(httpRequest);
bool success = legacySigner.SignRequestWithCreds(*httpRequest, legacyCreds, m_parameters.region->c_str(), m_parameters.serviceName.c_str(), signPayload);
bool success = legacySigner.SignRequestWithCreds(*httpRequest, legacyCreds, m_region.c_str(), m_serviceName.c_str(), signPayload);
if (success)
{
return SigningFutureOutcome(std::move(httpRequest));
Expand All @@ -55,7 +57,8 @@ namespace smithy {

virtual ~AwsSigV4Signer() {};
protected:
SigV4AuthSchemeParameters m_parameters;
Aws::String m_serviceName;
Aws::String m_region;
Aws::Client::AWSAuthV4Signer legacySigner;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace smithy {

public:
using SigV4aAuthSchemeParameters = smithy::DefaultAuthSchemeResolverParameters;
explicit AwsSigV4aSigner(const SigV4aAuthSchemeParameters& parameters)
: m_parameters{parameters}
explicit AwsSigV4aSigner(const Aws::String& serviceName, const Aws::String& region)
: m_serviceName(serviceName), m_region(region)
{
}

Expand Down Expand Up @@ -136,8 +136,8 @@ namespace smithy {
{
awsSigningConfig.SetSigningAlgorithm(static_cast<Aws::Crt::Auth::SigningAlgorithm>(Aws::Auth::AWSSigningAlgorithm::ASYMMETRIC_SIGV4));
awsSigningConfig.SetSignatureType(m_signatureType);
awsSigningConfig.SetRegion((*m_parameters.region).c_str());
awsSigningConfig.SetService((m_parameters.serviceName).c_str());
awsSigningConfig.SetRegion(m_region.c_str());
awsSigningConfig.SetService(m_region.c_str());
awsSigningConfig.SetSigningTimepoint(GetSigningTimestamp().UnderlyingTimestamp());
awsSigningConfig.SetUseDoubleUriEncode(m_urlEscape);
awsSigningConfig.SetShouldNormalizeUriPath(true);
Expand Down Expand Up @@ -174,7 +174,7 @@ namespace smithy {
}
else if (m_signatureType == Aws::Crt::Auth::SignatureType::HttpRequestViaQueryParams)
{
if (ServiceRequireUnsignedPayload(m_parameters.serviceName))
if (ServiceRequireUnsignedPayload(m_serviceName))
{
awsSigningConfig.SetSignedBodyValue(UNSIGNED_PAYLOAD);
}
Expand Down Expand Up @@ -205,7 +205,8 @@ namespace smithy {
return "s3" == serviceName || "s3-object-lambda" == serviceName;
}

SigV4aAuthSchemeParameters m_parameters;
Aws::String m_serviceName;
Aws::String m_region;
//params that can be exposed later
long long m_expirationTimeInSeconds{0};
const bool m_includeSha256HashHeader{true};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ TEST_F(SmithyClientTest, testSigV4) {

Aws::UnorderedMap<Aws::String, SigVariant> authSchemesMap;

smithy::SigV4AuthScheme::SigV4AuthSchemeParameters params;
params.serviceName = "MyService";
params.region = "us-west2";
params.operation = "TestOperation";

Aws::String key{"aws.auth#sigv4"};

//add mock credentials provider for the test to the credentials provider chain
Expand All @@ -143,7 +138,7 @@ TEST_F(SmithyClientTest, testSigV4) {
//create resolver with the credentials provider chain
auto credentialsResolver = Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG, credsProviderChain);

SigVariant val{smithy::SigV4AuthScheme( credentialsResolver, params)};
SigVariant val{smithy::SigV4AuthScheme( credentialsResolver, "MyService", "us-west-2")};

authSchemesMap.emplace(key, val);

Expand Down Expand Up @@ -196,7 +191,7 @@ TEST_F(SmithyClientTest, testSigV4a) {
Aws::String key{"aws.auth#sigv4a"};
auto credentialsResolver = Aws::MakeShared<smithy::DefaultAwsCredentialIdentityResolver>(ALLOCATION_TAG, credsProviderChain);

SigVariant val{smithy::SigV4aAuthScheme(credentialsResolver, params)};
SigVariant val{smithy::SigV4aAuthScheme(credentialsResolver, "MyService", "us-west-2")};

authSchemesMap.emplace(key, val);

Expand Down

0 comments on commit 6dd34e1

Please sign in to comment.