diff --git a/packages/smithy-aws-core/src/smithy_aws_core/interceptors/user_agent.py b/packages/smithy-aws-core/src/smithy_aws_core/interceptors/user_agent.py index 67eee6572..3e5cb388a 100644 --- a/packages/smithy-aws-core/src/smithy_aws_core/interceptors/user_agent.py +++ b/packages/smithy-aws-core/src/smithy_aws_core/interceptors/user_agent.py @@ -6,6 +6,7 @@ import smithy_aws_core import smithy_core from smithy_core.interceptors import Interceptor, InterceptorContext +from smithy_http.interceptors.user_agent import USER_AGENT from smithy_http.user_agent import UserAgentComponent, RawStringUserAgentComponent _USERAGENT_SDK_NAME = "aws-sdk-python" @@ -39,8 +40,8 @@ def __init__( def read_after_serialization( self, context: InterceptorContext[Any, Any, Any, Any] ) -> None: - if "user_agent" in context.properties: - user_agent = context.properties["user_agent"] + if USER_AGENT in context.properties: + user_agent = context.properties[USER_AGENT] user_agent.sdk_metadata = self._build_sdk_metadata() user_agent.api_metadata.append( UserAgentComponent("api", self._service_id, self._sdk_version) diff --git a/packages/smithy-http/src/smithy_http/interceptors/user_agent.py b/packages/smithy-http/src/smithy_http/interceptors/user_agent.py index ad58ddcaa..cd9fd1ea2 100644 --- a/packages/smithy-http/src/smithy_http/interceptors/user_agent.py +++ b/packages/smithy-http/src/smithy_http/interceptors/user_agent.py @@ -5,10 +5,13 @@ import smithy_core from smithy_core.interceptors import Interceptor, InterceptorContext +from smithy_core.types import PropertyKey from smithy_http import Field from smithy_http.aio.interfaces import HTTPRequest from smithy_http.user_agent import UserAgent, UserAgentComponent +USER_AGENT = PropertyKey(key="user_agent", value_type=UserAgent) + class UserAgentInterceptor(Interceptor[Any, None, HTTPRequest, None]): """Adds interceptors that initialize UserAgent in the context and add the user-agent @@ -17,12 +20,12 @@ class UserAgentInterceptor(Interceptor[Any, None, HTTPRequest, None]): def read_before_execution( self, context: InterceptorContext[Any, None, None, None] ) -> None: - context.properties["user_agent"] = _UserAgentBuilder.from_environment().build() + context.properties[USER_AGENT] = _UserAgentBuilder.from_environment().build() def modify_before_signing( self, context: InterceptorContext[Any, None, HTTPRequest, None] ) -> HTTPRequest: - user_agent = context.properties["user_agent"] + user_agent = context.properties[USER_AGENT] request = context.transport_request request.fields.set_field(Field(name="User-Agent", values=[str(user_agent)])) return context.transport_request