diff --git a/codegen-output/aws-json-1-0/src/awsjson10/aio/client.py b/codegen-output/aws-json-1-0/src/awsjson10/aio/client.py index 0bfaf22ed..a5b469820 100644 --- a/codegen-output/aws-json-1-0/src/awsjson10/aio/client.py +++ b/codegen-output/aws-json-1-0/src/awsjson10/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncJSONRPC10Config, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -45,7 +46,11 @@ class AsyncJSONRPC10Client(AsyncClient[AsyncJSONRPC10Config]): """Client for JsonRpc10""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def content_type_parameters( diff --git a/codegen-output/aws-json-1-0/src/awsjson10/aio/retry_headers.py b/codegen-output/aws-json-1-0/src/awsjson10/aio/retry_headers.py new file mode 100644 index 000000000..4c63375d6 --- /dev/null +++ b/codegen-output/aws-json-1-0/src/awsjson10/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncJSONRPC10Config + + +def aws_retry_headers_plugin(config: AsyncJSONRPC10Config) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/aws-json-1-0/src/awsjson10/client.py b/codegen-output/aws-json-1-0/src/awsjson10/client.py index e187e6cdf..af4b92bb1 100644 --- a/codegen-output/aws-json-1-0/src/awsjson10/client.py +++ b/codegen-output/aws-json-1-0/src/awsjson10/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import JSONRPC10Config, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -45,7 +46,11 @@ class JSONRPC10Client(Client[JSONRPC10Config]): """Client for JsonRpc10""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def content_type_parameters( diff --git a/codegen-output/aws-json-1-0/src/awsjson10/retry_headers.py b/codegen-output/aws-json-1-0/src/awsjson10/retry_headers.py new file mode 100644 index 000000000..13cffcb81 --- /dev/null +++ b/codegen-output/aws-json-1-0/src/awsjson10/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import JSONRPC10Config + + +def aws_retry_headers_plugin(config: JSONRPC10Config) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/aws-json-1-1/src/awsjson11/aio/client.py b/codegen-output/aws-json-1-1/src/awsjson11/aio/client.py index 4656a6e77..58ff9852c 100644 --- a/codegen-output/aws-json-1-1/src/awsjson11/aio/client.py +++ b/codegen-output/aws-json-1-1/src/awsjson11/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncJsonProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -47,7 +48,11 @@ class AsyncJsonProtocolClient(AsyncClient[AsyncJsonProtocolConfig]): """Client for JsonProtocol""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def content_type_parameters( diff --git a/codegen-output/aws-json-1-1/src/awsjson11/aio/retry_headers.py b/codegen-output/aws-json-1-1/src/awsjson11/aio/retry_headers.py new file mode 100644 index 000000000..1bd3a5ebe --- /dev/null +++ b/codegen-output/aws-json-1-1/src/awsjson11/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncJsonProtocolConfig + + +def aws_retry_headers_plugin(config: AsyncJsonProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/aws-json-1-1/src/awsjson11/client.py b/codegen-output/aws-json-1-1/src/awsjson11/client.py index 0745c4942..59ebe38f5 100644 --- a/codegen-output/aws-json-1-1/src/awsjson11/client.py +++ b/codegen-output/aws-json-1-1/src/awsjson11/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import JsonProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -47,7 +48,11 @@ class JsonProtocolClient(Client[JsonProtocolConfig]): """Client for JsonProtocol""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def content_type_parameters( diff --git a/codegen-output/aws-json-1-1/src/awsjson11/retry_headers.py b/codegen-output/aws-json-1-1/src/awsjson11/retry_headers.py new file mode 100644 index 000000000..66469e49e --- /dev/null +++ b/codegen-output/aws-json-1-1/src/awsjson11/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import JsonProtocolConfig + + +def aws_retry_headers_plugin(config: JsonProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/aws-query/src/awsquery/aio/client.py b/codegen-output/aws-query/src/awsquery/aio/client.py index 3199e7f86..ea70d34bd 100644 --- a/codegen-output/aws-query/src/awsquery/aio/client.py +++ b/codegen-output/aws-query/src/awsquery/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncQueryProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -62,7 +63,11 @@ class AsyncQueryProtocolClient(AsyncClient[AsyncQueryProtocolConfig]): """A query service that sends query requests and XML responses.""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def datetime_offsets( diff --git a/codegen-output/aws-query/src/awsquery/aio/retry_headers.py b/codegen-output/aws-query/src/awsquery/aio/retry_headers.py new file mode 100644 index 000000000..e6eed0f2f --- /dev/null +++ b/codegen-output/aws-query/src/awsquery/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncQueryProtocolConfig + + +def aws_retry_headers_plugin(config: AsyncQueryProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/aws-query/src/awsquery/client.py b/codegen-output/aws-query/src/awsquery/client.py index b004779d1..c5d8295ad 100644 --- a/codegen-output/aws-query/src/awsquery/client.py +++ b/codegen-output/aws-query/src/awsquery/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import Plugin, QueryProtocolConfig +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -62,7 +63,11 @@ class QueryProtocolClient(Client[QueryProtocolConfig]): """A query service that sends query requests and XML responses.""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def datetime_offsets( diff --git a/codegen-output/aws-query/src/awsquery/retry_headers.py b/codegen-output/aws-query/src/awsquery/retry_headers.py new file mode 100644 index 000000000..553114621 --- /dev/null +++ b/codegen-output/aws-query/src/awsquery/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import QueryProtocolConfig + + +def aws_retry_headers_plugin(config: QueryProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/ec2-query/src/ec2query/aio/client.py b/codegen-output/ec2-query/src/ec2query/aio/client.py index b6c477a1d..1d94d276c 100644 --- a/codegen-output/ec2-query/src/ec2query/aio/client.py +++ b/codegen-output/ec2-query/src/ec2query/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncEC2ProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -54,7 +55,11 @@ class AsyncEC2ProtocolClient(AsyncClient[AsyncEC2ProtocolConfig]): """An EC2 query service that sends query requests and XML responses.""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def datetime_offsets( diff --git a/codegen-output/ec2-query/src/ec2query/aio/retry_headers.py b/codegen-output/ec2-query/src/ec2query/aio/retry_headers.py new file mode 100644 index 000000000..62a9e3209 --- /dev/null +++ b/codegen-output/ec2-query/src/ec2query/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncEC2ProtocolConfig + + +def aws_retry_headers_plugin(config: AsyncEC2ProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/ec2-query/src/ec2query/client.py b/codegen-output/ec2-query/src/ec2query/client.py index 0a41d2b1e..1559bcb69 100644 --- a/codegen-output/ec2-query/src/ec2query/client.py +++ b/codegen-output/ec2-query/src/ec2query/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import EC2ProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -54,7 +55,11 @@ class EC2ProtocolClient(Client[EC2ProtocolConfig]): """An EC2 query service that sends query requests and XML responses.""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def datetime_offsets( diff --git a/codegen-output/ec2-query/src/ec2query/retry_headers.py b/codegen-output/ec2-query/src/ec2query/retry_headers.py new file mode 100644 index 000000000..1195b1964 --- /dev/null +++ b/codegen-output/ec2-query/src/ec2query/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import EC2ProtocolConfig + + +def aws_retry_headers_plugin(config: EC2ProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/aio/client.py b/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/aio/client.py index 37e67d682..621344b5e 100644 --- a/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/aio/client.py +++ b/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncNonQueryCompatibleRpcV2ProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -30,7 +31,11 @@ class AsyncNonQueryCompatibleRpcV2ProtocolClient( ): """Client for NonQueryCompatibleRpcV2Protocol""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def non_query_compatible_operation( diff --git a/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/aio/retry_headers.py b/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/aio/retry_headers.py new file mode 100644 index 000000000..7cd655b68 --- /dev/null +++ b/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/aio/retry_headers.py @@ -0,0 +1,11 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncNonQueryCompatibleRpcV2ProtocolConfig + + +def aws_retry_headers_plugin( + config: AsyncNonQueryCompatibleRpcV2ProtocolConfig, +) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/client.py b/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/client.py index 937b6e433..7e3f5bf18 100644 --- a/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/client.py +++ b/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import NonQueryCompatibleRpcV2ProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -30,7 +31,11 @@ class NonQueryCompatibleRpcV2ProtocolClient( ): """Client for NonQueryCompatibleRpcV2Protocol""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def non_query_compatible_operation( diff --git a/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/retry_headers.py b/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/retry_headers.py new file mode 100644 index 000000000..d8a3bb836 --- /dev/null +++ b/codegen-output/non-query-compatible-rpcv2-cbor/src/nonquerycompatiblerpcv2cbor/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import NonQueryCompatibleRpcV2ProtocolConfig + + +def aws_retry_headers_plugin(config: NonQueryCompatibleRpcV2ProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/aio/client.py b/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/aio/client.py index d5b55c019..d9f20d31a 100644 --- a/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/aio/client.py +++ b/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncQueryCompatibleJSONRPC10Config, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -30,7 +31,11 @@ class AsyncQueryCompatibleJSONRPC10Client( ): """Client for QueryCompatibleJsonRpc10""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def query_compatible_operation( diff --git a/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/aio/retry_headers.py b/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/aio/retry_headers.py new file mode 100644 index 000000000..70ebdb848 --- /dev/null +++ b/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncQueryCompatibleJSONRPC10Config + + +def aws_retry_headers_plugin(config: AsyncQueryCompatibleJSONRPC10Config) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/client.py b/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/client.py index c620e96d3..d27df2f57 100644 --- a/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/client.py +++ b/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import Plugin, QueryCompatibleJSONRPC10Config +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -28,7 +29,11 @@ class QueryCompatibleJSONRPC10Client(Client[QueryCompatibleJSONRPC10Config]): """Client for QueryCompatibleJsonRpc10""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def query_compatible_operation( diff --git a/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/retry_headers.py b/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/retry_headers.py new file mode 100644 index 000000000..b02cc75f2 --- /dev/null +++ b/codegen-output/query-compatible-aws-json-1-0/src/querycompatibleawsjson10/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import QueryCompatibleJSONRPC10Config + + +def aws_retry_headers_plugin(config: QueryCompatibleJSONRPC10Config) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/aio/client.py b/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/aio/client.py index a1313e1b4..4b7fcdbcf 100644 --- a/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/aio/client.py +++ b/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncQueryCompatibleRpcV2ProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -30,7 +31,11 @@ class AsyncQueryCompatibleRpcV2ProtocolClient( ): """Client for QueryCompatibleRpcV2Protocol""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def query_compatible_operation( diff --git a/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/aio/retry_headers.py b/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/aio/retry_headers.py new file mode 100644 index 000000000..826024a49 --- /dev/null +++ b/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncQueryCompatibleRpcV2ProtocolConfig + + +def aws_retry_headers_plugin(config: AsyncQueryCompatibleRpcV2ProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/client.py b/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/client.py index bf76bd38b..8a74b704f 100644 --- a/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/client.py +++ b/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import Plugin, QueryCompatibleRpcV2ProtocolConfig +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -28,7 +29,11 @@ class QueryCompatibleRpcV2ProtocolClient(Client[QueryCompatibleRpcV2ProtocolConfig]): """Client for QueryCompatibleRpcV2Protocol""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def query_compatible_operation( diff --git a/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/retry_headers.py b/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/retry_headers.py new file mode 100644 index 000000000..fba58d8ba --- /dev/null +++ b/codegen-output/query-compatible-rpcv2-cbor/src/querycompatiblerpcv2cbor/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import QueryCompatibleRpcV2ProtocolConfig + + +def aws_retry_headers_plugin(config: QueryCompatibleRpcV2ProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/rest-json-1/src/restjson/aio/client.py b/codegen-output/rest-json-1/src/restjson/aio/client.py index 9bdb86196..133a39de2 100644 --- a/codegen-output/rest-json-1/src/restjson/aio/client.py +++ b/codegen-output/rest-json-1/src/restjson/aio/client.py @@ -30,6 +30,7 @@ _EventStreamDeserializer, ) from .config import AsyncRestJsonProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -151,7 +152,11 @@ class AsyncRestJsonProtocolClient(AsyncClient[AsyncRestJsonProtocolConfig]): """Client for RestJson""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def all_query_string_types( diff --git a/codegen-output/rest-json-1/src/restjson/aio/retry_headers.py b/codegen-output/rest-json-1/src/restjson/aio/retry_headers.py new file mode 100644 index 000000000..913f17e8e --- /dev/null +++ b/codegen-output/rest-json-1/src/restjson/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncRestJsonProtocolConfig + + +def aws_retry_headers_plugin(config: AsyncRestJsonProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/rest-json-1/src/restjson/client.py b/codegen-output/rest-json-1/src/restjson/client.py index 5b37a6984..2a733b000 100644 --- a/codegen-output/rest-json-1/src/restjson/client.py +++ b/codegen-output/rest-json-1/src/restjson/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import Plugin, RestJsonProtocolConfig +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -135,7 +136,11 @@ class RestJsonProtocolClient(Client[RestJsonProtocolConfig]): """Client for RestJson""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def all_query_string_types( diff --git a/codegen-output/rest-json-1/src/restjson/retry_headers.py b/codegen-output/rest-json-1/src/restjson/retry_headers.py new file mode 100644 index 000000000..1d06e3eb9 --- /dev/null +++ b/codegen-output/rest-json-1/src/restjson/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import RestJsonProtocolConfig + + +def aws_retry_headers_plugin(config: RestJsonProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/aio/client.py b/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/aio/client.py index 4501fd151..d8026059a 100644 --- a/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/aio/client.py +++ b/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncRestXmlProtocolNamespaceConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -36,7 +37,11 @@ class AsyncRestXmlProtocolNamespaceClient( https://github.com/smithy-lang/smithy/issues/616 """ - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def simple_scalar_properties( diff --git a/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/aio/retry_headers.py b/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/aio/retry_headers.py new file mode 100644 index 000000000..2d60affa6 --- /dev/null +++ b/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncRestXmlProtocolNamespaceConfig + + +def aws_retry_headers_plugin(config: AsyncRestXmlProtocolNamespaceConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/client.py b/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/client.py index d5306246c..d872663d7 100644 --- a/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/client.py +++ b/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import Plugin, RestXmlProtocolNamespaceConfig +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -34,7 +35,11 @@ class RestXmlProtocolNamespaceClient(Client[RestXmlProtocolNamespaceConfig]): https://github.com/smithy-lang/smithy/issues/616 """ - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def simple_scalar_properties( diff --git a/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/retry_headers.py b/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/retry_headers.py new file mode 100644 index 000000000..028494c0e --- /dev/null +++ b/codegen-output/rest-xml-with-namespace/src/restxmlwithnamespace/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import RestXmlProtocolNamespaceConfig + + +def aws_retry_headers_plugin(config: RestXmlProtocolNamespaceConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/rest-xml/src/restxml/aio/client.py b/codegen-output/rest-xml/src/restxml/aio/client.py index 233bc2e1d..c3e7f2cfa 100644 --- a/codegen-output/rest-xml/src/restxml/aio/client.py +++ b/codegen-output/rest-xml/src/restxml/aio/client.py @@ -14,6 +14,7 @@ from .. import models as _models from .config import AsyncRestXmlProtocolConfig, Plugin +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -94,7 +95,11 @@ class AsyncRestXmlProtocolClient(AsyncClient[AsyncRestXmlProtocolConfig]): """A REST XML service that sends XML requests and responses.""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload async def all_query_string_types( diff --git a/codegen-output/rest-xml/src/restxml/aio/retry_headers.py b/codegen-output/rest-xml/src/restxml/aio/retry_headers.py new file mode 100644 index 000000000..185866f37 --- /dev/null +++ b/codegen-output/rest-xml/src/restxml/aio/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import AsyncRestXmlProtocolConfig + + +def aws_retry_headers_plugin(config: AsyncRestXmlProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen-output/rest-xml/src/restxml/client.py b/codegen-output/rest-xml/src/restxml/client.py index 57acdab3a..45c279428 100644 --- a/codegen-output/rest-xml/src/restxml/client.py +++ b/codegen-output/rest-xml/src/restxml/client.py @@ -14,6 +14,7 @@ from . import models as _models from .config import Plugin, RestXmlProtocolConfig +from .retry_headers import aws_retry_headers_plugin from .user_agent import aws_user_agent_plugin from typing import TYPE_CHECKING @@ -94,7 +95,11 @@ class RestXmlProtocolClient(Client[RestXmlProtocolConfig]): """A REST XML service that sends XML requests and responses.""" - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + aws_retry_headers_plugin, + user_agent_plugin, + ) @_overload def all_query_string_types( diff --git a/codegen-output/rest-xml/src/restxml/retry_headers.py b/codegen-output/rest-xml/src/restxml/retry_headers.py new file mode 100644 index 000000000..bde63520f --- /dev/null +++ b/codegen-output/rest-xml/src/restxml/retry_headers.py @@ -0,0 +1,9 @@ +# Code generated by smithy-python-codegen DO NOT EDIT. + +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor + +from .config import RestXmlProtocolConfig + + +def aws_retry_headers_plugin(config: RestXmlProtocolConfig) -> None: + config.interceptors.append(RetryHeadersInterceptor()) diff --git a/codegen/aws/core/src/it/java/software/amazon/smithy/python/codegen/test/AwsCodegenTest.java b/codegen/aws/core/src/it/java/software/amazon/smithy/python/codegen/test/AwsCodegenTest.java index f1d21e83e..30d495e13 100644 --- a/codegen/aws/core/src/it/java/software/amazon/smithy/python/codegen/test/AwsCodegenTest.java +++ b/codegen/aws/core/src/it/java/software/amazon/smithy/python/codegen/test/AwsCodegenTest.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import software.amazon.smithy.build.FileManifest; @@ -69,6 +70,14 @@ public void testCodegen(@TempDir Path tempDir) throws IOException { assertFalse(client.contains("def _ensure_setup(")); assertFalse(client.contains("def _prepare_call[")); + // The sync and async clients both add the retry headers interceptor. + for (var prefix : List.of("src/restjson/aio/", "src/restjson/")) { + assertTrue(Files.readString(tempDir.resolve(prefix + "client.py")) + .contains("aws_retry_headers_plugin")); + assertTrue(Files.readString(tempDir.resolve(prefix + "retry_headers.py")) + .contains("config.interceptors.append(RetryHeadersInterceptor())")); + } + var schemas = Files.readString(tempDir.resolve("src/restjson/_private/schemas.py")); assertTrue(schemas.contains("aws.protocols#restJson1")); assertTrue(schemas.contains("smithy.api#httpApiKeyAuth")); diff --git a/codegen/aws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsRetryHeadersIntegration.java b/codegen/aws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsRetryHeadersIntegration.java new file mode 100644 index 000000000..6524ed18c --- /dev/null +++ b/codegen/aws/core/src/main/java/software/amazon/smithy/python/aws/codegen/AwsRetryHeadersIntegration.java @@ -0,0 +1,69 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package software.amazon.smithy.python.aws.codegen; + +import java.util.List; +import software.amazon.smithy.codegen.core.Symbol; +import software.amazon.smithy.codegen.core.SymbolReference; +import software.amazon.smithy.python.codegen.CodegenUtils; +import software.amazon.smithy.python.codegen.GenerationContext; +import software.amazon.smithy.python.codegen.SyncVariant; +import software.amazon.smithy.python.codegen.integrations.PythonIntegration; +import software.amazon.smithy.python.codegen.integrations.RuntimeClientPlugin; +import software.amazon.smithy.utils.SmithyInternalApi; + +/** + * Adds the interceptor that sends the retry information headers to clients of AWS + * services. + */ +@SmithyInternalApi +public final class AwsRetryHeadersIntegration implements PythonIntegration { + + private static final String PLUGIN_FILE = "retry_headers"; + + private static final String RETRY_HEADERS_PLUGIN = """ + def aws_retry_headers_plugin(config: $1T) -> None: + config.interceptors.append($2T()) + """; + + // The interceptor has no async twin, so the sync plugin gets the same symbol. + private static final Symbol INTERCEPTOR = Symbol.builder() + .namespace("smithy_aws_core.interceptors.retry_headers", ".") + .name("RetryHeadersInterceptor") + .addDependency(AwsPythonDependency.SMITHY_AWS_CORE) + .build(); + + @Override + public List getClientPlugins(GenerationContext context) { + if (!CodegenUtils.isAwsService(context)) { + return List.of(); + } + + final SymbolReference plugin = SymbolReference.builder() + .symbol(CodegenUtils.aioSymbol(context.settings(), PLUGIN_FILE, "aws_retry_headers_plugin")) + .build(); + + return List.of( + RuntimeClientPlugin.builder() + .pythonPlugin(plugin) + .writeAdditionalFiles((c) -> { + var filename = plugin.getSymbol().getDefinitionFile(); + var asyncConfig = CodegenUtils.getAsyncConfigSymbol(c.settings(), c.model()); + c.writerDelegator() + .useFileWriter(filename, + plugin.getSymbol().getNamespace(), + writer -> writer.write(RETRY_HEADERS_PLUGIN, + asyncConfig, + INTERCEPTOR)); + var syncFile = SyncVariant.writeSyncTwin(c, + plugin.getSymbol(), + RETRY_HEADERS_PLUGIN, + asyncConfig, + INTERCEPTOR); + return List.of(filename, syncFile); + }) + .build()); + } +} diff --git a/codegen/aws/core/src/main/resources/META-INF/services/software.amazon.smithy.python.codegen.integrations.PythonIntegration b/codegen/aws/core/src/main/resources/META-INF/services/software.amazon.smithy.python.codegen.integrations.PythonIntegration index 723bec22e..c60c868f5 100644 --- a/codegen/aws/core/src/main/resources/META-INF/services/software.amazon.smithy.python.codegen.integrations.PythonIntegration +++ b/codegen/aws/core/src/main/resources/META-INF/services/software.amazon.smithy.python.codegen.integrations.PythonIntegration @@ -9,6 +9,7 @@ software.amazon.smithy.python.aws.codegen.AwsIdentityIntegration software.amazon.smithy.python.aws.codegen.AwsProtocolsIntegration software.amazon.smithy.python.aws.codegen.AwsServiceIdIntegration software.amazon.smithy.python.aws.codegen.AwsUserAgentIntegration +software.amazon.smithy.python.aws.codegen.AwsRetryHeadersIntegration software.amazon.smithy.python.aws.codegen.AwsFlexibleChecksumsIntegration software.amazon.smithy.python.aws.codegen.AwsEndpointRulesIntegration software.amazon.smithy.python.aws.codegen.AwsDefaultEndpointRuleSetIntegration diff --git a/packages/smithy-aws-core/.changes/next-release/smithy-aws-core-enhancement-e41cee1f886447129272ae91cc576e13.json b/packages/smithy-aws-core/.changes/next-release/smithy-aws-core-enhancement-e41cee1f886447129272ae91cc576e13.json new file mode 100644 index 000000000..11f80bf9b --- /dev/null +++ b/packages/smithy-aws-core/.changes/next-release/smithy-aws-core-enhancement-e41cee1f886447129272ae91cc576e13.json @@ -0,0 +1,4 @@ +{ + "type": "enhancement", + "description": "Added the `amz-sdk-request` header, with the attempt number and the maximum attempts, to requests of generated AWS clients." +} \ No newline at end of file diff --git a/packages/smithy-aws-core/.changes/next-release/smithy-aws-core-feature-fbc59bea9bb94c2886ab6534011acead.json b/packages/smithy-aws-core/.changes/next-release/smithy-aws-core-feature-fbc59bea9bb94c2886ab6534011acead.json new file mode 100644 index 000000000..a0a202a79 --- /dev/null +++ b/packages/smithy-aws-core/.changes/next-release/smithy-aws-core-feature-fbc59bea9bb94c2886ab6534011acead.json @@ -0,0 +1,4 @@ +{ + "type": "feature", + "description": "Added the `amz-sdk-invocation-id` header to requests of generated AWS clients." +} diff --git a/packages/smithy-aws-core/src/smithy_aws_core/interceptors/retry_headers.py b/packages/smithy-aws-core/src/smithy_aws_core/interceptors/retry_headers.py new file mode 100644 index 000000000..cfe4e91ad --- /dev/null +++ b/packages/smithy-aws-core/src/smithy_aws_core/interceptors/retry_headers.py @@ -0,0 +1,61 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +import uuid +from typing import Any + +from smithy_core.interceptors import Interceptor, RequestContext +from smithy_core.retries import RETRY_STRATEGY +from smithy_core.types import PropertyKey +from smithy_http import Field +from smithy_http.interfaces import HTTPRequest + +__all__ = ["RetryHeadersInterceptor"] + +_ATTEMPT = PropertyKey(key="retry_headers_attempt", value_type=int) + + +class RetryHeadersInterceptor(Interceptor[Any, Any, HTTPRequest, Any]): + """Adds the headers that tell a service how a call is retried. + + ``amz-sdk-invocation-id`` holds a random (version 4) UUID that is the same on every + attempt of a call and different for every call, so a service can tell which + requests are attempts of the same call. + + ``amz-sdk-request`` holds the number of the attempt, starting at 1, and the most + attempts the call's retry strategy allows, such as ``attempt=2; max=3``. When that + number is not known (no retry strategy, or a ``max_attempts`` that is missing or + not a positive integer), it holds only the attempt number. + """ + + def modify_before_retry_loop( + self, context: RequestContext[Any, HTTPRequest] + ) -> HTTPRequest: + # This hook runs once per call, before the first attempt, so every attempt + # sends the same ID. + request = context.transport_request + request.fields.set_field( + Field(name="amz-sdk-invocation-id", values=[str(uuid.uuid4())]) + ) + return request + + def read_before_attempt(self, context: RequestContext[Any, HTTPRequest]) -> None: + # The properties are shared by every attempt of a call, so they hold the count. + context.properties[_ATTEMPT] = context.properties.get(_ATTEMPT, 0) + 1 + + def modify_before_signing( + self, context: RequestContext[Any, HTTPRequest] + ) -> HTTPRequest: + request = context.transport_request + value = f"attempt={context.properties[_ATTEMPT]}" + # A custom strategy may not set max_attempts, so it's read with a default. + max_attempts = getattr( + context.properties.get(RETRY_STRATEGY), "max_attempts", None + ) + if ( + isinstance(max_attempts, int) + and not isinstance(max_attempts, bool) + and max_attempts >= 1 + ): + value += f"; max={max_attempts}" + request.fields.set_field(Field(name="amz-sdk-request", values=[value])) + return request diff --git a/packages/smithy-aws-core/tests/functional/test_retry_headers.py b/packages/smithy-aws-core/tests/functional/test_retry_headers.py new file mode 100644 index 000000000..ad67531f4 --- /dev/null +++ b/packages/smithy-aws-core/tests/functional/test_retry_headers.py @@ -0,0 +1,106 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +"""The retry information headers through a generated AWS client. + +Drives the generated awsJson1.0 client (``codegen-output/aws-json-1-0``) and checks +the headers of every attempt the sync and async clients send. +""" + +from pathlib import Path +from typing import Any + +import pytest + +pytest.importorskip("awsjson10") + +from awsjson10.aio.client import AsyncJSONRPC10Client +from awsjson10.aio.config import AsyncJSONRPC10Config +from awsjson10.client import JSONRPC10Client +from awsjson10.config import JSONRPC10Config +from smithy_http import HTTPResponse, tuples_to_fields + +_JSON_CONTENT_TYPE = ("content-type", "application/x-amz-json-1.0") + + +class _RecordingTransport: + """Throttles the first ``throttles`` requests and records every request's headers.""" + + TIMEOUT_EXCEPTIONS = () + + def __init__(self, throttles: int = 0) -> None: + self.headers: list[dict[str, str]] = [] + self._throttles = throttles + + def send(self, request: Any, *, request_config: Any = None) -> HTTPResponse: + # Attempts can share one Fields object, so copy the values as they are sent. + self.headers.append({f.name.lower(): f.as_string() for f in request.fields}) + if len(self.headers) <= self._throttles: + return HTTPResponse( + status=429, + fields=tuples_to_fields([_JSON_CONTENT_TYPE]), + body=b'{"__type":"ThrottlingException"}', + ) + return HTTPResponse( + status=200, fields=tuples_to_fields([_JSON_CONTENT_TYPE]), body=b"{}" + ) + + +class _AsyncRecordingTransport(_RecordingTransport): + async def send( # pyright: ignore[reportIncompatibleMethodOverride] + self, request: Any, *, request_config: Any = None + ) -> HTTPResponse: + return super().send(request, request_config=request_config) + + +@pytest.fixture(params=[True, False], ids=["sync", "async"]) +def sync(request: pytest.FixtureRequest) -> bool: + return request.param + + +async def _call(sync: bool, tmp_path: Path, throttles: int = 0) -> list[dict[str, str]]: + transport = (_RecordingTransport if sync else _AsyncRecordingTransport)(throttles) + missing = str(tmp_path / "missing") + config: dict[str, Any] = { + "config_file_path": missing, + "credentials_file_path": missing, + "region": "us-west-2", + "aws_access_key_id": "AKID", + "aws_secret_access_key": "secret", + "transport": transport, + } + if sync: + JSONRPC10Client( + config=JSONRPC10Config.resolve(**config) + ).empty_input_and_empty_output() + else: + await AsyncJSONRPC10Client( + config=await AsyncJSONRPC10Config.resolve(**config) + ).empty_input_and_empty_output() + return transport.headers + + +async def test_sends_same_invocation_id_on_every_attempt( + sync: bool, tmp_path: Path +) -> None: + attempts = await _call(sync, tmp_path, throttles=2) + invocation_ids = {headers["amz-sdk-invocation-id"] for headers in attempts} + assert len(attempts) == 3 + assert len(invocation_ids) == 1 + + +async def test_sends_attempt_number_and_max_attempts( + sync: bool, tmp_path: Path +) -> None: + attempts = await _call(sync, tmp_path, throttles=2) + assert [headers["amz-sdk-request"] for headers in attempts] == [ + "attempt=1; max=3", + "attempt=2; max=3", + "attempt=3; max=3", + ] + + +async def test_signs_retry_headers(sync: bool, tmp_path: Path) -> None: + (headers,) = await _call(sync, tmp_path) + signed = headers["authorization"] + assert "amz-sdk-invocation-id" in signed + assert "amz-sdk-request" in signed diff --git a/packages/smithy-aws-core/tests/unit/interceptors/test_retry_headers.py b/packages/smithy-aws-core/tests/unit/interceptors/test_retry_headers.py new file mode 100644 index 000000000..d9a879600 --- /dev/null +++ b/packages/smithy-aws-core/tests/unit/interceptors/test_retry_headers.py @@ -0,0 +1,101 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +import uuid +from types import SimpleNamespace +from typing import Any +from unittest.mock import Mock + +import pytest +from smithy_aws_core.interceptors.retry_headers import RetryHeadersInterceptor +from smithy_core import URI +from smithy_core.interceptors import RequestContext +from smithy_core.retries import RETRY_STRATEGY +from smithy_core.types import TypedProperties +from smithy_http import Field, Fields, HTTPRequest + + +def _context() -> RequestContext[Any, HTTPRequest]: + return RequestContext[Any, HTTPRequest]( + request=Mock(), + transport_request=HTTPRequest( + method="POST", destination=URI(host="example.com"), fields=Fields() + ), + properties=TypedProperties(), + ) + + +def _invocation_id() -> str: + request = RetryHeadersInterceptor().modify_before_retry_loop(_context()) + return request.fields["amz-sdk-invocation-id"].as_string() + + +def test_invocation_id_is_a_version_4_uuid() -> None: + assert uuid.UUID(_invocation_id()).version == 4 + + +def test_invocation_id_is_the_same_on_every_attempt() -> None: + interceptor = RetryHeadersInterceptor() + context = _context() + request = interceptor.modify_before_retry_loop(context) + invocation_id = request.fields["amz-sdk-invocation-id"].as_string() + for _ in range(3): + interceptor.read_before_attempt(context) + request = interceptor.modify_before_signing(context) + assert request.fields["amz-sdk-invocation-id"].as_string() == invocation_id + + +def test_invocation_id_differs_between_calls() -> None: + assert _invocation_id() != _invocation_id() + + +def test_invocation_id_replaces_a_callers_value() -> None: + context = _context() + context.transport_request.fields.set_field( + Field(name="amz-sdk-invocation-id", values=["from-the-caller"]) + ) + request = RetryHeadersInterceptor().modify_before_retry_loop(context) + invocation_id = request.fields["amz-sdk-invocation-id"].as_string() + assert uuid.UUID(invocation_id).version == 4 + + +_NO_STRATEGY = object() + + +def _request_header(strategy: Any) -> str: + interceptor = RetryHeadersInterceptor() + context = _context() + if strategy is not _NO_STRATEGY: + context.properties[RETRY_STRATEGY] = strategy + interceptor.read_before_attempt(context) + request = interceptor.modify_before_signing(context) + return request.fields["amz-sdk-request"].as_string() + + +@pytest.mark.parametrize( + "strategy", + [ + _NO_STRATEGY, + SimpleNamespace(), + SimpleNamespace(max_attempts=None), + SimpleNamespace(max_attempts=0), + SimpleNamespace(max_attempts=True), + ], + ids=["no strategy", "no attribute", "None", "0", "True"], +) +def test_request_header_omits_unknown_max(strategy: Any) -> None: + assert _request_header(strategy) == "attempt=1" + + +def test_request_header_sends_max_attempts() -> None: + assert _request_header(SimpleNamespace(max_attempts=3)) == "attempt=1; max=3" + + +def test_request_header_replaces_a_callers_value() -> None: + interceptor = RetryHeadersInterceptor() + context = _context() + context.transport_request.fields.set_field( + Field(name="amz-sdk-request", values=["from-the-caller"]) + ) + interceptor.read_before_attempt(context) + request = interceptor.modify_before_signing(context) + assert request.fields["amz-sdk-request"].as_string() == "attempt=1" diff --git a/scripts/api-snapshot/api-rex.json b/scripts/api-snapshot/api-rex.json index 0614f5f66..0272a33ec 100644 --- a/scripts/api-snapshot/api-rex.json +++ b/scripts/api-snapshot/api-rex.json @@ -517,6 +517,14 @@ "register_feature_id": "rex-function", "response_validation_order": "rex-function" }, + "smithy_aws_core.interceptors.retry_headers": { + "Field": "rex-class", + "HTTPRequest": "rex-protocol", + "Interceptor": "rex-class", + "PropertyKey": "rex-class", + "RETRY_STRATEGY": "rex-PropertyKey", + "RequestContext": "rex-class" + }, "smithy_aws_core.interceptors.user_agent": { "AdaptiveRetryStrategy": "rex-class", "AwsFeatureId": "rex-class", diff --git a/scripts/api-snapshot/api.json b/scripts/api-snapshot/api.json index bcb4c0586..5d4e72118 100644 --- a/scripts/api-snapshot/api.json +++ b/scripts/api-snapshot/api.json @@ -276,6 +276,9 @@ "FlexibleChecksumsInterceptor": "class", "logger": "Logger" }, + "smithy_aws_core.interceptors.retry_headers": { + "RetryHeadersInterceptor": "class" + }, "smithy_aws_core.interceptors.user_agent": { "UserAgentInterceptor": "class" }, diff --git a/scripts/verifications/import-cost.json b/scripts/verifications/import-cost.json index 3f0b06223..e61e5067e 100644 --- a/scripts/verifications/import-cost.json +++ b/scripts/verifications/import-cost.json @@ -4,7 +4,7 @@ "smithy_aws_checksums": 7, "smithy_aws_checksums (all public modules)": 7, "smithy_aws_core": 1, - "smithy_aws_core (all public modules)": 176, + "smithy_aws_core (all public modules)": 177, "smithy_aws_event_stream": 1, "smithy_aws_event_stream (all public modules)": 42, "smithy_cbor": 20,