Skip to content

Commit 6a2cf3f

Browse files
Pseudocode for S3 resolve auth with embedded endpoint provider
1 parent 040638e commit 6a2cf3f

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ namespace client
107107
protected:
108108
void initClient() {
109109
m_endpointProvider->InitBuiltInParameters(m_clientConfiguration);
110+
m_authSchemeResolver->Init(m_clientConfiguration);
110111
}
111112

112113
inline const char* GetServiceClientName() const override { return m_serviceName.c_str(); }

src/aws-cpp-sdk-core/include/smithy/identity/auth/AuthSchemeResolverBase.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ namespace smithy {
2929

3030
};
3131

32-
template<typename ServiceAuthSchemeParametersT = DefaultAuthSchemeResolverParameters>
32+
template<typename ServiceAuthSchemeParametersT = DefaultAuthSchemeResolverParameters, typename ClientConfigT = Aws::Client::ClientConfiguration>
3333
class AuthSchemeResolverBase
3434
{
3535
public:
3636
using ServiceAuthSchemeParameters = ServiceAuthSchemeParametersT;
3737

38+
virtual void Init(const ClientConfigT& config) {
39+
AWS_UNREFERENCED_PARAM(config);
40+
};
41+
3842
virtual ~AuthSchemeResolverBase() = default;
3943
// AuthScheme Resolver returns a list of AuthSchemeOptions for some reason, according to the SRA...
4044
virtual Aws::Vector<AuthSchemeOption> resolveAuthScheme(const ServiceAuthSchemeParameters& identityProperties) = 0;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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/auth/AuthSchemeResolverBase.h>
8+
#include <smithy/identity/auth/built-in/SigV4aAuthSchemeOption.h>
9+
10+
// psuedocode draft, must be in S3 package
11+
namespace smithy {
12+
template<>
13+
class S3AuthSchemeResolver : public AuthSchemeResolverBase<DefaultAuthSchemeResolverParameters, Aws::S3::S3ClientConfiguration>
14+
{
15+
public:
16+
using ServiceAuthSchemeParameters = DefaultAuthSchemeResolverParameters;
17+
virtual ~S3AuthSchemeResolver() = default;
18+
19+
virtual void Init(const Aws::S3::S3ClientConfiguration& config) {
20+
m_endpointProviderForAuth = Aws::MakeShared<S3EndpointProvider>(ALLOCATION_TAG);
21+
m_endpointProviderForAuth->InitBuiltInParameters(config);
22+
AWS_UNREFERENCED_PARAM(config);
23+
};
24+
25+
26+
Aws::Vector<AuthSchemeOption> resolveAuthScheme(const ServiceAuthSchemeParameters& identityProperties) override
27+
{
28+
// design step 2: skip an additional endpoint resolution call if we know the operation is always the same auth
29+
auto operationNameIt = identityProperties.find("OperationName");
30+
if (operationNameIt != identityProperties.end()) {
31+
auto knownStaticAuthSchemeOption = knownStaticOperations.find(*operationNameIt);
32+
if (knownStaticAuthSchemeOption != knownStaticOperations.end()) {
33+
return {knownStaticAuthSchemeOption.second};
34+
}
35+
}
36+
37+
Aws::Endpoint::EndpointParameters epParams = MapIdentityPropsToEpParams(identityProperties);
38+
auto resolveEpOutcome = m_endpointProviderForAuth->ResolveEndpoint(epParams);
39+
if (!resolveEpOutcome.IsSuccess()) {
40+
TRACE_ERR();
41+
return {};
42+
}
43+
44+
Aws::Vector<AuthSchemeOption> authSchemeOptions = BuildAuthSchemeOptionListFromEndpointResolution(resolveEpOutcome.GetResult());
45+
46+
return authSchemeOptions;
47+
}
48+
};
49+
50+
private:
51+
std::shared_ptr<S3EndpointProviderBase> m_endpointProviderForAuth;
52+
53+
// design step 2: skip an additional endpoint resolution call if we know the operation is always the same auth
54+
UnorderedMap<String, String> knownStaticOperations;
55+
56+
}

0 commit comments

Comments
 (0)