@@ -38,12 +38,42 @@ namespace smithy
3838 using SigningError = Aws::Client::AWSError<Aws::Client::CoreErrors>;
3939 using SigningOutcome = Aws::Utils::FutureOutcome<std::shared_ptr<HttpRequest>, SigningError>;
4040 using HttpResponseOutcome = Aws::Utils::Outcome<std::shared_ptr<Aws::Http::HttpResponse>, Aws::Client::AWSError<Aws::Client::CoreErrors>>;
41+ using IdentityOutcome = Aws::Utils::Outcome<std::shared_ptr<smithy::AwsIdentity>, Aws::Client::AWSError<Aws::Client::CoreErrors>>;
4142
42- static SigningOutcome SignRequest (std::shared_ptr<HttpRequest> HTTPRequest, const AuthSchemeOption& authSchemeOption ,
43- const Aws::UnorderedMap<Aws::String, AuthSchemesVariantT>& authSchemes)
43+ static IdentityOutcome ResolveIdentity ( const client::AwsSmithyClientAsyncRequestContext& ctx ,
44+ const Aws::UnorderedMap<Aws::String, AuthSchemesVariantT>& authSchemes)
4445 {
46+ auto authSchemeIt = authSchemes.find (ctx.m_authSchemeOption .schemeId );
47+ if (authSchemeIt == authSchemes.end ())
48+ {
49+ assert (!" Auth scheme has not been found for a given auth option!" );
50+ return (SigningError (Aws::Client::CoreErrors::CLIENT_SIGNING_FAILURE,
51+ " " ,
52+ " Requested AuthSchemeOption was not found within client Auth Schemes" ,
53+ false /* retryable*/ ));
54+ }
4555
46- auto authSchemeIt = authSchemes.find (authSchemeOption.schemeId );
56+ const AuthSchemesVariantT& authScheme = authSchemeIt->second ;
57+ IdentityVisitor visitor (ctx);
58+ AuthSchemesVariantT authSchemesVariantCopy (authScheme); // TODO: allow const visiting
59+ authSchemesVariantCopy.Visit (visitor);
60+
61+ if (!visitor.result )
62+ {
63+ return (SigningError (Aws::Client::CoreErrors::CLIENT_SIGNING_FAILURE,
64+ " " ,
65+ " Failed to sign with an unknown error" ,
66+ false /* retryable*/ ));
67+ }
68+
69+ return std::move (*visitor.result );
70+ }
71+
72+ static SigningOutcome SignRequest (std::shared_ptr<HttpRequest> HTTPRequest,
73+ const client::AwsSmithyClientAsyncRequestContext& ctx,
74+ const Aws::UnorderedMap<Aws::String, AuthSchemesVariantT>& authSchemes)
75+ {
76+ auto authSchemeIt = authSchemes.find (ctx.m_authSchemeOption .schemeId );
4777 if (authSchemeIt == authSchemes.end ())
4878 {
4979 assert (!" Auth scheme has not been found for a given auth option!" );
@@ -55,8 +85,9 @@ namespace smithy
5585
5686 const AuthSchemesVariantT& authScheme = authSchemeIt->second ;
5787
58- return SignWithAuthScheme (std::move (HTTPRequest), authScheme, authSchemeOption );
88+ return SignWithAuthScheme (std::move (HTTPRequest), authScheme, ctx );
5989 }
90+
6091 static SigningOutcome PreSignRequest (std::shared_ptr<HttpRequest> httpRequest,
6192 const AuthSchemeOption& authSchemeOption,
6293 const Aws::UnorderedMap<Aws::String, AuthSchemesVariantT>& authSchemes,
@@ -113,59 +144,74 @@ namespace smithy
113144
114145
115146 protected:
147+ struct IdentityVisitor
148+ {
149+ IdentityVisitor (const client::AwsSmithyClientAsyncRequestContext& ctx): m_requestContext(ctx)
150+ {
151+ }
152+
153+ const client::AwsSmithyClientAsyncRequestContext& m_requestContext;
154+ Aws::Crt::Optional<IdentityOutcome> result;
155+
156+ template <typename AuthSchemeAlternativeT>
157+ void operator ()(AuthSchemeAlternativeT& authScheme)
158+ {
159+ using IdentityT = typename std::remove_reference<decltype (authScheme)>::type::IdentityT;
160+ using IdentityResolver = IdentityResolverBase<IdentityT>;
161+
162+ std::shared_ptr<IdentityResolver> identityResolver = authScheme.identityResolver ();
163+ if (!identityResolver)
164+ {
165+ result.emplace (SigningError (Aws::Client::CoreErrors::CLIENT_SIGNING_FAILURE,
166+ " " ,
167+ " Auth scheme provided a nullptr identityResolver" ,
168+ false /* retryable*/ ));
169+ return ;
170+ }
171+
172+ // relay service params in additional properties which will be relevant in credential resolution
173+ // example: bucket Name
174+ Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool >> additionalIdentityProperties;
175+ const auto & serviceSpecificParameters = m_requestContext.m_pRequest ->GetServiceSpecificParameters ();
176+ if (serviceSpecificParameters)
177+ {
178+ for (const auto & propPair : serviceSpecificParameters->parameterMap )
179+ {
180+ additionalIdentityProperties.emplace (propPair.first ,Aws::Crt::Variant<Aws::String, bool >{propPair.second } );
181+ }
182+ }
183+
184+ auto identityResult = identityResolver->getIdentity (m_requestContext.m_authSchemeOption .identityProperties (), additionalIdentityProperties);
185+ if (!identityResult.IsSuccess ())
186+ {
187+ result.emplace (identityResult.GetError ());
188+ return ;
189+ }
190+ result.emplace (std::move (identityResult.GetResultWithOwnership ()));
191+ }
192+ };
193+
116194 struct SignerVisitor
117195 {
118- SignerVisitor (std::shared_ptr<HttpRequest> httpRequest, const AuthSchemeOption& targetAuthSchemeOption )
119- : m_httpRequest(std::move(httpRequest)), m_targetAuthSchemeOption(targetAuthSchemeOption )
196+ SignerVisitor (std::shared_ptr<HttpRequest> httpRequest, const client::AwsSmithyClientAsyncRequestContext& ctx )
197+ : m_httpRequest(std::move(httpRequest)), m_requestContext(ctx )
120198 {
121199 }
122200
123201 const std::shared_ptr<HttpRequest> m_httpRequest;
124- const AuthSchemeOption& m_targetAuthSchemeOption ;
202+ const client::AwsSmithyClientAsyncRequestContext& m_requestContext ;
125203
126204 Aws::Crt::Optional<SigningOutcome> result;
127205
128206 template <typename AuthSchemeAlternativeT>
129207 void operator ()(AuthSchemeAlternativeT& authScheme)
130208 {
131209 // Auth Scheme Variant alternative contains the requested auth option
132- assert (strcmp (authScheme.schemeId , m_targetAuthSchemeOption .schemeId ) == 0 );
210+ assert (strcmp (authScheme.schemeId , m_requestContext. m_authSchemeOption .schemeId ) == 0 );
133211
134212 using IdentityT = typename std::remove_reference<decltype (authScheme)>::type::IdentityT;
135- using IdentityResolver = IdentityResolverBase<IdentityT>;
136213 using Signer = AwsSignerBase<IdentityT>;
137214
138- std::shared_ptr<IdentityResolver> identityResolver = authScheme.identityResolver ();
139- if (!identityResolver)
140- {
141- result.emplace (SigningError (Aws::Client::CoreErrors::CLIENT_SIGNING_FAILURE,
142- " " ,
143- " Auth scheme provided a nullptr identityResolver" ,
144- false /* retryable*/ ));
145- return ;
146- }
147-
148- // relay service params in additional properties which will be relevant in credential resolution
149- // example: bucket Name
150- Aws::UnorderedMap<Aws::String, Aws::Crt::Variant<Aws::String, bool >> additionalIdentityProperties;
151- const auto & serviceSpecificParameters = m_httpRequest->GetServiceSpecificParameters ();
152- if (serviceSpecificParameters)
153- {
154- for (const auto & propPair : serviceSpecificParameters->parameterMap )
155- {
156- additionalIdentityProperties.emplace (propPair.first ,Aws::Crt::Variant<Aws::String, bool >{propPair.second } );
157- }
158- }
159-
160- auto identityResult = identityResolver->getIdentity (m_targetAuthSchemeOption.identityProperties (), additionalIdentityProperties);
161-
162- if (!identityResult.IsSuccess ())
163- {
164- result.emplace (identityResult.GetError ());
165- return ;
166- }
167- auto identity = std::move (identityResult.GetResultWithOwnership ());
168-
169215 std::shared_ptr<Signer> signer = authScheme.signer ();
170216 if (!signer)
171217 {
@@ -176,7 +222,9 @@ namespace smithy
176222 return ;
177223 }
178224
179- result.emplace (signer->sign (m_httpRequest, *identity, m_targetAuthSchemeOption.signerProperties ()));
225+ result.emplace (signer->sign (m_httpRequest,
226+ *static_cast <IdentityT*>(m_requestContext.m_awsIdentity .get ()),
227+ m_requestContext.m_authSchemeOption .signerProperties ()));
180228 }
181229 };
182230
@@ -236,11 +284,11 @@ namespace smithy
236284 }
237285 };
238286
239- static
240- SigningOutcome SignWithAuthScheme (std::shared_ptr<HttpRequest> httpRequest, const AuthSchemesVariantT& authSchemesVariant,
241- const AuthSchemeOption& targetAuthSchemeOption )
287+ static SigningOutcome SignWithAuthScheme (std::shared_ptr<HttpRequest> httpRequest,
288+ const AuthSchemesVariantT& authSchemesVariant,
289+ const client::AwsSmithyClientAsyncRequestContext& ctx )
242290 {
243- SignerVisitor visitor (httpRequest, targetAuthSchemeOption );
291+ SignerVisitor visitor (httpRequest, ctx );
244292 AuthSchemesVariantT authSchemesVariantCopy (authSchemesVariant); // TODO: allow const visiting
245293 authSchemesVariantCopy.Visit (visitor);
246294
0 commit comments