From a95ffc0fcc83fe7cee932171d8ad7147bc2b79bc Mon Sep 17 00:00:00 2001 From: Sean O'Brien <60306702+stobrien89@users.noreply.github.com> Date: Fri, 27 Nov 2026 18:04:27 -0500 Subject: [PATCH] Generate flexible checksums for AWS clients --- .../.smithy-python-manifest.json | 18 +- .../features-client/pyproject.toml | 2 +- .../src/features_client/_private/schemas.py | 330 ++++++++++-------- .../src/features_client/aio/checksums.py | 8 + .../src/features_client/aio/client.py | 7 +- .../src/features_client/aio/config.py | 30 +- .../src/features_client/checksums.py | 8 + .../src/features_client/client.py | 7 +- .../src/features_client/config.py | 30 +- .../src/features_client/models.py | 4 + .../src/features_client/models.pyi | 13 + designs/codegen/client.md | 14 + ...ture-dd5d0a23a2f040bfab12e48ed51bbe70.json | 4 + .../src/smithy_python/aws/__init__.py | 3 + .../src/smithy_python/aws/_checksums.py | 179 ++++++++++ .../src/smithy_python/aws/_config.py | 5 + .../src/smithy_python/schemas.py | 2 + .../tests/unit/test_client_generation.py | 29 ++ scripts/api-snapshot/api-rex.json | 1 + .../codegen-output-py/models/features.json | 48 ++- .../codegen-output-py/models/features.smithy | 14 + .../tests/test_client_snapshots.py | 19 + scripts/verifications/import-cost.json | 2 +- 23 files changed, 616 insertions(+), 161 deletions(-) create mode 100644 codegen-output-py/features-client/src/features_client/aio/checksums.py create mode 100644 codegen-output-py/features-client/src/features_client/checksums.py create mode 100644 packages/smithy-python/.changes/next-release/smithy-python-feature-dd5d0a23a2f040bfab12e48ed51bbe70.json create mode 100644 packages/smithy-python/src/smithy_python/aws/_checksums.py diff --git a/codegen-output-py/features-client/.smithy-python-manifest.json b/codegen-output-py/features-client/.smithy-python-manifest.json index 8bb016bf2..6f88cb95e 100644 --- a/codegen-output-py/features-client/.smithy-python-manifest.json +++ b/codegen-output-py/features-client/.smithy-python-manifest.json @@ -1,19 +1,21 @@ { "files": { "README.md": "2806a5e5abe658301cad30030818d656fc9095fd3e510bc14744e2c053766c38", - "pyproject.toml": "3bf9e8ba4f2d5620cb43a34b5a05445485d96bbc71b79d568cfe10e92d3deef6", + "pyproject.toml": "d48190684abc74f2ac25e9d4e99e7ab5e9a85c036254cd4cfbfa59c85e41b43b", "src/features_client/__init__.py": "32592f5725712e19c306d0c817040e64c67203ae420e3fac2a05301915b742aa", "src/features_client/_private/__init__.py": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/features_client/_private/endpoints.py": "90e1bc94c3ca6338b495b94870e7b1e433c1c2da064e336a85ad94616953916a", - "src/features_client/_private/schemas.py": "dd35b878aad2db78ea2903357eb190b596acc7c7723d3b49488ca3e7b360f916", + "src/features_client/_private/schemas.py": "b013d45e1cb2797a288606657f640f0e7d33a560a8e4fe6a4bf2e9ab0f65c15a", "src/features_client/aio/__init__.py": "2d6c204a7bbceeed5b175fe0df922722d341068027b29287cfdcbb9cb29403af", - "src/features_client/aio/client.py": "72e1e989866364a4a80f36056e177d67d519d5cab966dbae870f0a10f9f4fb81", - "src/features_client/aio/config.py": "0b8ab6e0648b479de7a9befe6742fbe72865bee2fab11a4533fbede79516e99a", + "src/features_client/aio/checksums.py": "95697fce8d5534f9dbf9e7999c16826ccf29d01d62a4d651ce980c2a90bf18ec", + "src/features_client/aio/client.py": "308dfd230cb311ea86e94590300e7c158012dcab7d5e2dc87961635b82b38146", + "src/features_client/aio/config.py": "94153805ac5b924c0c7c29942cb1f0bbba15c7c06d481bfa92c4f2586bc869e6", "src/features_client/aio/user_agent.py": "05cbb5932a96cb83d55ece172f9b9b5b8aeb625782140647e177d5d5cbd18dd5", - "src/features_client/client.py": "43ec0fe0d6616d2d8f3219e481997b773cbd3e93035f8a6965ce04b652b14448", - "src/features_client/config.py": "8852d5679ab46123361451298ec619ee6506c6d0488fad2f940a29972e1cc755", - "src/features_client/models.py": "27b38abaebb0f568b92052d2c42dee9f804fcb00f15b25ef2c2f226e2d89ec96", - "src/features_client/models.pyi": "b0c577481ee04ac11b91b85eee3cf94de8eebbd977d95025b87736f3bc8c33f3", + "src/features_client/checksums.py": "656fed64fc55e049820b1b7c36778d6e16e1607a74e7fb356613dcdd54309073", + "src/features_client/client.py": "dc4c4a211ead82a0a63aa2098491ceefa6fef578776fe108e5e06eb5b98e5d6f", + "src/features_client/config.py": "a24fb8543d342425a2937f58f8f3ef152f30c8826c4b7764e60a78fc3b553dc2", + "src/features_client/models.py": "17dd691ffe9049cc1751916244006ff2135d9ac89be57ef7d80951d95e630eaa", + "src/features_client/models.pyi": "fa65739c238fa143750d65d3d839687a57a6850eccb1ad1b98cbe9d58d2635a7", "src/features_client/py.typed": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "src/features_client/user_agent.py": "6d7e1477fa0123330b26d750070dcb49afe76bd14baa8bbe4b66a3d28e7ad75f", "tests/test_endpoints.py": "395f805a2889159097487f70f8ee3d6bfb83403ec370dc97e56e5e9304ba93a9" diff --git a/codegen-output-py/features-client/pyproject.toml b/codegen-output-py/features-client/pyproject.toml index ddf01f809..99bf92497 100644 --- a/codegen-output-py/features-client/pyproject.toml +++ b/codegen-output-py/features-client/pyproject.toml @@ -9,7 +9,7 @@ requires-python = ">=3.12" keywords = ["smithy", "features_client"] license = {text = "Apache-2.0"} dependencies = [ - "smithy-aws-core~=0.16.0", + "smithy-aws-core[checksums]~=0.16.0", "smithy-core~=0.13.0", "smithy-http[aiohttp,cbor,urllib3]~=0.10.0", ] diff --git a/codegen-output-py/features-client/src/features_client/_private/schemas.py b/codegen-output-py/features-client/src/features_client/_private/schemas.py index ad3060e75..7ffe97875 100644 --- a/codegen-output-py/features-client/src/features_client/_private/schemas.py +++ b/codegen-output-py/features-client/src/features_client/_private/schemas.py @@ -3,221 +3,247 @@ from smithy_core._schema_compact import StaticOperationSchema, StaticSchema n0 = "example.features" -_s0 = "DescribeNoteInput" -_s1 = "smithy.synthetic#originalShapeId" -_s2 = "example.features#DescribeNoteInput" -_s3 = "smithy.api#input" -_s4 = "id" -_s5 = "NoteState" -_s6 = "DRAFT" -_s7 = "smithy.api#enumValue" -_s8 = "SAVED" -_s9 = "REJECTED" -_s10 = "DescribeNoteOutput" -_s11 = "example.features#DescribeNoteOutput" -_s12 = "smithy.api#output" -_s13 = "state" -_s14 = "reason" -_s15 = "GetNoteInput" -_s16 = "example.features#GetNoteInput" -_s17 = "GetNoteOutput" -_s18 = "example.features#GetNoteOutput" -_s19 = "text" -_s20 = "GetThingInput" -_s21 = "example.features#GetThingInput" -_s22 = "name" -_s23 = "GetThingOutput" -_s24 = "example.features#GetThingOutput" -_s25 = "value" -_s26 = "ListNotesInput" -_s27 = "example.features#ListNotesInput" -_s28 = "nextToken" -_s29 = "pageSize" -_s30 = "NoteList" -_s31 = "member" -_s32 = "ListNotesOutput" -_s33 = "example.features#ListNotesOutput" -_s34 = "items" -_s35 = "NoteNotFound" -_s36 = "smithy.api#error" -_s37 = "client" -_s38 = "message" -_s39 = "PluginNames" -_s40 = "PutNoteInput" -_s41 = "example.features#PutNoteInput" -_s42 = "PutNoteOutput" -_s43 = "example.features#PutNoteOutput" -_s44 = "ThingTag" -_s45 = "key" -_s46 = "PutThingInput" -_s47 = "example.features#PutThingInput" -_s48 = "smithy.rules#contextParam" -_s49 = "smithy.api#required" -_s50 = "tag" -_s51 = "plugins" -_s52 = "EchoInput" -_s53 = "smithy.api#Unit" -_s54 = "EchoOutput" -_s55 = "PingInput" -_s56 = "PingOutput" -_s57 = "PutThingOutput" -_s58 = "DescribeNote" -_s59 = "smithy.waiters#waitable" -_s60 = "Echo" -_s61 = "GetNote" -_s62 = "GetThing" -_s63 = "ListNotes" -_s64 = "smithy.rules#staticContextParams" -_s65 = "Ping" -_s66 = "PutNote" -_s67 = "PutThing" -_s68 = "FieldNotes" -_s69 = "aws.api#service" -_s70 = "smithy.protocols#rpcv2Cbor" +_s0 = "ChecksumAlgorithm" +_s1 = "CRC32" +_s2 = "smithy.api#enumValue" +_s3 = "SHA256" +_s4 = "ChecksumMode" +_s5 = "ENABLED" +_s6 = "DescribeNoteInput" +_s7 = "smithy.synthetic#originalShapeId" +_s8 = "example.features#DescribeNoteInput" +_s9 = "smithy.api#input" +_s10 = "id" +_s11 = "NoteState" +_s12 = "DRAFT" +_s13 = "SAVED" +_s14 = "REJECTED" +_s15 = "DescribeNoteOutput" +_s16 = "example.features#DescribeNoteOutput" +_s17 = "smithy.api#output" +_s18 = "state" +_s19 = "reason" +_s20 = "GetNoteInput" +_s21 = "example.features#GetNoteInput" +_s22 = "checksumMode" +_s23 = "GetNoteOutput" +_s24 = "example.features#GetNoteOutput" +_s25 = "text" +_s26 = "GetThingInput" +_s27 = "example.features#GetThingInput" +_s28 = "name" +_s29 = "GetThingOutput" +_s30 = "example.features#GetThingOutput" +_s31 = "value" +_s32 = "ListNotesInput" +_s33 = "example.features#ListNotesInput" +_s34 = "nextToken" +_s35 = "pageSize" +_s36 = "NoteList" +_s37 = "member" +_s38 = "ListNotesOutput" +_s39 = "example.features#ListNotesOutput" +_s40 = "items" +_s41 = "NoteNotFound" +_s42 = "smithy.api#error" +_s43 = "client" +_s44 = "message" +_s45 = "PluginNames" +_s46 = "PutNoteInput" +_s47 = "example.features#PutNoteInput" +_s48 = "checksumAlgorithm" +_s49 = "PutNoteOutput" +_s50 = "example.features#PutNoteOutput" +_s51 = "ThingTag" +_s52 = "key" +_s53 = "PutThingInput" +_s54 = "example.features#PutThingInput" +_s55 = "smithy.rules#contextParam" +_s56 = "smithy.api#required" +_s57 = "tag" +_s58 = "plugins" +_s59 = "EchoInput" +_s60 = "smithy.api#Unit" +_s61 = "EchoOutput" +_s62 = "PingInput" +_s63 = "PingOutput" +_s64 = "PutThingOutput" +_s65 = "DescribeNote" +_s66 = "smithy.waiters#waitable" +_s67 = "Echo" +_s68 = "GetNote" +_s69 = "aws.protocols#httpChecksum" +_s70 = "GetThing" +_s71 = "ListNotes" +_s72 = "smithy.rules#staticContextParams" +_s73 = "Ping" +_s74 = "PutNote" +_s75 = "PutThing" +_s76 = "FieldNotes" +_s77 = "aws.api#service" +_s78 = "smithy.protocols#rpcv2Cbor" + +CHECKSUM_ALGORITHM: StaticSchema = ( + 14, + n0, + _s0, + 0, + (_s1, _s3), + ((-1, {_s2: _s1}), (-1, {_s2: _s3})), +) + +CHECKSUM_MODE: StaticSchema = ( + 14, + n0, + _s4, + 0, + (_s5,), + ((-1, {_s2: _s5}),), +) DESCRIBE_NOTE_INPUT: StaticSchema = ( 18, n0, - _s0, - {_s1: _s2, _s3: None}, - (_s4,), + _s6, + {_s7: _s8, _s9: None}, + (_s10,), ((3, 1),), ) NOTE_STATE: StaticSchema = ( 14, n0, - _s5, + _s11, 0, - (_s6, _s8, _s9), - ((-1, {_s7: _s6}), (-1, {_s7: _s8}), (-1, {_s7: _s9})), + (_s12, _s13, _s14), + ((-1, {_s2: _s12}), (-1, {_s2: _s13}), (-1, {_s2: _s14})), ) DESCRIBE_NOTE_OUTPUT: StaticSchema = ( 18, n0, - _s10, - {_s1: _s11, _s12: None}, - (_s4, _s13, _s14), + _s15, + {_s7: _s16, _s17: None}, + (_s10, _s18, _s19), ((3, 0), (NOTE_STATE, 0), (3, 0)), ) GET_NOTE_INPUT: StaticSchema = ( 18, n0, - _s15, - {_s1: _s16, _s3: None}, - (_s4,), - ((3, 0),), + _s20, + {_s7: _s21, _s9: None}, + (_s10, _s22), + ((3, 0), (CHECKSUM_MODE, 0)), ) GET_NOTE_OUTPUT: StaticSchema = ( 18, n0, - _s17, - {_s1: _s18, _s12: None}, - (_s19,), + _s23, + {_s7: _s24, _s17: None}, + (_s25,), ((3, 0),), ) GET_THING_INPUT: StaticSchema = ( 18, n0, - _s20, - {_s1: _s21, _s3: None}, - (_s22,), + _s26, + {_s7: _s27, _s9: None}, + (_s28,), ((3, 0),), ) GET_THING_OUTPUT: StaticSchema = ( 18, n0, - _s23, - {_s1: _s24, _s12: None}, - (_s25,), + _s29, + {_s7: _s30, _s17: None}, + (_s31,), ((3, 0),), ) LIST_NOTES_INPUT: StaticSchema = ( 18, n0, - _s26, - {_s1: _s27, _s3: None}, - (_s28, _s29), + _s32, + {_s7: _s33, _s9: None}, + (_s34, _s35), ((3, 0), (7, 0)), ) NOTE_LIST: StaticSchema = ( 16, n0, - _s30, + _s36, 0, - (_s31,), + (_s37,), ((3, 0),), ) LIST_NOTES_OUTPUT: StaticSchema = ( 18, n0, - _s32, - {_s1: _s33, _s12: None}, - (_s34, _s28), + _s38, + {_s7: _s39, _s17: None}, + (_s40, _s34), ((NOTE_LIST, 0), (3, 0)), ) NOTE_NOT_FOUND: StaticSchema = ( 18, n0, - _s35, - {_s36: _s37}, - (_s38,), + _s41, + {_s42: _s43}, + (_s44,), ((3, 0),), ) PLUGIN_NAMES: StaticSchema = ( 16, n0, - _s39, + _s45, 0, - (_s31,), + (_s37,), ((3, 0),), ) PUT_NOTE_INPUT: StaticSchema = ( 18, n0, - _s40, - {_s1: _s41, _s3: None}, - (_s19,), - ((3, 0),), + _s46, + {_s7: _s47, _s9: None}, + (_s25, _s48), + ((3, 0), (CHECKSUM_ALGORITHM, 0)), ) PUT_NOTE_OUTPUT: StaticSchema = ( 18, n0, - _s42, - {_s1: _s43, _s12: None}, - (_s4,), + _s49, + {_s7: _s50, _s17: None}, + (_s10,), ((3, 0),), ) THING_TAG: StaticSchema = ( 18, n0, - _s44, + _s51, 0, - (_s45, _s25), + (_s52, _s31), ((3, 0), (3, 0)), ) PUT_THING_INPUT: StaticSchema = ( 18, n0, - _s46, - {_s1: _s47, _s3: None}, - (_s22, _s50, _s51), + _s53, + {_s7: _s54, _s9: None}, + (_s28, _s57, _s58), ( - (3, {_s48: MappingProxyType({"name": "Name"}), _s49: None}), + (3, {_s55: MappingProxyType({"name": "Name"}), _s56: None}), (THING_TAG, 0), (PLUGIN_NAMES, 0), ), @@ -226,44 +252,44 @@ ECHO_INPUT: StaticSchema = ( 18, n0, - _s52, - {_s1: _s53, _s3: None}, + _s59, + {_s7: _s60, _s9: None}, ) ECHO_OUTPUT: StaticSchema = ( 18, n0, - _s54, - {_s1: _s53, _s12: None}, + _s61, + {_s7: _s60, _s17: None}, ) PING_INPUT: StaticSchema = ( 18, n0, - _s55, - {_s1: _s53, _s3: None}, + _s62, + {_s7: _s60, _s9: None}, ) PING_OUTPUT: StaticSchema = ( 18, n0, - _s56, - {_s1: _s53, _s12: None}, + _s63, + {_s7: _s60, _s17: None}, ) PUT_THING_OUTPUT: StaticSchema = ( 18, n0, - _s57, - {_s1: _s53, _s12: None}, + _s64, + {_s7: _s60, _s17: None}, ) DESCRIBE_NOTE: StaticOperationSchema = ( 23, n0, - _s58, + _s65, { - _s59: MappingProxyType( + _s66: MappingProxyType( { "NoteSaved": MappingProxyType( { @@ -340,7 +366,7 @@ ECHO: StaticOperationSchema = ( 23, n0, - _s60, + _s67, 0, ECHO_INPUT, ECHO_OUTPUT, @@ -350,8 +376,15 @@ GET_NOTE: StaticOperationSchema = ( 23, n0, - _s61, - 0, + _s68, + { + _s69: MappingProxyType( + { + "requestValidationModeMember": "checksumMode", + "responseAlgorithms": ("CRC32",), + } + ) + }, GET_NOTE_INPUT, GET_NOTE_OUTPUT, (), @@ -360,7 +393,7 @@ GET_THING: StaticOperationSchema = ( 23, n0, - _s62, + _s70, 0, GET_THING_INPUT, GET_THING_OUTPUT, @@ -370,8 +403,8 @@ LIST_NOTES: StaticOperationSchema = ( 23, n0, - _s63, - {_s64: MappingProxyType({"Kind": MappingProxyType({"value": "list"})})}, + _s71, + {_s72: MappingProxyType({"Kind": MappingProxyType({"value": "list"})})}, LIST_NOTES_INPUT, LIST_NOTES_OUTPUT, (), @@ -380,8 +413,8 @@ PING: StaticOperationSchema = ( 23, n0, - _s65, - {_s64: MappingProxyType({"Kind": MappingProxyType({"value": "ping"})})}, + _s73, + {_s72: MappingProxyType({"Kind": MappingProxyType({"value": "ping"})})}, PING_INPUT, PING_OUTPUT, (), @@ -390,8 +423,15 @@ PUT_NOTE: StaticOperationSchema = ( 23, n0, - _s66, - 0, + _s74, + { + _s69: MappingProxyType( + { + "requestChecksumRequired": True, + "requestAlgorithmMember": "checksumAlgorithm", + } + ) + }, PUT_NOTE_INPUT, PUT_NOTE_OUTPUT, (), @@ -400,8 +440,8 @@ PUT_THING: StaticOperationSchema = ( 23, n0, - _s67, - {_s64: MappingProxyType({"Kind": MappingProxyType({"value": "put"})})}, + _s75, + {_s72: MappingProxyType({"Kind": MappingProxyType({"value": "put"})})}, PUT_THING_INPUT, PUT_THING_OUTPUT, (), @@ -410,6 +450,6 @@ FIELD_NOTES: StaticSchema = ( 21, n0, - _s68, - {_s69: MappingProxyType({"sdkId": "Field Notes"}), _s70: None}, + _s76, + {_s77: MappingProxyType({"sdkId": "Field Notes"}), _s78: None}, ) diff --git a/codegen-output-py/features-client/src/features_client/aio/checksums.py b/codegen-output-py/features-client/src/features_client/aio/checksums.py new file mode 100644 index 000000000..d587a643c --- /dev/null +++ b/codegen-output-py/features-client/src/features_client/aio/checksums.py @@ -0,0 +1,8 @@ +from smithy_aws_core.aio.interceptors.checksums import AsyncFlexibleChecksumsInterceptor + +from features_client.aio.config import AsyncFieldNotesConfig + + +def flexible_checksums_plugin(config: AsyncFieldNotesConfig) -> None: + "Add and validate the checksums the operations model." + config.interceptors.append(AsyncFlexibleChecksumsInterceptor()) diff --git a/codegen-output-py/features-client/src/features_client/aio/client.py b/codegen-output-py/features-client/src/features_client/aio/client.py index 9545124c3..ddb540343 100644 --- a/codegen-output-py/features-client/src/features_client/aio/client.py +++ b/codegen-output-py/features-client/src/features_client/aio/client.py @@ -15,6 +15,7 @@ from smithy_http.plugins import user_agent_plugin from features_client import models +from features_client.aio.checksums import flexible_checksums_plugin from features_client.aio.config import AsyncFieldNotesConfig, Plugin from features_client.aio.user_agent import aws_user_agent_plugin @@ -28,7 +29,11 @@ class AsyncFieldNotesClient(AsyncClient[AsyncFieldNotesConfig]): token auth, API key auth, optional auth, and no auth. """ - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + flexible_checksums_plugin, + user_agent_plugin, + ) @overload async def describe_note( diff --git a/codegen-output-py/features-client/src/features_client/aio/config.py b/codegen-output-py/features-client/src/features_client/aio/config.py index dd87c1100..2fc006ed3 100644 --- a/codegen-output-py/features-client/src/features_client/aio/config.py +++ b/codegen-output-py/features-client/src/features_client/aio/config.py @@ -10,9 +10,19 @@ from smithy_aws_core.aio.config.filesystem import AsyncFileSystem from smithy_aws_core.config.resolvers import ( EndpointUriResolver, + resolve_request_checksum_calculation_program, + resolve_response_checksum_validation_program, resolve_use_fips_endpoint_program, ) -from smithy_aws_core.config.types import FieldSpec +from smithy_aws_core.config.types import ( + FieldSpec, + RequestChecksumCalculation, + ResponseChecksumValidation, +) +from smithy_aws_core.config.validators import ( + validate_request_checksum_calculation, + validate_response_checksum_validation, +) from smithy_aws_core.endpoints import AWS_RULES_EXTENSION from smithy_core.aio.interfaces import AsyncEndpointResolver from smithy_core.aio.interfaces.auth import AsyncAuthScheme @@ -72,6 +82,8 @@ class _AsyncFieldNotesConfigOverrides(AsyncAwsConfigOverrides, total=False): stage: str | None force_path_style: bool | None use_fips_endpoint: bool | None + request_checksum_calculation: RequestChecksumCalculation | None + response_checksum_validation: ResponseChecksumValidation | None @dataclass(kw_only=True, repr=False, init=False) @@ -120,6 +132,12 @@ class AsyncFieldNotesConfig(AsyncAwsConfig): use_fips_endpoint: bool | None = None "Whether to use a FIPS endpoint." + request_checksum_calculation: RequestChecksumCalculation | None = None + "When to calculate request checksums: `when_supported` (the default) or `when_required`, only when the operation requires one or the request sets an algorithm." + + response_checksum_validation: ResponseChecksumValidation | None = None + "When to validate response checksums: `when_supported` (the default) or `when_required`, only when the request enables validation." + _FIELDS: ClassVar[dict[str, FieldSpec]] = { **AsyncAwsConfig._FIELDS, "endpoint_uri": FieldSpec( @@ -157,6 +175,16 @@ class AsyncFieldNotesConfig(AsyncAwsConfig): "use_fips_endpoint": FieldSpec( default=None, resolver=resolve_use_fips_endpoint_program ), + "request_checksum_calculation": FieldSpec( + default="when_supported", + resolver=resolve_request_checksum_calculation_program, + validator=validate_request_checksum_calculation, + ), + "response_checksum_validation": FieldSpec( + default="when_supported", + resolver=resolve_response_checksum_validation_program, + validator=validate_response_checksum_validation, + ), "transport": FieldSpec(default_factory=lambda: AIOHTTPClient()), } diff --git a/codegen-output-py/features-client/src/features_client/checksums.py b/codegen-output-py/features-client/src/features_client/checksums.py new file mode 100644 index 000000000..ffecb62f8 --- /dev/null +++ b/codegen-output-py/features-client/src/features_client/checksums.py @@ -0,0 +1,8 @@ +from smithy_aws_core.interceptors.checksums import FlexibleChecksumsInterceptor + +from features_client.config import FieldNotesConfig + + +def flexible_checksums_plugin(config: FieldNotesConfig) -> None: + "Add and validate the checksums the operations model." + config.interceptors.append(FlexibleChecksumsInterceptor()) diff --git a/codegen-output-py/features-client/src/features_client/client.py b/codegen-output-py/features-client/src/features_client/client.py index 25c0862eb..a90b92552 100644 --- a/codegen-output-py/features-client/src/features_client/client.py +++ b/codegen-output-py/features-client/src/features_client/client.py @@ -15,6 +15,7 @@ from smithy_http.plugins import user_agent_plugin from features_client import models +from features_client.checksums import flexible_checksums_plugin from features_client.config import FieldNotesConfig, Plugin from features_client.user_agent import aws_user_agent_plugin @@ -28,7 +29,11 @@ class FieldNotesClient(Client[FieldNotesConfig]): token auth, API key auth, optional auth, and no auth. """ - _client_plugins = (aws_user_agent_plugin, user_agent_plugin) + _client_plugins = ( + aws_user_agent_plugin, + flexible_checksums_plugin, + user_agent_plugin, + ) @overload def describe_note( diff --git a/codegen-output-py/features-client/src/features_client/config.py b/codegen-output-py/features-client/src/features_client/config.py index 93565fb41..4f824e3fd 100644 --- a/codegen-output-py/features-client/src/features_client/config.py +++ b/codegen-output-py/features-client/src/features_client/config.py @@ -7,9 +7,19 @@ from smithy_aws_core.config.filesystem import FileSystem from smithy_aws_core.config.resolvers import ( EndpointUriResolver, + resolve_request_checksum_calculation_program, + resolve_response_checksum_validation_program, resolve_use_fips_endpoint_program, ) -from smithy_aws_core.config.types import FieldSpec +from smithy_aws_core.config.types import ( + FieldSpec, + RequestChecksumCalculation, + ResponseChecksumValidation, +) +from smithy_aws_core.config.validators import ( + validate_request_checksum_calculation, + validate_response_checksum_validation, +) from smithy_aws_core.endpoints import AWS_RULES_EXTENSION from smithy_core.auth import DefaultAuthResolver from smithy_core.endpoints import BddEndpointResolver @@ -67,6 +77,8 @@ class _FieldNotesConfigOverrides(AwsConfigOverrides, total=False): stage: str | None force_path_style: bool | None use_fips_endpoint: bool | None + request_checksum_calculation: RequestChecksumCalculation | None + response_checksum_validation: ResponseChecksumValidation | None @dataclass(kw_only=True, repr=False, init=False) @@ -115,6 +127,12 @@ class FieldNotesConfig(AwsConfig): use_fips_endpoint: bool | None = None "Whether to use a FIPS endpoint." + request_checksum_calculation: RequestChecksumCalculation | None = None + "When to calculate request checksums: `when_supported` (the default) or `when_required`, only when the operation requires one or the request sets an algorithm." + + response_checksum_validation: ResponseChecksumValidation | None = None + "When to validate response checksums: `when_supported` (the default) or `when_required`, only when the request enables validation." + _FIELDS: ClassVar[dict[str, FieldSpec]] = { **AwsConfig._FIELDS, "endpoint_uri": FieldSpec( @@ -152,6 +170,16 @@ class FieldNotesConfig(AwsConfig): "use_fips_endpoint": FieldSpec( default=None, resolver=resolve_use_fips_endpoint_program ), + "request_checksum_calculation": FieldSpec( + default="when_supported", + resolver=resolve_request_checksum_calculation_program, + validator=validate_request_checksum_calculation, + ), + "response_checksum_validation": FieldSpec( + default="when_supported", + resolver=resolve_response_checksum_validation_program, + validator=validate_response_checksum_validation, + ), "transport": FieldSpec(default_factory=lambda: Urllib3HTTPClient()), } diff --git a/codegen-output-py/features-client/src/features_client/models.py b/codegen-output-py/features-client/src/features_client/models.py index f67e4b056..8e2f5e49b 100644 --- a/codegen-output-py/features-client/src/features_client/models.py +++ b/codegen-output-py/features-client/src/features_client/models.py @@ -14,6 +14,8 @@ class ServiceError(ModeledError): _MODEL_INDEX = { + "ChecksumAlgorithm": "CHECKSUM_ALGORITHM", + "ChecksumMode": "CHECKSUM_MODE", "DescribeNoteInput": "DESCRIBE_NOTE_INPUT", "DescribeNoteOutput": "DESCRIBE_NOTE_OUTPUT", "GetNoteInput": "GET_NOTE_INPUT", @@ -85,6 +87,8 @@ class ServiceError(ModeledError): target_names=_TARGET_NAMES, shape_names=frozenset( { + "ChecksumAlgorithm", + "ChecksumMode", "DescribeNoteInput", "DescribeNoteOutput", "EchoInput", diff --git a/codegen-output-py/features-client/src/features_client/models.pyi b/codegen-output-py/features-client/src/features_client/models.pyi index 9b75c082c..91f650c14 100644 --- a/codegen-output-py/features-client/src/features_client/models.pyi +++ b/codegen-output-py/features-client/src/features_client/models.pyi @@ -19,6 +19,8 @@ __all__ = [ "PING", "PUT_NOTE", "PUT_THING", + "ChecksumAlgorithm", + "ChecksumMode", "DescribeNoteInput", "DescribeNoteOutput", "EchoInput", @@ -55,6 +57,13 @@ class ServiceError(ModeledError): implicit, and shared exception types. """ +class ChecksumAlgorithm(UnknownEnumMixin, StrEnum): + CRC32 = "CRC32" + SHA256 = "SHA256" + +class ChecksumMode(UnknownEnumMixin, StrEnum): + ENABLED = "ENABLED" + @dataclass(kw_only=True) class DescribeNoteInput(_SerdeShape): "Dataclass for DescribeNoteInput structure." @@ -87,11 +96,13 @@ class GetNoteInput(_SerdeShape): "Dataclass for GetNoteInput structure." id: str | None = ... + checksum_mode: str | None = ... class GetNoteInputDict(TypedDict, total=False): "Dictionary form of `GetNoteInput`." id: str | None + checksum_mode: str | None @dataclass(kw_only=True) class GetNoteOutput(_SerdeShape): @@ -183,11 +194,13 @@ class PutNoteInput(_SerdeShape): "Dataclass for PutNoteInput structure." text: str | None = ... + checksum_algorithm: str | None = ... class PutNoteInputDict(TypedDict, total=False): "Dictionary form of `PutNoteInput`." text: str | None + checksum_algorithm: str | None @dataclass(kw_only=True) class PutNoteOutput(_SerdeShape): diff --git a/designs/codegen/client.md b/designs/codegen/client.md index 56f8cb7a5..de952df9a 100644 --- a/designs/codegen/client.md +++ b/designs/codegen/client.md @@ -413,6 +413,20 @@ generator's `AwsEndpointRulesIntegration`: S3's bucket and S3 Control's account ID host prefix customizations come with S3 support. +`AwsChecksumsIntegration` follows the Java generator's +`AwsFlexibleChecksumsIntegration` for AWS services whose operations have the +`aws.protocols#httpChecksum` trait. Schemas keep the trait, and clients apply +`flexible_checksums_plugin` from their `checksums` modules, which adds +`FlexibleChecksumsInterceptor`, or `AsyncFlexibleChecksumsInterceptor` in async +clients. These need the `checksums` extra of `smithy-aws-core`. Each setting is +added only where it has an effect, and resolves from the environment and +profile with a default of `when_supported`: + +* `request_checksum_calculation`, when an operation requires a request checksum + or names a `requestAlgorithmMember`. +* `response_checksum_validation`, when an operation has `responseAlgorithms` + and a `requestValidationModeMember`. + ## Clients and Configuration Service classes are thin subclasses of `Client[Config]` and diff --git a/packages/smithy-python/.changes/next-release/smithy-python-feature-dd5d0a23a2f040bfab12e48ed51bbe70.json b/packages/smithy-python/.changes/next-release/smithy-python-feature-dd5d0a23a2f040bfab12e48ed51bbe70.json new file mode 100644 index 000000000..e2d0c1027 --- /dev/null +++ b/packages/smithy-python/.changes/next-release/smithy-python-feature-dd5d0a23a2f040bfab12e48ed51bbe70.json @@ -0,0 +1,4 @@ +{ + "type": "feature", + "description": "Generated AWS clients add and validate flexible checksums for operations with the aws.protocols#httpChecksum trait, with the request_checksum_calculation and response_checksum_validation config fields." +} \ No newline at end of file diff --git a/packages/smithy-python/src/smithy_python/aws/__init__.py b/packages/smithy-python/src/smithy_python/aws/__init__.py index 45da20f61..8520ff622 100644 --- a/packages/smithy-python/src/smithy_python/aws/__init__.py +++ b/packages/smithy-python/src/smithy_python/aws/__init__.py @@ -17,6 +17,7 @@ from typing import Final +from ._checksums import AwsChecksumsIntegration from ._config import AwsConfigIntegration from ._dependencies import SMITHY_AWS_CORE from ._endpoints import AwsEndpointsIntegration @@ -41,6 +42,7 @@ "REST_JSON", "REST_XML", "SMITHY_AWS_CORE", + "AwsChecksumsIntegration", "AwsConfigIntegration", "AwsEndpointsIntegration", "AwsIdentityIntegration", @@ -50,5 +52,6 @@ AwsConfigIntegration(), AwsIdentityIntegration(), AwsEndpointsIntegration(), + AwsChecksumsIntegration(), ) """The integrations AWS services get, in order.""" diff --git a/packages/smithy-python/src/smithy_python/aws/_checksums.py b/packages/smithy-python/src/smithy_python/aws/_checksums.py new file mode 100644 index 000000000..1e14dcf86 --- /dev/null +++ b/packages/smithy-python/src/smithy_python/aws/_checksums.py @@ -0,0 +1,179 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +"""Flexible checksums for AWS services with the ``aws.protocols#httpChecksum`` trait. + +As in the Java generator's ``AwsFlexibleChecksumsIntegration``, clients apply a +plugin that adds the runtime's checksum interceptor. Their configs get +``request_checksum_calculation`` when an operation calculates request checksums, +and ``response_checksum_validation`` when one validates response checksums. +""" + +from __future__ import annotations + +from collections.abc import Collection, Mapping +from dataclasses import dataclass +from typing import TYPE_CHECKING, Final + +from .. import model as _model +from .. import models as _models +from ..dependencies import Dependency +from ..integrations import ClientIntegration, ClientMode +from ..symbols import TypeReference +from ._dependencies import SMITHY_AWS_CORE + +if TYPE_CHECKING: + from ..clients import ClientPlan + from ..generation import ClientSettings, GenerationContext + from ..integrations import Part + +__all__ = ["AwsChecksumsIntegration", "ChecksumField", "checksum_fields"] + +_SERVICE: Final = _model.ShapeId("aws.api", "service") +_HTTP_CHECKSUM: Final = _model.ShapeId("aws.protocols", "httpChecksum") +_PLUGIN: Final = "flexible_checksums_plugin" + + +@dataclass(frozen=True, slots=True) +class ChecksumField: + """A checksum setting's config field.""" + + name: str + type: TypeReference + documentation: str + + @property + def spec(self) -> tuple[Part, ...]: + """The field's ``FieldSpec`` arguments.""" + return ( + 'default="when_supported", resolver=', + _aws(f"resolve_{self.name}_program", "config.resolvers"), + ", validator=", + _aws(f"validate_{self.name}", "config.validators"), + ) + + +_REQUEST: Final = ChecksumField( + "request_checksum_calculation", + TypeReference( + "RequestChecksumCalculation", + "smithy_aws_core.config.types", + dependencies=(SMITHY_AWS_CORE,), + ), + "When to calculate request checksums: `when_supported` (the default) or " + "`when_required`, only when the operation requires one or the request sets an " + "algorithm.", +) +_RESPONSE: Final = ChecksumField( + "response_checksum_validation", + TypeReference( + "ResponseChecksumValidation", + "smithy_aws_core.config.types", + dependencies=(SMITHY_AWS_CORE,), + ), + "When to validate response checksums: `when_supported` (the default) or " + "`when_required`, only when the request enables validation.", +) + + +class AwsChecksumsIntegration(ClientIntegration): + """Flexible checksums, for AWS services with ``httpChecksum`` operations.""" + + def matches(self, service: _model.ServiceShape) -> bool: + # The operations are checked when fields and plugins are planned. + return service.has_trait(_SERVICE) + + def config_fields(self, service: _model.ServiceShape) -> Collection[str]: + del service + return (_REQUEST.name, _RESPONSE.name) + + def client_plugins( + self, plan: ClientPlan, mode: ClientMode, package: str + ) -> tuple[TypeReference, ...]: + if not _traits(plan): + return () + return (TypeReference(_PLUGIN, _module(package, mode)),) + + def write_files( + self, + context: GenerationContext[ClientSettings], + plan: ClientPlan, + modes: tuple[ClientMode, ClientMode], + ) -> None: + if not _traits(plan): + return + package = context.settings.import_name + for mode in modes: + module = _module(package, mode) + writer = context.files.python_module( + f"src/{module.replace('.', '/')}.py", module + ) + config = TypeReference( + mode.config, f"{package}.{mode.directory.replace('/', '.')}config" + ) + interceptor = ( + _checksums("AsyncFlexibleChecksumsInterceptor", "aio.interceptors") + if mode.is_async + else _checksums("FlexibleChecksumsInterceptor", "interceptors") + ) + writer.line("def ", _PLUGIN, "(config: ", config, ") -> None:") + with writer.indent(): + writer.line( + _quote("Add and validate the checksums the operations model.") + ) + writer.line("config.interceptors.append(", interceptor, "())") + + +def checksum_fields(plan: ClientPlan) -> tuple[ChecksumField, ...]: + """The checksum settings that have an effect on a client, in order.""" + traits = _traits(plan) + fields: list[ChecksumField] = [] + if any( + trait.get("requestChecksumRequired") is True + or isinstance(trait.get("requestAlgorithmMember"), str) + for trait in traits + ): + fields.append(_REQUEST) + if any( + trait.get("responseAlgorithms") + and isinstance(trait.get("requestValidationModeMember"), str) + for trait in traits + ): + fields.append(_RESPONSE) + return tuple(fields) + + +def _traits(plan: ClientPlan) -> tuple[Mapping[str, _model.Node], ...]: + return tuple( + trait + for operation in plan.operations + if isinstance(trait := operation.operation.get_trait(_HTTP_CHECKSUM), Mapping) + ) + + +def _module(package: str, mode: ClientMode) -> str: + return f"{package}.{mode.directory.replace('/', '.')}checksums" + + +def _aws(name: str, module: str) -> TypeReference: + return TypeReference( + name, f"smithy_aws_core.{module}", dependencies=(SMITHY_AWS_CORE,) + ) + + +def _checksums(name: str, module: str) -> TypeReference: + return TypeReference( + name, + f"smithy_aws_core.{module}.checksums", + dependencies=( + Dependency( + package=SMITHY_AWS_CORE.package, + specifier=SMITHY_AWS_CORE.specifier, + group="runtime", + extras=("checksums",), + ), + ), + ) + + +def _quote(value: str) -> str: + return _models._quote(value) # pyright: ignore[reportPrivateUsage] diff --git a/packages/smithy-python/src/smithy_python/aws/_config.py b/packages/smithy-python/src/smithy_python/aws/_config.py index 345216f0e..e201e7378 100644 --- a/packages/smithy-python/src/smithy_python/aws/_config.py +++ b/packages/smithy-python/src/smithy_python/aws/_config.py @@ -14,6 +14,7 @@ from .._client_emitter import HOST_PREFIX_FIELD from ..integrations import ClientIntegration, ClientMode, ClientNames, ConfigPlan from ..symbols import TypeReference +from ._checksums import checksum_fields from ._dependencies import SMITHY_AWS_CORE from ._endpoints import BuiltinField, builtin_fields, static_credentials @@ -257,6 +258,10 @@ def _write_config(writer: PythonWriter, config: ConfigPlan) -> None: _builtin_field(definition, field) for definition, field in builtin_fields(service) ), + *( + (field.name, (field.type, " | None"), field.documentation, field.spec) + for field in checksum_fields(config.plan) + ), ] overrides = f"_{mode.config}Overrides" writer.line("class ", overrides, "(", overrides_base, ", total=False):") diff --git a/packages/smithy-python/src/smithy_python/schemas.py b/packages/smithy-python/src/smithy_python/schemas.py index 4646d7bc7..cbf2826d3 100644 --- a/packages/smithy-python/src/smithy_python/schemas.py +++ b/packages/smithy-python/src/smithy_python/schemas.py @@ -352,6 +352,8 @@ def _shape_id(value: str) -> _model.ShapeId: # awsJson1_0 and rpcv2 read these at runtime for query compatibility. "aws.protocols#awsQueryCompatible", "aws.protocols#awsQueryError", + # The flexible checksums interceptor reads this from operations. + "aws.protocols#httpChecksum", # restXml reads this to take an output from its root element's text. "aws.customizations#s3UnwrappedXmlOutput", # The waiter runtime reads an operation's waiters from its schema. diff --git a/packages/smithy-python/tests/unit/test_client_generation.py b/packages/smithy-python/tests/unit/test_client_generation.py index 2954e1d75..435b98b30 100644 --- a/packages/smithy-python/tests/unit/test_client_generation.py +++ b/packages/smithy-python/tests/unit/test_client_generation.py @@ -1495,6 +1495,35 @@ def test_rest_xml_services_use_the_aws_core_protocol(tmp_path: Path) -> None: ) +def test_aws_clients_get_checksums_only_for_checksum_operations( + tmp_path: Path, +) -> None: + shapes = _shapes() + shapes["example#Greeter"]["traits"]["aws.api#service"] = {"sdkId": "Greeter"} + _aws_generate(tmp_path / "plain", "greeter_no_checksums", shapes) + source = tmp_path / "plain/src/greeter_no_checksums" + assert not (source / "checksums.py").exists() + assert "checksum_calculation" not in (source / "config.py").read_text() + + shapes["example#Greet"]["traits"] = { + "aws.protocols#httpChecksum": {"requestChecksumRequired": True} + } + _aws_generate(tmp_path / "checked", "greeter_checksums", shapes) + source = tmp_path / "checked/src/greeter_checksums" + assert "FlexibleChecksumsInterceptor()" in (source / "checksums.py").read_text() + assert ( + "AsyncFlexibleChecksumsInterceptor()" + in (source / "aio/checksums.py").read_text() + ) + config = (source / "config.py").read_text() + assert "request_checksum_calculation" in config + assert "response_checksum_validation" not in config + assert ( + '"smithy-aws-core[checksums]~=' + in (tmp_path / "checked/pyproject.toml").read_text() + ) + + def test_integrations_apply_only_to_services_they_match(tmp_path: Path) -> None: _aws_generate(tmp_path, "greeter_plain", _shapes()) assert "class Config:" in (tmp_path / "src/greeter_plain/config.py").read_text() diff --git a/scripts/api-snapshot/api-rex.json b/scripts/api-snapshot/api-rex.json index e4e900422..a46411851 100644 --- a/scripts/api-snapshot/api-rex.json +++ b/scripts/api-snapshot/api-rex.json @@ -1389,6 +1389,7 @@ "AWS_JSON_10": "rex-ProtocolContribution", "AWS_JSON_11": "rex-ProtocolContribution", "AWS_QUERY": "rex-ProtocolContribution", + "AwsChecksumsIntegration": "rex-class", "AwsConfigIntegration": "rex-class", "AwsEndpointsIntegration": "rex-class", "AwsIdentityIntegration": "rex-class", diff --git a/scripts/codegen-output-py/models/features.json b/scripts/codegen-output-py/models/features.json index cfd617a7d..7510dab7f 100644 --- a/scripts/codegen-output-py/models/features.json +++ b/scripts/codegen-output-py/models/features.json @@ -1,6 +1,34 @@ { "smithy": "2.0", "shapes": { + "example.features#ChecksumAlgorithm": { + "type": "enum", + "members": { + "CRC32": { + "target": "smithy.api#Unit", + "traits": { + "smithy.api#enumValue": "CRC32" + } + }, + "SHA256": { + "target": "smithy.api#Unit", + "traits": { + "smithy.api#enumValue": "SHA256" + } + } + } + }, + "example.features#ChecksumMode": { + "type": "enum", + "members": { + "ENABLED": { + "target": "smithy.api#Unit", + "traits": { + "smithy.api#enumValue": "ENABLED" + } + } + } + }, "example.features#DescribeNote": { "type": "operation", "input": { @@ -813,7 +841,13 @@ "smithy.api#auth": [ "smithy.api#httpBearerAuth" ], - "smithy.api#documentation": "Reads a note, with a bearer token." + "smithy.api#documentation": "Reads a note, with a bearer token.", + "aws.protocols#httpChecksum": { + "requestValidationModeMember": "checksumMode", + "responseAlgorithms": [ + "CRC32" + ] + } } }, "example.features#GetNoteInput": { @@ -821,6 +855,9 @@ "members": { "id": { "target": "smithy.api#String" + }, + "checksumMode": { + "target": "example.features#ChecksumMode" } }, "traits": { @@ -1000,7 +1037,11 @@ "target": "example.features#PutNoteOutput" }, "traits": { - "smithy.api#documentation": "

Saves a note, signed with SigV4.

Notes are stored in arn:aws:notes::.

" + "smithy.api#documentation": "

Saves a note, signed with SigV4.

Notes are stored in arn:aws:notes::.

", + "aws.protocols#httpChecksum": { + "requestChecksumRequired": true, + "requestAlgorithmMember": "checksumAlgorithm" + } } }, "example.features#PutNoteInput": { @@ -1008,6 +1049,9 @@ "members": { "text": { "target": "smithy.api#String" + }, + "checksumAlgorithm": { + "target": "example.features#ChecksumAlgorithm" } }, "traits": { diff --git a/scripts/codegen-output-py/models/features.smithy b/scripts/codegen-output-py/models/features.smithy index 8c24b5d3f..ffa0d0ada 100644 --- a/scripts/codegen-output-py/models/features.smithy +++ b/scripts/codegen-output-py/models/features.smithy @@ -4,6 +4,7 @@ namespace example.features use aws.api#service use aws.auth#sigv4 +use aws.protocols#httpChecksum use smithy.protocols#rpcv2Cbor use smithy.rules#clientContextParams use smithy.rules#contextParam @@ -282,9 +283,11 @@ operation Echo {} /// Reads a note, with a bearer token. @auth([httpBearerAuth]) +@httpChecksum(requestValidationModeMember: "checksumMode", responseAlgorithms: ["CRC32"]) operation GetNote { input := { id: String + checksumMode: ChecksumMode } output := { text: String @@ -327,9 +330,11 @@ list NoteList { operation Ping {} @documentation("

Saves a note, signed with SigV4.

Notes are stored in arn:aws:notes::.

") +@httpChecksum(requestChecksumRequired: true, requestAlgorithmMember: "checksumAlgorithm") operation PutNote { input := { text: String + checksumAlgorithm: ChecksumAlgorithm } output := { id: String @@ -359,3 +364,12 @@ structure ThingTag { list PluginNames { member: String } + +enum ChecksumAlgorithm { + CRC32 + SHA256 +} + +enum ChecksumMode { + ENABLED +} diff --git a/scripts/codegen-output-py/tests/test_client_snapshots.py b/scripts/codegen-output-py/tests/test_client_snapshots.py index d2ba7ac90..5925bf3b3 100644 --- a/scripts/codegen-output-py/tests/test_client_snapshots.py +++ b/scripts/codegen-output-py/tests/test_client_snapshots.py @@ -304,6 +304,25 @@ def use_transport(config: Any) -> None: assert request.destination.host == "profile.example.com" +@pytest.mark.parametrize("aio", [False, True]) +def test_snapshot_clients_send_modeled_request_checksums( + features: ModuleType, aio: bool, aws_env: pytest.MonkeyPatch +) -> None: + client, transport = _client( + features, + aio, + endpoint_uri=_ENDPOINT, + aws_access_key_id="AKIDEXAMPLE", + aws_secret_access_key="secret", + ) + _call(aio, client.put_note(text="hi", checksum_algorithm="SHA256")) + (request,) = transport.requests + assert request.fields["x-amz-checksum-sha256"].as_string() + # Both settings default to when_supported. + assert client._config.request_checksum_calculation == "when_supported" + assert client._config.response_checksum_validation == "when_supported" + + @pytest.mark.parametrize("aio", [False, True]) def test_sigv4_signs_with_configured_credentials( features: ModuleType, aio: bool, aws_env: pytest.MonkeyPatch diff --git a/scripts/verifications/import-cost.json b/scripts/verifications/import-cost.json index 0b9e6cf57..10536bb8d 100644 --- a/scripts/verifications/import-cost.json +++ b/scripts/verifications/import-cost.json @@ -16,7 +16,7 @@ "smithy_json": 21, "smithy_json (all public modules)": 21, "smithy_python": 1, - "smithy_python (all public modules)": 37, + "smithy_python (all public modules)": 38, "smithy_test": 50, "smithy_test (all public modules)": 70, "smithy_xml": 20,