Skip to content

Commit e3110b5

Browse files
committed
Add noAuthIdentityResolver instead of nullptr, fix include headers
1 parent 23a60d3 commit e3110b5

File tree

11 files changed

+82
-31
lines changed

11 files changed

+82
-31
lines changed

src/aws-cpp-sdk-core/include/aws/core/auth/AWSAuthSigner.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,4 @@
1111
#include <aws/core/auth/signer/AWSAuthV4Signer.h>
1212
#include <aws/core/auth/signer/AWSAuthEventStreamV4Signer.h>
1313
#include <aws/core/auth/signer/AWSNullSigner.h>
14-
15-
#include <smithy/identity/auth/built-in/NoAuthScheme.h>
16-
#include <smithy/identity/auth/built-in/NoAuthSchemeOption.h>
17-
1814
// This is a header that represents old legacy all-in-one header to maintain backward compatibility

src/aws-cpp-sdk-core/include/smithy/client/AwsSmithyClient.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,15 @@ namespace client
352352

353353
GetContextEndpointParametersOutcome GetContextEndpointParametersImpl(const AwsSmithyClientAsyncRequestContext& ctx) const {
354354
Aws::Vector<Aws::Endpoint::EndpointParameter> endpointParameters;
355-
//nullptr indicates we're using noAuth and therefore there is no identity
356-
if (ctx.m_awsIdentity != nullptr) {
357-
const auto resolvedAccountId = ctx.m_awsIdentity->accountId();
358-
const auto resolvedNonEmptyAccountId = resolvedAccountId.has_value() && !resolvedAccountId.value().empty();
359-
// Set user agent if account ID was resolved in identity provider
360-
if (resolvedNonEmptyAccountId) {
361-
ctx.m_pRequest->AddUserAgentFeature(Aws::Client::UserAgentFeature::RESOLVED_ACCOUNT_ID);
362-
}
363-
// Only set EP param if client configuration does not have a configured account ID and we resolved a account id
364-
if (resolvedNonEmptyAccountId && m_clientConfiguration.accountId.empty()) {
365-
endpointParameters.emplace_back("AccountId", resolvedAccountId.value(), Aws::Endpoint::EndpointParameter::ParameterOrigin::OPERATION_CONTEXT);
366-
}
355+
const auto resolvedAccountId = ctx.m_awsIdentity->accountId();
356+
const auto resolvedNonEmptyAccountId = resolvedAccountId.has_value() && !resolvedAccountId.value().empty();
357+
// Set user agent if account ID was resolved in identity provider
358+
if (resolvedNonEmptyAccountId) {
359+
ctx.m_pRequest->AddUserAgentFeature(Aws::Client::UserAgentFeature::RESOLVED_ACCOUNT_ID);
360+
}
361+
// Only set EP param if client configuration does not have a configured account ID and we resolved a account id
362+
if (resolvedNonEmptyAccountId && m_clientConfiguration.accountId.empty()) {
363+
endpointParameters.emplace_back("AccountId", resolvedAccountId.value(), Aws::Endpoint::EndpointParameter::ParameterOrigin::OPERATION_CONTEXT);
367364
}
368365
return endpointParameters;
369366
}

src/aws-cpp-sdk-core/include/smithy/identity/auth/built-in/NoAuthScheme.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <smithy/identity/identity/AwsCredentialIdentityBase.h>
1111
#include <smithy/identity/signer/built-in/NoAuthSigner.h>
12+
#include <smithy/identity/resolver/built-in/NoAuthIdentityResolver.h>
1213

1314
namespace smithy {
1415
constexpr char NOAUTH[] = "smithy.api#noAuth";
@@ -21,48 +22,55 @@ namespace smithy {
2122

2223
explicit NoAuthScheme()
2324
: AuthScheme(NOAUTH),
24-
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")}
25+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")},
26+
m_identityResolver{Aws::MakeShared<NoAuthIdentityResolver>("NoAuthScheme")}
2527
{
2628
assert(m_signer);
29+
assert(m_identityResolver);
2730
}
2831

2932
explicit NoAuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver,
3033
const Aws::String& serviceName,
3134
const Aws::String& region)
3235
: AuthScheme(NOAUTH),
33-
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")}
36+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")},
37+
m_identityResolver{Aws::MakeShared<NoAuthIdentityResolver>("NoAuthScheme")}
3438
{
3539
AWS_UNREFERENCED_PARAM(identityResolver);
3640
AWS_UNREFERENCED_PARAM(serviceName);
3741
AWS_UNREFERENCED_PARAM(region);
3842
assert(m_signer);
43+
assert(m_identityResolver);
3944
}
4045

4146
explicit NoAuthScheme(const Aws::String& serviceName,
4247
const Aws::String& region)
4348
: NoAuthScheme(nullptr, serviceName, region)
4449
{
4550
assert(m_signer);
51+
assert(m_identityResolver);
4652
}
4753

4854
//legacy constructors
4955
explicit NoAuthScheme(std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver, const Aws::String& serviceName, const Aws::String& region, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy policy, bool urlEscape)
5056
: AuthScheme(NOAUTH),
51-
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")}
57+
m_signer{Aws::MakeShared<AwsNoAuthSigner>("NoAuthScheme")},
58+
m_identityResolver{Aws::MakeShared<NoAuthIdentityResolver>("NoAuthScheme")}
5259
{
5360
AWS_UNREFERENCED_PARAM(identityResolver);
5461
AWS_UNREFERENCED_PARAM(serviceName);
5562
AWS_UNREFERENCED_PARAM(region);
5663
AWS_UNREFERENCED_PARAM(policy);
5764
AWS_UNREFERENCED_PARAM(urlEscape);
5865
assert(m_signer);
66+
assert(m_identityResolver);
5967
}
6068

6169
virtual ~NoAuthScheme() = default;
6270

6371
std::shared_ptr<AwsCredentialIdentityResolverT> identityResolver() override
6472
{
65-
return nullptr;
73+
return m_identityResolver;
6674
}
6775

6876
std::shared_ptr<AwsCredentialSignerT> signer() override
@@ -72,5 +80,6 @@ namespace smithy {
7280

7381
protected:
7482
std::shared_ptr<AwsCredentialSignerT> m_signer;
83+
std::shared_ptr<AwsCredentialIdentityResolverT> m_identityResolver;
7584
};
7685
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
#pragma once
6+
7+
#include <smithy/identity/resolver/AwsCredentialIdentityResolver.h>
8+
9+
#include <aws/core/auth/AWSCredentials.h>
10+
11+
namespace smithy {
12+
/**
13+
* A no-auth identity resolver that returns empty credentials for unauthenticated requests
14+
*/
15+
class NoAuthIdentityResolver : public AwsCredentialIdentityResolver {
16+
public:
17+
NoAuthIdentityResolver() = default;
18+
virtual ~NoAuthIdentityResolver() = default;
19+
20+
ResolveIdentityFutureOutcome getIdentity(const IdentityProperties& identityProperties, const AdditionalParameters& additionalParameters) override
21+
{
22+
AWS_UNREFERENCED_PARAM(identityProperties);
23+
AWS_UNREFERENCED_PARAM(additionalParameters);
24+
25+
auto smithyCreds = Aws::MakeUnique<AwsCredentialIdentity>("NoAuthIdentityResolver");
26+
// Return empty identity for no-auth scenarios
27+
return {std::move(smithyCreds)};
28+
}
29+
};
30+
}

src/aws-cpp-sdk-core/source/smithy/client/AwsSmithyClientBase.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,14 @@ bool AwsSmithyClientBase::ResolveIdentityAuth(
195195
assert(pRequestCtx->m_authSchemeOption.schemeId);
196196

197197
// resolve identity
198-
if (strcmp(authSchemeOptionOutcome.GetResult().schemeId, smithy::NOAUTH) != 0) {
199-
auto identityOutcome = this->ResolveIdentity(*pRequestCtx);
200-
if (!identityOutcome.IsSuccess())
201-
{
202-
responseHandler(std::move(identityOutcome));
203-
return false;
204-
}
205-
pRequestCtx->m_awsIdentity = std::move(identityOutcome.GetResultWithOwnership());
198+
auto identityOutcome = this->ResolveIdentity(*pRequestCtx);
199+
if (!identityOutcome.IsSuccess())
200+
{
201+
responseHandler(std::move(identityOutcome));
202+
return false;
206203
}
204+
pRequestCtx->m_awsIdentity = std::move(identityOutcome.GetResultWithOwnership());
205+
207206

208207

209208
// get endpoint params from operation context

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/domainmodels/codegeneration/Operation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public boolean hasSigV4aAuth() {
102102
return auth != null && auth.contains("aws.auth#sigv4a");
103103
}
104104

105+
public boolean hasNoAuth() {
106+
return auth != null && auth.contains("smithy.api#noAuth");
107+
}
108+
105109
public boolean hasBearerAuth() {
106110
return auth != null && auth.contains("smithy.api#httpBearerAuth");
107111
}

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/domainmodels/codegeneration/ServiceModel.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,22 @@ public boolean hasSigV4Auth() {
5151
if(metadata.getSignatureVersion().equals("v4") || metadata.getSignatureVersion().equals("s3v4")) {
5252
return true;
5353
}
54-
return authSchemes.contains("aws.auth#sigv4") || operations.values().parallelStream().anyMatch(operation -> operation.getSignerName().equals("Aws::Auth::SIGV4_SIGNER"));
54+
return authSchemes.contains("aws.auth#sigv4") || operations.values().parallelStream().anyMatch(operation -> operation.getSignerName().equals("Aws::Auth::SIGV4_SIGNER") || operation.hasSigV4Auth());
5555
}
5656

5757
public boolean hasSigV4aAuth() {
58-
return authSchemes.contains("aws.auth#sigv4a") || operations.values().parallelStream().anyMatch(operation -> operation.getSignerName().equals("Aws::Auth::SIGV4A_SIGNER"));
58+
return authSchemes.contains("aws.auth#sigv4a") || operations.values().parallelStream().anyMatch(operation -> operation.getSignerName().equals("Aws::Auth::SIGV4A_SIGNER") || operation.hasSigV4aAuth());
59+
}
60+
61+
public boolean hasNoAuth() {
62+
return authSchemes.contains("smithy.api#noAuth") || operations.values().parallelStream().anyMatch(operation -> operation.getSignerName().equals("Aws::Auth::NULL_SIGNER") || operation.hasNoAuth());
5963
}
6064

6165
public boolean hasBearerAuth() {
6266
if(metadata.getSignatureVersion().equals("bearer")) {
6367
return true;
6468
}
65-
return authSchemes.contains("smithy.api#httpBearerAuth") || operations.values().parallelStream().anyMatch(operation -> operation.getSignerName().equals("Aws::Auth::BEARER_SIGNER"));
69+
return authSchemes.contains("smithy.api#httpBearerAuth") || operations.values().parallelStream().anyMatch(operation -> operation.getSignerName().equals("Aws::Auth::BEARER_SIGNER") || operation.hasBearerAuth());
6670
}
6771

6872
public boolean hasOnlyBearerAuth() {

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborRequestSource.vm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#if($operation.hasBearerAuth())
2525
\#include <smithy/identity/auth/built-in/BearerTokenAuthSchemeOption.h>
2626
#end
27+
#if($operation.hasNoAuth())
28+
\#include <smithy/identity/auth/built-in/NoAuthScheme.h>
29+
#end
2730
#end ###if($serviceModel.useSmithyClient)
2831

2932
\#include <utility>

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/json/JsonRequestSource.vm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#if($operation.hasBearerAuth())
2525
\#include <smithy/identity/auth/built-in/BearerTokenAuthSchemeOption.h>
2626
#end
27+
#if($operation.hasNoAuth())
28+
\#include <smithy/identity/auth/built-in/NoAuthScheme.h>
29+
#end
2730
#end ###if($serviceModel.useSmithyClient)
2831
\#include <utility>
2932
#if(${CppViewHelper.hasListMemberUsedForHeader($shape)})

tools/code-generation/generator/src/main/resources/com/amazonaws/util/awsclientgenerator/velocity/cpp/smithy/SmithyClientHeader.vm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#if($serviceModel.hasSigV4aAuth())
2828
\#include <smithy/identity/auth/built-in/SigV4aAuthScheme.h>
2929
#end
30+
#if($serviceModel.hasNoAuth())
31+
\#include <smithy/identity/auth/built-in/NoAuthScheme.h>
32+
#end
3033
\#include <smithy/identity/auth/built-in/GenericAuthSchemeResolver.h>
3134
\#include <smithy/client/serializer/${serializer}.h>
3235
\#include <aws/${metadata.projectName}/${metadata.classNamePrefix}ErrorMarshaller.h>

0 commit comments

Comments
 (0)