@@ -300,8 +300,10 @@ def _classify_error(
300300 writer .consumer (w -> context .protocolGenerator ().wrapInputStream (context , w )),
301301 writer .consumer (w -> context .protocolGenerator ().wrapOutputStream (context , w )));
302302 }
303+
303304 writer .addStdlibImport ("typing" , "Any" );
304305 writer .addStdlibImport ("asyncio" , "iscoroutine" );
306+ writer .addImport ("smithy_core.auth" , "AuthParams" );
305307 writer .write (
306308 """
307309 async def _execute_operation[Input: SerializeableShape, Output: DeserializeableShape](
@@ -466,7 +468,6 @@ await sleep(retry_token.retry_delay)
466468 try:
467469 # Step 7a: Invoke read_before_attempt
468470 interceptor.read_before_attempt(context)
469-
470471 """ ,
471472 pluginSymbol ,
472473 transportRequest ,
@@ -476,53 +477,60 @@ await sleep(retry_token.retry_delay)
476477
477478 boolean supportsAuth = !ServiceIndex .of (model ).getAuthSchemes (service ).isEmpty ();
478479 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
492482
493483 writer .addDependency (SmithyPythonDependency .SMITHY_CORE );
494- writer .addDependency (SmithyPythonDependency .SMITHY_HTTP );
495484 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" );
497488 writer .addStdlibImport ("typing" , "Any" );
498489 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(
500496 auth_parameters=auth_parameters
501497 )
502- auth_option: HTTPAuthOption | None = None
498+
499+ auth_option: AuthOption | None = None
503500 for option in auth_options:
504- if option.scheme_id in config.http_auth_schemes :
501+ if option.scheme_id in config.auth_schemes :
505502 auth_option = option
506503 break
507504
508- signer: HTTPSigner[ Any, Any] | None = None
505+ signer: Signer[$2T, Any, Any] | None = None
509506 identity: Identity | None = None
507+ auth_scheme: Any = None
510508
511509 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
513512
514513 # 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
516516
517517 # 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
519525
520526 # Step 7e: Invoke identity_resolver.get_identity
521527 identity = await identity_resolver.get_identity(
522- identity_properties=auth_option. identity_properties
528+ identity_properties=identity_properties
523529 )
524530
525- """ );
531+ """ ,
532+ context .protocolGenerator ().getProtocol (),
533+ transportRequest );
526534 }
527535 writer .popState ();
528536
@@ -580,45 +588,29 @@ await sleep(retry_token.retry_delay)
580588 """ );
581589
582590 writer .pushState (new SignRequestSection ());
583- if (context . applicationProtocol (). isHttpProtocol () && supportsAuth ) {
591+ if (supportsAuth ) {
584592 writer .addStdlibImport ("re" );
585593 writer .addStdlibImport ("typing" , "Any" );
586594 writer .addImport ("smithy_core.interfaces.identity" , "Identity" );
587595 writer .addImport ("smithy_core.types" , "PropertyKey" );
588596 writer .write ("""
589597 # Step 7i: sign the request
590598 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+
596605 context = replace(
597606 context,
598- transport_request= await signer.sign(
599- http_request =context.transport_request,
607+ transport_request = await signer.sign(
608+ request =context.transport_request,
600609 identity=identity,
601- signing_properties=auth_option. signer_properties,
610+ properties= signer_properties,
602611 )
603612 )
604613 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
622614 """ );
623615 }
624616 writer .popState ();
@@ -788,28 +780,6 @@ private boolean hasEventStream() {
788780 return false ;
789781 }
790782
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-
813783 private void writeDefaultPlugins (PythonWriter writer , Collection <SymbolReference > plugins ) {
814784 for (SymbolReference plugin : plugins ) {
815785 writer .write ("$T," , plugin );
@@ -873,8 +843,8 @@ private void writeSharedOperationInit(PythonWriter writer, OperationShape operat
873843 .orElse ("The operation's input." );
874844
875845 writer .write ("""
876- $L
877- """ ,docs );
846+ $L
847+ """ , docs );
878848 writer .write ("" );
879849 writer .write (":param input: $L" , inputDocs );
880850 writer .write ("" );
0 commit comments