@@ -38,12 +38,42 @@ namespace smithy
38
38
using SigningError = Aws::Client::AWSError<Aws::Client::CoreErrors>;
39
39
using SigningOutcome = Aws::Utils::FutureOutcome<std::shared_ptr<HttpRequest>, SigningError>;
40
40
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>>;
41
42
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)
44
45
{
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
+ }
45
55
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 );
47
77
if (authSchemeIt == authSchemes.end ())
48
78
{
49
79
assert (!" Auth scheme has not been found for a given auth option!" );
@@ -55,8 +85,9 @@ namespace smithy
55
85
56
86
const AuthSchemesVariantT& authScheme = authSchemeIt->second ;
57
87
58
- return SignWithAuthScheme (std::move (HTTPRequest), authScheme, authSchemeOption );
88
+ return SignWithAuthScheme (std::move (HTTPRequest), authScheme, ctx );
59
89
}
90
+
60
91
static SigningOutcome PreSignRequest (std::shared_ptr<HttpRequest> httpRequest,
61
92
const AuthSchemeOption& authSchemeOption,
62
93
const Aws::UnorderedMap<Aws::String, AuthSchemesVariantT>& authSchemes,
@@ -113,59 +144,74 @@ namespace smithy
113
144
114
145
115
146
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
+
116
194
struct SignerVisitor
117
195
{
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 )
120
198
{
121
199
}
122
200
123
201
const std::shared_ptr<HttpRequest> m_httpRequest;
124
- const AuthSchemeOption& m_targetAuthSchemeOption ;
202
+ const client::AwsSmithyClientAsyncRequestContext& m_requestContext ;
125
203
126
204
Aws::Crt::Optional<SigningOutcome> result;
127
205
128
206
template <typename AuthSchemeAlternativeT>
129
207
void operator ()(AuthSchemeAlternativeT& authScheme)
130
208
{
131
209
// 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 );
133
211
134
212
using IdentityT = typename std::remove_reference<decltype (authScheme)>::type::IdentityT;
135
- using IdentityResolver = IdentityResolverBase<IdentityT>;
136
213
using Signer = AwsSignerBase<IdentityT>;
137
214
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
-
169
215
std::shared_ptr<Signer> signer = authScheme.signer ();
170
216
if (!signer)
171
217
{
@@ -176,7 +222,9 @@ namespace smithy
176
222
return ;
177
223
}
178
224
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 ()));
180
228
}
181
229
};
182
230
@@ -236,11 +284,11 @@ namespace smithy
236
284
}
237
285
};
238
286
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 )
242
290
{
243
- SignerVisitor visitor (httpRequest, targetAuthSchemeOption );
291
+ SignerVisitor visitor (httpRequest, ctx );
244
292
AuthSchemesVariantT authSchemesVariantCopy (authSchemesVariant); // TODO: allow const visiting
245
293
authSchemesVariantCopy.Visit (visitor);
246
294
0 commit comments