AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
AwsSmithyClient.h
1
5#pragma once
6
7#include <smithy/client/AwsSmithyClientBase.h>
8#include <smithy/client/AwsSmithyClientAsyncRequestContext.h>
9#include <smithy/client/common/AwsSmithyRequestSigning.h>
10#include <smithy/identity/identity/AwsIdentity.h>
11#include <smithy/identity/auth/AuthSchemeOption.h>
12#include <smithy/identity/auth/AuthSchemeResolverBase.h>
13#include <smithy/tracing/TelemetryProvider.h>
14
15#include <aws/crt/Variant.h>
16
17#include <aws/core/client/ClientConfiguration.h>
18#include <aws/core/http/HttpResponse.h>
19#include <aws/core/utils/memory/stl/AWSMap.h>
20#include <aws/core/utils/FutureOutcome.h>
21#include <aws/core/utils/Outcome.h>
22
23namespace smithy {
24namespace client
25{
26 template<const char* ServiceNameT,
27 typename ServiceClientConfigurationT,
28 typename ServiceAuthSchemeResolverT,
29 typename AuthSchemesVariantT,
30 typename EndpointProviderT,
31 typename SerializerT,
32 typename ResponseT>
34 {
35 public:
36 explicit AwsSmithyClientT(const ServiceClientConfigurationT& clientConfig, const Aws::String& serviceName,
37 const std::shared_ptr<Aws::Http::HttpClient>& httpClient,
38 const std::shared_ptr<Aws::Client::AWSErrorMarshaller>& errorMarshaller,
39 const std::shared_ptr<EndpointProviderT> endpointProvider,
40 const std::shared_ptr<ServiceAuthSchemeResolverT>& authSchemeResolver,
42 : AwsSmithyClientBase(Aws::MakeUnique<ServiceClientConfigurationT>(ServiceNameT, clientConfig), serviceName, httpClient, errorMarshaller),
43 m_clientConfiguration(*static_cast<ServiceClientConfigurationT*>(AwsSmithyClientBase::m_clientConfig.get())),
44 m_endpointProvider(endpointProvider),
45 m_authSchemeResolver(authSchemeResolver),
46 m_authSchemes(authSchemes),
47 m_serializer(Aws::MakeUnique<SerializerT>(ServiceNameT, m_clientConfiguration.telemetryProvider))
48 {
49 m_serviceName = ServiceNameT;
50 }
51
52 virtual ~AwsSmithyClientT() = default;
53
54 protected:
55 inline const char* GetServiceClientName() const override { return m_serviceName.c_str(); }
56
58 {
59 assert(m_endpointProvider);
60 ResolveEndpointOutcome resolveEndpointOutcome = m_endpointProvider->ResolveEndpoint(endpointParameters);
61 if (resolveEndpointOutcome.IsSuccess())
62 {
63 epCallback(resolveEndpointOutcome.GetResult());
64 }
65 return resolveEndpointOutcome;
66 }
67
69 {
71 typename ServiceAuthSchemeResolverT::ServiceAuthSchemeParameters identityParams;
72
73 identityParams.serviceName = m_serviceName;
74 identityParams.operation = ctx.m_requestName;
75 identityParams.region = m_clientConfiguration.region;
76
77 if (ctx.m_pRequest) {
78 // refactor once auth scheme resolver will use it's own rule set
79 const auto& epParams = ctx.m_pRequest->GetEndpointContextParams();
80 for (const auto& epParam : epParams) {
82 if(epParam.GetStoredType() == ParameterType::STRING)
83 identityParams.additionalProperties.insert({epParam.GetName(), epParam.GetStrValueNoCheck()});
84 else if (epParam.GetStoredType() == ParameterType::BOOLEAN)
85 identityParams.additionalProperties.insert({epParam.GetName(), epParam.GetBoolValueNoCheck()});
86 else
87 assert(!"Unknown endpoint parameter!");
88 }
89 const auto& serviceParams = ctx.m_pRequest->GetServiceSpecificParameters();
90 if (serviceParams) {
91 for (const auto& serviceParam : serviceParams->parameterMap) {
92 identityParams.additionalProperties.insert({serviceParam.first, serviceParam.second});
93 }
94 }
95 }
96 Aws::Vector<AuthSchemeOption> authSchemeOptions = m_authSchemeResolver->resolveAuthScheme(identityParams);
97
98 auto authSchemeOptionIt = std::find_if(authSchemeOptions.begin(), authSchemeOptions.end(),
99 [this](const AuthSchemeOption& opt)
100 {
101 return m_authSchemes.find(opt.schemeId) != m_authSchemes.end();
102 });
103 assert(authSchemeOptionIt != authSchemeOptions.end());
104
105 if (authSchemeOptionIt != authSchemeOptions.end()) {
106 return SelectAuthSchemeOptionOutcome(*authSchemeOptionIt);
107 }
109 "",
110 "Failed to select an auth scheme",
111 false/*retryable*/);
112 }
113
114 SigningOutcome SignRequest(std::shared_ptr<HttpRequest> httpRequest, const AuthSchemeOption& targetAuthSchemeOption) const override
115 {
116 return AwsClientRequestSigning<AuthSchemesVariantT>::SignRequest(httpRequest, targetAuthSchemeOption, m_authSchemes);
117 }
118
119 bool AdjustClockSkew(HttpResponseOutcome& outcome, const AuthSchemeOption& authSchemeOption) const override
120 {
121 return AwsClientRequestSigning<AuthSchemesVariantT>::AdjustClockSkew(outcome, authSchemeOption, m_authSchemes);
122 }
123
125 const char* requestName,
127 EndpointUpdateCallback&& endpointCallback) const
128 {
129 auto httpResponseOutcome = MakeRequestSync(request, requestName, method, std::move(endpointCallback));
130 return m_serializer->Deserialize(std::move(httpResponseOutcome), GetServiceClientName(), requestName);
131 }
132
133 protected:
134 ServiceClientConfigurationT& m_clientConfiguration;
135 std::shared_ptr<EndpointProviderT> m_endpointProvider{};
136 std::shared_ptr<ServiceAuthSchemeResolverT> m_authSchemeResolver{};
139 };
140
141} // namespace client
142} // namespace smithy
virtual EndpointParameters GetEndpointContextParams() const
bool IsSuccess() const
Definition Outcome.h:161
const R & GetResult() const
Definition Outcome.h:131
static SigningOutcome SignRequest(std::shared_ptr< HttpRequest > HTTPRequest, const AuthSchemeOption &authSchemeOption, const Aws::UnorderedMap< Aws::String, AuthSchemesVariantT > &authSchemes)
static bool AdjustClockSkew(HttpResponseOutcome &outcome, const AuthSchemeOption &authSchemeOption, const Aws::UnorderedMap< Aws::String, AuthSchemesVariantT > &authSchemes)
Aws::UniquePtr< Aws::Client::ClientConfiguration > m_clientConfig
std::function< void(Aws::Endpoint::AWSEndpoint &)> EndpointUpdateCallback
ServiceClientConfigurationT & m_clientConfiguration
virtual ~AwsSmithyClientT()=default
SigningOutcome SignRequest(std::shared_ptr< HttpRequest > httpRequest, const AuthSchemeOption &targetAuthSchemeOption) const override
std::shared_ptr< EndpointProviderT > m_endpointProvider
SelectAuthSchemeOptionOutcome SelectAuthSchemeOption(const AwsSmithyClientAsyncRequestContext &ctx) const override
Aws::UniquePtr< SerializerT > m_serializer
bool AdjustClockSkew(HttpResponseOutcome &outcome, const AuthSchemeOption &authSchemeOption) const override
Aws::UnorderedMap< Aws::String, AuthSchemesVariantT > m_authSchemes
std::shared_ptr< ServiceAuthSchemeResolverT > m_authSchemeResolver
AwsSmithyClientT(const ServiceClientConfigurationT &clientConfig, const Aws::String &serviceName, const std::shared_ptr< Aws::Http::HttpClient > &httpClient, const std::shared_ptr< Aws::Client::AWSErrorMarshaller > &errorMarshaller, const std::shared_ptr< EndpointProviderT > endpointProvider, const std::shared_ptr< ServiceAuthSchemeResolverT > &authSchemeResolver, const Aws::UnorderedMap< Aws::String, AuthSchemesVariantT > &authSchemes)
const char * GetServiceClientName() const override
ResponseT MakeRequestDeserialize(Aws::AmazonWebServiceRequest const *const request, const char *requestName, Aws::Http::HttpMethod method, EndpointUpdateCallback &&endpointCallback) const
ResolveEndpointOutcome ResolveEndpoint(const Aws::Endpoint::EndpointParameters &endpointParameters, EndpointUpdateCallback &&epCallback) const override
Aws::Vector< Aws::Endpoint::EndpointParameter > EndpointParameters
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
std::vector< T, Aws::Allocator< T > > Vector
Definition AWSVector.h:17
std::unique_ptr< T, D > UniquePtr
Definition AWSMemory.h:255
std::unordered_map< K, V, std::hash< K >, std::equal_to< K >, Aws::Allocator< std::pair< const K, V > > > UnorderedMap
Definition AWSMap.h:21
Aws::Client::AWSError< CoreErrors > AWSError