@@ -300,8 +300,10 @@ def _classify_error(
300
300
writer .consumer (w -> context .protocolGenerator ().wrapInputStream (context , w )),
301
301
writer .consumer (w -> context .protocolGenerator ().wrapOutputStream (context , w )));
302
302
}
303
+
303
304
writer .addStdlibImport ("typing" , "Any" );
304
305
writer .addStdlibImport ("asyncio" , "iscoroutine" );
306
+ writer .addImport ("smithy_core.auth" , "AuthParams" );
305
307
writer .write (
306
308
"""
307
309
async def _execute_operation[Input: SerializeableShape, Output: DeserializeableShape](
@@ -466,7 +468,6 @@ await sleep(retry_token.retry_delay)
466
468
try:
467
469
# Step 7a: Invoke read_before_attempt
468
470
interceptor.read_before_attempt(context)
469
-
470
471
""" ,
471
472
pluginSymbol ,
472
473
transportRequest ,
@@ -476,53 +477,60 @@ await sleep(retry_token.retry_delay)
476
477
477
478
boolean supportsAuth = !ServiceIndex .of (model ).getAuthSchemes (service ).isEmpty ();
478
479
writer .pushState (new ResolveIdentitySection ());
479
- if (context .applicationProtocol ().isHttpProtocol () && supportsAuth ) {
480
- writer .pushState (new InitializeHttpAuthParametersSection ());
481
- writer .write ("""
482
- # Step 7b: Invoke service_auth_scheme_resolver.resolve_auth_scheme
483
- auth_parameters: $1T = $1T(
484
- operation=operation.schema.id.name,
485
- ${2C|}
486
- )
487
-
488
- """ ,
489
- CodegenUtils .getHttpAuthParamsSymbol (context .settings ()),
490
- writer .consumer (this ::initializeHttpAuthParameters ));
491
- writer .popState ();
480
+ if (supportsAuth ) {
481
+ // TODO: delete InitializeHttpAuthParametersSection
492
482
493
483
writer .addDependency (SmithyPythonDependency .SMITHY_CORE );
494
- writer .addDependency (SmithyPythonDependency .SMITHY_HTTP );
495
484
writer .addImport ("smithy_core.interfaces.identity" , "Identity" );
496
- writer .addImports ("smithy_http.aio.interfaces.auth" , Set .of ("HTTPSigner" , "HTTPAuthOption" ));
485
+ writer .addImport ("smithy_core.interfaces.auth" , "AuthOption" );
486
+ writer .addImport ("smithy_core.aio.interfaces.auth" , "Signer" );
487
+ writer .addImport ("smithy_core.shapes" , "ShapeID" );
497
488
writer .addStdlibImport ("typing" , "Any" );
498
489
writer .write ("""
499
- auth_options = config.http_auth_scheme_resolver.resolve_auth_scheme(
490
+ auth_parameters = AuthParams(
491
+ protocol_id=ShapeID($1S),
492
+ operation=operation,
493
+ context=context.properties,
494
+ )
495
+ auth_options = config.auth_scheme_resolver.resolve_auth_scheme(
500
496
auth_parameters=auth_parameters
501
497
)
502
- auth_option: HTTPAuthOption | None = None
498
+
499
+ auth_option: AuthOption | None = None
503
500
for option in auth_options:
504
- if option.scheme_id in config.http_auth_schemes :
501
+ if option.scheme_id in config.auth_schemes :
505
502
auth_option = option
506
503
break
507
504
508
- signer: HTTPSigner[ Any, Any] | None = None
505
+ signer: Signer[$2T, Any, Any] | None = None
509
506
identity: Identity | None = None
507
+ auth_scheme: Any = None
510
508
511
509
if auth_option:
512
- auth_scheme = config.http_auth_schemes[auth_option.scheme_id]
510
+ auth_scheme = config.auth_schemes[auth_option.scheme_id]
511
+ context.properties["auth_scheme"] = auth_scheme
513
512
514
513
# Step 7c: Invoke auth_scheme.identity_resolver
515
- identity_resolver = auth_scheme.identity_resolver(config=config)
514
+ identity_resolver = auth_scheme.identity_resolver(context=context.properties)
515
+ context.properties["identity_resolver"] = identity_resolver
516
516
517
517
# Step 7d: Invoke auth_scheme.signer
518
- signer = auth_scheme.signer
518
+ signer = auth_scheme.signer()
519
+
520
+ # TODO: merge from auth_option
521
+ identity_properties = auth_scheme.identity_properties(
522
+ context=context.properties
523
+ )
524
+ context.properties["identity_properties"] = identity_properties
519
525
520
526
# Step 7e: Invoke identity_resolver.get_identity
521
527
identity = await identity_resolver.get_identity(
522
- identity_properties=auth_option. identity_properties
528
+ identity_properties=identity_properties
523
529
)
524
530
525
- """ );
531
+ """ ,
532
+ context .protocolGenerator ().getProtocol (),
533
+ transportRequest );
526
534
}
527
535
writer .popState ();
528
536
@@ -580,45 +588,29 @@ await sleep(retry_token.retry_delay)
580
588
""" );
581
589
582
590
writer .pushState (new SignRequestSection ());
583
- if (context . applicationProtocol (). isHttpProtocol () && supportsAuth ) {
591
+ if (supportsAuth ) {
584
592
writer .addStdlibImport ("re" );
585
593
writer .addStdlibImport ("typing" , "Any" );
586
594
writer .addImport ("smithy_core.interfaces.identity" , "Identity" );
587
595
writer .addImport ("smithy_core.types" , "PropertyKey" );
588
596
writer .write ("""
589
597
# Step 7i: sign the request
590
598
if auth_option and signer:
591
- logger.debug("HTTP request to sign: %s", context.transport_request)
592
- logger.debug(
593
- "Signer properties: %s",
594
- auth_option.signer_properties
595
- )
599
+ signer_properties = auth_scheme.signer_properties(context=context.properties)
600
+ context.properties["signer_properties"] = signer_properties
601
+
602
+ logger.debug("Request to sign: %s", context.transport_request)
603
+ logger.debug("Signer properties: %s", signer_properties)
604
+
596
605
context = replace(
597
606
context,
598
- transport_request= await signer.sign(
599
- http_request =context.transport_request,
607
+ transport_request = await signer.sign(
608
+ request =context.transport_request,
600
609
identity=identity,
601
- signing_properties=auth_option. signer_properties,
610
+ properties= signer_properties,
602
611
)
603
612
)
604
613
logger.debug("Signed HTTP request: %s", context.transport_request)
605
-
606
- # TODO - Move this to separate resolution/population function
607
- fields = context.transport_request.fields
608
- auth_value = fields["Authorization"].as_string() # type: ignore
609
- signature = re.split("Signature=", auth_value)[-1] # type: ignore
610
- context.properties["signature"] = signature.encode('utf-8')
611
-
612
- identity_key: PropertyKey[Identity | None] = PropertyKey(
613
- key="identity",
614
- value_type=Identity | None # type: ignore
615
- )
616
- sp_key: PropertyKey[dict[str, Any]] = PropertyKey(
617
- key="signer_properties",
618
- value_type=dict[str, Any] # type: ignore
619
- )
620
- context.properties[identity_key] = identity
621
- context.properties[sp_key] = auth_option.signer_properties
622
614
""" );
623
615
}
624
616
writer .popState ();
@@ -788,28 +780,6 @@ private boolean hasEventStream() {
788
780
return false ;
789
781
}
790
782
791
- private void initializeHttpAuthParameters (PythonWriter writer ) {
792
- var derived = new LinkedHashSet <DerivedProperty >();
793
- for (PythonIntegration integration : context .integrations ()) {
794
- for (RuntimeClientPlugin plugin : integration .getClientPlugins (context )) {
795
- if (plugin .matchesService (model , service )
796
- && plugin .getAuthScheme ().isPresent ()
797
- && plugin .getAuthScheme ().get ().getApplicationProtocol ().isHttpProtocol ()) {
798
- derived .addAll (plugin .getAuthScheme ().get ().getAuthProperties ());
799
- }
800
- }
801
- }
802
-
803
- for (DerivedProperty property : derived ) {
804
- var source = property .source ().scopeLocation ();
805
- if (property .initializationFunction ().isPresent ()) {
806
- writer .write ("$L=$T($L)," , property .name (), property .initializationFunction ().get (), source );
807
- } else if (property .sourcePropertyName ().isPresent ()) {
808
- writer .write ("$L=$L.$L," , property .name (), source , property .sourcePropertyName ().get ());
809
- }
810
- }
811
- }
812
-
813
783
private void writeDefaultPlugins (PythonWriter writer , Collection <SymbolReference > plugins ) {
814
784
for (SymbolReference plugin : plugins ) {
815
785
writer .write ("$T," , plugin );
@@ -873,8 +843,8 @@ private void writeSharedOperationInit(PythonWriter writer, OperationShape operat
873
843
.orElse ("The operation's input." );
874
844
875
845
writer .write ("""
876
- $L
877
- """ ,docs );
846
+ $L
847
+ """ , docs );
878
848
writer .write ("" );
879
849
writer .write (":param input: $L" , inputDocs );
880
850
writer .write ("" );
0 commit comments