Skip to content

Commit 4e4b38b

Browse files
committed
Porting botocore aws#3500
1 parent e86184a commit 4e4b38b

9 files changed

Lines changed: 445 additions & 24 deletions

awscli/botocore/handlers.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,12 +1187,6 @@ def _update_status_code(response, **kwargs):
11871187
http_response.status_code = parsed_status_code
11881188

11891189

1190-
def add_query_compatibility_header(model, params, **kwargs):
1191-
if not model.service_model.is_query_compatible:
1192-
return
1193-
params['headers']['x-amzn-query-mode'] = 'true'
1194-
1195-
11961190
def _handle_request_validation_mode_member(params, model, **kwargs):
11971191
client_config = kwargs.get("context", {}).get("client_config")
11981192
if client_config is None:
@@ -1285,7 +1279,6 @@ def _set_extra_headers_for_unsigned_request(
12851279
('docs.response-example.s3.*.complete-section', document_expires_shape),
12861280
('docs.response-params.s3.*.complete-section', document_expires_shape),
12871281
('before-endpoint-resolution.s3', customize_endpoint_resolver_builtins),
1288-
('before-call', add_query_compatibility_header),
12891282
('before-call.s3', add_expect_header),
12901283
('before-call.glacier', add_glacier_version),
12911284
('before-call.api-gateway', add_accept_header),

awscli/botocore/serialize.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ def _handle_float(self, value):
205205
value = "NaN"
206206
return value
207207

208+
def _handle_query_compatible_trait(self, operation_model, serialized):
209+
if operation_model.service_model.is_query_compatible:
210+
serialized['headers']['x-amzn-query-mode'] = 'true'
211+
208212

209213
class QuerySerializer(Serializer):
210214
TIMESTAMP_FORMAT = 'iso8601'
@@ -364,6 +368,8 @@ def serialize_to_request(self, parameters, operation_model):
364368
'X-Amz-Target': target,
365369
'Content-Type': f'application/x-amz-json-{json_version}',
366370
}
371+
self._handle_query_compatible_trait(operation_model, serialized)
372+
367373
body = self.MAP_TYPE()
368374
input_shape = operation_model.input_shape
369375
if input_shape is not None:
@@ -1179,6 +1185,7 @@ def _serialize_headers(self, serialized, operation_model):
11791185
header_val = 'application/vnd.amazon.eventstream'
11801186
else:
11811187
header_val = 'application/cbor'
1188+
self._handle_query_compatible_trait(operation_model, serialized)
11821189

11831190
has_body = serialized['body'] != b''
11841191
has_content_type = has_header('Content-Type', serialized['headers'])
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"description": "Test cases for QueryCompatibleOperation operation",
4+
"metadata": {
5+
"apiVersion": "2020-07-14",
6+
"auth": [
7+
"aws.auth#sigv4"
8+
],
9+
"awsQueryCompatible": {},
10+
"endpointPrefix": "querycompatiblejsonrpc10",
11+
"jsonVersion": "1.0",
12+
"protocol": "json",
13+
"protocols": [
14+
"json"
15+
],
16+
"serviceFullName": "QueryCompatibleJsonRpc10",
17+
"serviceId": "Query Compatible JSON RPC 10",
18+
"signatureVersion": "v4",
19+
"signingName": "QueryCompatibleJsonRpc10",
20+
"targetPrefix": "QueryCompatibleJsonRpc10",
21+
"uid": "query-compatible-json-rpc-10-2020-07-14"
22+
},
23+
"shapes": {},
24+
"cases": [
25+
{
26+
"id": "QueryCompatibleAwsJson10CborSendsQueryModeHeader",
27+
"given": {
28+
"name": "QueryCompatibleOperation",
29+
"http": {
30+
"method": "POST",
31+
"requestUri": "/"
32+
},
33+
"idempotent": true
34+
},
35+
"description": "Clients for query-compatible services MUST send the x-amzn-query-mode header.",
36+
"params": {},
37+
"serialized": {
38+
"method": "POST",
39+
"uri": "/",
40+
"body": "{}",
41+
"headers": {
42+
"Content-Type": "application/x-amz-json-1.0",
43+
"X-Amz-Target": "QueryCompatibleJsonRpc10.QueryCompatibleOperation",
44+
"x-amzn-query-mode": "true"
45+
}
46+
}
47+
}
48+
]
49+
}
50+
]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"description": "Test cases for NonQueryCompatibleOperation operation",
4+
"metadata": {
5+
"apiVersion": "2025-06-20",
6+
"auth": [
7+
"aws.auth#sigv4"
8+
],
9+
"endpointPrefix": "nonquerycompatiblerpcv2protocol",
10+
"protocol": "smithy-rpc-v2-cbor",
11+
"protocols": [
12+
"smithy-rpc-v2-cbor"
13+
],
14+
"serviceFullName": "NonQueryCompatibleRpcV2Protocol",
15+
"serviceId": "Non Query Compatible RpcV2 Protocol",
16+
"signatureVersion": "v4",
17+
"signingName": "NonQueryCompatibleRpcV2Protocol",
18+
"targetPrefix": "NonQueryCompatibleRpcV2Protocol",
19+
"uid": "non-query-compatible-rpcv2-protocol-2025-06-20"
20+
},
21+
"shapes": {},
22+
"cases": [
23+
{
24+
"id": "NonQueryCompatibleRpcV2CborForbidsQueryModeHeader",
25+
"given": {
26+
"name": "NonQueryCompatibleOperation",
27+
"http": {
28+
"method": "POST",
29+
"requestUri": "/"
30+
},
31+
"idempotent": true
32+
},
33+
"description": "The query mode header MUST NOT be set on non-query-compatible services.",
34+
"params": {},
35+
"serialized": {
36+
"method": "POST",
37+
"uri": "/service/NonQueryCompatibleRpcV2Protocol/operation/NonQueryCompatibleOperation",
38+
"body": "",
39+
"headers": {
40+
"Accept": "application/cbor",
41+
"smithy-protocol": "rpc-v2-cbor"
42+
},
43+
"forbidHeaders": [
44+
"x-amzn-query-mode"
45+
]
46+
}
47+
}
48+
]
49+
}
50+
]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[
2+
{
3+
"description": "Test cases for QueryCompatibleOperation operation",
4+
"metadata": {
5+
"apiVersion": "2025-06-20",
6+
"auth": [
7+
"aws.auth#sigv4"
8+
],
9+
"awsQueryCompatible": {},
10+
"endpointPrefix": "querycompatiblerpcv2protocol",
11+
"protocol": "smithy-rpc-v2-cbor",
12+
"protocols": [
13+
"smithy-rpc-v2-cbor"
14+
],
15+
"serviceFullName": "QueryCompatibleRpcV2Protocol",
16+
"serviceId": "Query Compatible RpcV2 Protocol",
17+
"signatureVersion": "v4",
18+
"signingName": "QueryCompatibleRpcV2Protocol",
19+
"targetPrefix": "QueryCompatibleRpcV2Protocol",
20+
"uid": "query-compatible-rpcv2-protocol-2025-06-20"
21+
},
22+
"shapes": {},
23+
"cases": [
24+
{
25+
"id": "QueryCompatibleRpcV2CborSendsQueryModeHeader",
26+
"given": {
27+
"name": "QueryCompatibleOperation",
28+
"http": {
29+
"method": "POST",
30+
"requestUri": "/"
31+
},
32+
"idempotent": true
33+
},
34+
"description": "Clients for query-compatible services MUST send the x-amzn-query-mode header.",
35+
"params": {},
36+
"serialized": {
37+
"method": "POST",
38+
"uri": "/service/QueryCompatibleRpcV2Protocol/operation/QueryCompatibleOperation",
39+
"body": "",
40+
"headers": {
41+
"Accept": "application/cbor",
42+
"smithy-protocol": "rpc-v2-cbor",
43+
"x-amzn-query-mode": "true"
44+
},
45+
"forbidHeaders": [
46+
"Content-Type",
47+
"X-Amz-Target"
48+
]
49+
}
50+
}
51+
]
52+
}
53+
]
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
[
2+
{
3+
"description": "Test cases for QueryCompatibleOperation operation",
4+
"metadata": {
5+
"apiVersion": "2020-07-14",
6+
"auth": [
7+
"aws.auth#sigv4"
8+
],
9+
"awsQueryCompatible": {},
10+
"endpointPrefix": "querycompatiblejsonrpc10",
11+
"jsonVersion": "1.0",
12+
"protocol": "json",
13+
"protocols": [
14+
"json"
15+
],
16+
"serviceFullName": "QueryCompatibleJsonRpc10",
17+
"serviceId": "Query Compatible JSON RPC 10",
18+
"signatureVersion": "v4",
19+
"signingName": "QueryCompatibleJsonRpc10",
20+
"targetPrefix": "QueryCompatibleJsonRpc10",
21+
"uid": "query-compatible-json-rpc-10-2020-07-14"
22+
},
23+
"shapes": {
24+
"NoCustomCodeError": {
25+
"type": "structure",
26+
"members": {
27+
"message": {
28+
"shape": "String"
29+
}
30+
},
31+
"exception": true
32+
},
33+
"String": {
34+
"type": "string"
35+
}
36+
},
37+
"cases": [
38+
{
39+
"id": "QueryCompatibleAwsJson10NoCustomCodeError",
40+
"given": {
41+
"name": "QueryCompatibleOperation",
42+
"http": {
43+
"method": "POST",
44+
"requestUri": "/"
45+
},
46+
"idempotent": true,
47+
"errors": [
48+
{
49+
"shape": "NoCustomCodeError"
50+
}
51+
]
52+
},
53+
"description": "Parses simple errors with no query error code",
54+
"errorCode": "NoCustomCodeError",
55+
"errorMessage": "Hi",
56+
"error": {
57+
"message": "Hi"
58+
},
59+
"response": {
60+
"status_code": 400,
61+
"headers": {
62+
"Content-Type": "application/x-amz-json-1.0"
63+
},
64+
"body": "{\n \"__type\": \"aws.protocoltests.json10#NoCustomCodeError\",\n \"message\": \"Hi\"\n}"
65+
}
66+
}
67+
]
68+
},
69+
{
70+
"description": "Test cases for QueryCompatibleOperation operation",
71+
"metadata": {
72+
"apiVersion": "2020-07-14",
73+
"auth": [
74+
"aws.auth#sigv4"
75+
],
76+
"awsQueryCompatible": {},
77+
"endpointPrefix": "querycompatiblejsonrpc10",
78+
"jsonVersion": "1.0",
79+
"protocol": "json",
80+
"protocols": [
81+
"json"
82+
],
83+
"serviceFullName": "QueryCompatibleJsonRpc10",
84+
"serviceId": "Query Compatible JSON RPC 10",
85+
"signatureVersion": "v4",
86+
"signingName": "QueryCompatibleJsonRpc10",
87+
"targetPrefix": "QueryCompatibleJsonRpc10",
88+
"uid": "query-compatible-json-rpc-10-2020-07-14"
89+
},
90+
"shapes": {
91+
"CustomCodeError": {
92+
"type": "structure",
93+
"members": {
94+
"message": {
95+
"shape": "String"
96+
}
97+
},
98+
"error": {
99+
"code": "Customized",
100+
"httpStatusCode": 402,
101+
"senderFault": true
102+
},
103+
"exception": true
104+
},
105+
"String": {
106+
"type": "string"
107+
}
108+
},
109+
"cases": [
110+
{
111+
"id": "QueryCompatibleAwsJson10CustomCodeError",
112+
"given": {
113+
"name": "QueryCompatibleOperation",
114+
"http": {
115+
"method": "POST",
116+
"requestUri": "/"
117+
},
118+
"idempotent": true,
119+
"errors": [
120+
{
121+
"shape": "CustomCodeError"
122+
}
123+
]
124+
},
125+
"description": "Parses simple errors with query error code",
126+
"errorCode": "Customized",
127+
"errorMessage": "Hi",
128+
"error": {
129+
"message": "Hi"
130+
},
131+
"response": {
132+
"status_code": 400,
133+
"headers": {
134+
"Content-Type": "application/x-amz-json-1.0",
135+
"x-amzn-query-error": "Customized;Sender"
136+
},
137+
"body": "{\n \"__type\": \"aws.protocoltests.json10#CustomCodeError\",\n \"message\": \"Hi\"\n}"
138+
}
139+
}
140+
]
141+
}
142+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)