@@ -256,9 +256,11 @@ private void generateOperationExecutor(PythonWriter writer) {
256256 writer .consumer (w -> context .protocolGenerator ().wrapInputStream (context , w )),
257257 writer .consumer (w -> context .protocolGenerator ().wrapOutputStream (context , w )));
258258 }
259+
259260 writer .addStdlibImport ("typing" , "Any" );
260261 writer .addStdlibImport ("asyncio" , "iscoroutine" );
261262 writer .addImports ("smithy_core.exceptions" , Set .of ("SmithyError" , "CallError" , "RetryError" ));
263+ writer .addImport ("smithy_core.auth" , "AuthParams" );
262264 writer .pushState ();
263265 writer .putContext ("request" , transportRequest );
264266 writer .putContext ("response" , transportResponse );
@@ -438,53 +440,60 @@ await sleep(retry_token.retry_delay)
438440
439441 boolean supportsAuth = !ServiceIndex .of (model ).getAuthSchemes (service ).isEmpty ();
440442 writer .pushState (new ResolveIdentitySection ());
441- if (context .applicationProtocol ().isHttpProtocol () && supportsAuth ) {
442- writer .pushState (new InitializeHttpAuthParametersSection ());
443- writer .write ("""
444- # Step 7b: Invoke service_auth_scheme_resolver.resolve_auth_scheme
445- auth_parameters: $1T = $1T(
446- operation=operation.schema.id.name,
447- ${2C|}
448- )
449-
450- """ ,
451- CodegenUtils .getHttpAuthParamsSymbol (context .settings ()),
452- writer .consumer (this ::initializeHttpAuthParameters ));
453- writer .popState ();
443+ if (supportsAuth ) {
444+ // TODO: delete InitializeHttpAuthParametersSection
454445
455446 writer .addDependency (SmithyPythonDependency .SMITHY_CORE );
456- writer .addDependency (SmithyPythonDependency .SMITHY_HTTP );
457447 writer .addImport ("smithy_core.interfaces.identity" , "Identity" );
458- writer .addImports ("smithy_http.aio.interfaces.auth" , Set .of ("HTTPSigner" , "HTTPAuthOption" ));
448+ writer .addImport ("smithy_core.interfaces.auth" , "AuthOption" );
449+ writer .addImport ("smithy_core.aio.interfaces.auth" , "Signer" );
450+ writer .addImport ("smithy_core.shapes" , "ShapeID" );
459451 writer .addStdlibImport ("typing" , "Any" );
460452 writer .write ("""
461- auth_options = config.http_auth_scheme_resolver.resolve_auth_scheme(
453+ auth_parameters = AuthParams(
454+ protocol_id=ShapeID($1S),
455+ operation=operation,
456+ context=context.properties,
457+ )
458+ auth_options = config.auth_scheme_resolver.resolve_auth_scheme(
462459 auth_parameters=auth_parameters
463460 )
464- auth_option: HTTPAuthOption | None = None
461+
462+ auth_option: AuthOption | None = None
465463 for option in auth_options:
466- if option.scheme_id in config.http_auth_schemes :
464+ if option.scheme_id in config.auth_schemes :
467465 auth_option = option
468466 break
469467
470- signer: HTTPSigner[ Any, Any] | None = None
468+ signer: Signer[$2T, Any, Any] | None = None
471469 identity: Identity | None = None
470+ auth_scheme: Any = None
472471
473472 if auth_option:
474- auth_scheme = config.http_auth_schemes[auth_option.scheme_id]
473+ auth_scheme = config.auth_schemes[auth_option.scheme_id]
474+ context.properties["auth_scheme"] = auth_scheme
475475
476476 # Step 7c: Invoke auth_scheme.identity_resolver
477- identity_resolver = auth_scheme.identity_resolver(config=config)
477+ identity_resolver = auth_scheme.identity_resolver(context=context.properties)
478+ context.properties["identity_resolver"] = identity_resolver
478479
479480 # Step 7d: Invoke auth_scheme.signer
480- signer = auth_scheme.signer
481+ signer = auth_scheme.signer()
482+
483+ # TODO: merge from auth_option
484+ identity_properties = auth_scheme.identity_properties(
485+ context=context.properties
486+ )
487+ context.properties["identity_properties"] = identity_properties
481488
482489 # Step 7e: Invoke identity_resolver.get_identity
483490 identity = await identity_resolver.get_identity(
484- identity_properties=auth_option. identity_properties
491+ identity_properties=identity_properties
485492 )
486493
487- """ );
494+ """ ,
495+ context .protocolGenerator ().getProtocol (),
496+ transportRequest );
488497 }
489498 writer .popState ();
490499
@@ -543,48 +552,29 @@ await sleep(retry_token.retry_delay)
543552
544553 writer .pushState (new SignRequestSection ());
545554 writer .addStdlibImport ("typing" , "cast" );
546- if (context . applicationProtocol (). isHttpProtocol () && supportsAuth ) {
555+ if (supportsAuth ) {
547556 writer .addStdlibImport ("re" );
548557 writer .addStdlibImport ("typing" , "Any" );
549558 writer .addImport ("smithy_core.interfaces.identity" , "Identity" );
550559 writer .addImport ("smithy_core.types" , "PropertyKey" );
551560 writer .write ("""
552561 # Step 7i: sign the request
553562 if auth_option and signer:
554- logger.debug("HTTP request to sign: %s", context.transport_request)
555- logger.debug(
556- "Signer properties: %s",
557- auth_option.signer_properties
558- )
563+ signer_properties = auth_scheme.signer_properties(context=context.properties)
564+ context.properties["signer_properties"] = signer_properties
565+
566+ logger.debug("Request to sign: %s", context.transport_request)
567+ logger.debug("Signer properties: %s", signer_properties)
568+
559569 context = replace(
560570 context,
561- transport_request= await signer.sign(
562- http_request =context.transport_request,
571+ transport_request = await signer.sign(
572+ request =context.transport_request,
563573 identity=identity,
564- signing_properties=auth_option. signer_properties,
574+ properties= signer_properties,
565575 )
566576 )
567577 logger.debug("Signed HTTP request: %s", context.transport_request)
568-
569- # TODO - Move this to separate resolution/population function
570- fields = context.transport_request.fields
571- auth_value = fields["Authorization"].as_string() # type: ignore
572- signature = re.split("Signature=", auth_value)[-1] # type: ignore
573- context.properties["signature"] = signature.encode('utf-8')
574-
575- identity_key = cast(
576- PropertyKey[Identity | None],
577- PropertyKey(
578- key="identity",
579- value_type=Identity | None # type: ignore
580- )
581- )
582- sp_key: PropertyKey[dict[str, Any]] = PropertyKey(
583- key="signer_properties",
584- value_type=dict[str, Any] # type: ignore
585- )
586- context.properties[identity_key] = identity
587- context.properties[sp_key] = auth_option.signer_properties
588578 """ );
589579 }
590580 writer .popState ();
@@ -757,28 +747,6 @@ private boolean hasEventStream() {
757747 return false ;
758748 }
759749
760- private void initializeHttpAuthParameters (PythonWriter writer ) {
761- var derived = new LinkedHashSet <DerivedProperty >();
762- for (PythonIntegration integration : context .integrations ()) {
763- for (RuntimeClientPlugin plugin : integration .getClientPlugins (context )) {
764- if (plugin .matchesService (model , service )
765- && plugin .getAuthScheme ().isPresent ()
766- && plugin .getAuthScheme ().get ().getApplicationProtocol ().isHttpProtocol ()) {
767- derived .addAll (plugin .getAuthScheme ().get ().getAuthProperties ());
768- }
769- }
770- }
771-
772- for (DerivedProperty property : derived ) {
773- var source = property .source ().scopeLocation ();
774- if (property .initializationFunction ().isPresent ()) {
775- writer .write ("$L=$T($L)," , property .name (), property .initializationFunction ().get (), source );
776- } else if (property .sourcePropertyName ().isPresent ()) {
777- writer .write ("$L=$L.$L," , property .name (), source , property .sourcePropertyName ().get ());
778- }
779- }
780- }
781-
782750 private void writeDefaultPlugins (PythonWriter writer , Collection <SymbolReference > plugins ) {
783751 for (SymbolReference plugin : plugins ) {
784752 writer .write ("$T," , plugin );
0 commit comments