Skip to content

Commit 7fd998d

Browse files
authored
Improve awsQueryCompatible support for JSON and CBOR (#3128)
1 parent d555e5a commit 7fd998d

30 files changed

+4253
-320
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Feature - Support functionality for services that migrate from AWS Query to AWS JSON or CBOR.
5+
46
* Issue - Fix RPCv2 protocol to always send an Accept header for CBOR.
57

68
3.210.0 (2024-10-18)

gems/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,14 @@ def data_to_http_resp(operation_name, data)
307307

308308
def protocol_helper
309309
case config.api.metadata['protocol']
310-
when 'json' then Stubbing::Protocols::Json
311-
when 'rest-json' then Stubbing::Protocols::RestJson
312-
when 'rest-xml' then Stubbing::Protocols::RestXml
313-
when 'query' then Stubbing::Protocols::Query
314-
when 'ec2' then Stubbing::Protocols::EC2
310+
when 'json' then Stubbing::Protocols::Json
311+
when 'rest-json' then Stubbing::Protocols::RestJson
312+
when 'rest-xml' then Stubbing::Protocols::RestXml
313+
when 'query' then Stubbing::Protocols::Query
314+
when 'ec2' then Stubbing::Protocols::EC2
315315
when 'smithy-rpc-v2-cbor' then Stubbing::Protocols::RpcV2
316-
when 'api-gateway' then Stubbing::Protocols::ApiGateway
317-
else raise "unsupported protocol"
316+
when 'api-gateway' then Stubbing::Protocols::ApiGateway
317+
else raise 'unsupported protocol'
318318
end.new
319319
end
320320
end

gems/aws-sdk-core/lib/aws-sdk-core/json/error_handler.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def extract_error(body, context)
2626
def error_code(json, context)
2727
code =
2828
if aws_query_error?(context)
29-
error = context.http_response.headers['x-amzn-query-error'].split(';')[0]
29+
query_header = context.http_response.headers['x-amzn-query-error']
30+
error, _type = query_header.split(';') # type not supported
3031
remove_prefix(error, context)
3132
else
3233
json['__type']

gems/aws-sdk-core/lib/aws-sdk-core/json/handler.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def build_request(context)
2121
context.http_request.http_method = 'POST'
2222
context.http_request.headers['Content-Type'] = content_type(context)
2323
context.http_request.headers['X-Amz-Target'] = target(context)
24+
context.http_request.headers['X-Amzn-Query-Mode'] = 'true' if query_compatible?(context)
2425
context.http_request.body = build_body(context)
2526
end
2627

gems/aws-sdk-core/lib/aws-sdk-core/rpc_v2/error_handler.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def extract_error(body, context)
3939
def error_code(data, context)
4040
code =
4141
if aws_query_error?(context)
42-
error = context.http_response.headers['x-amzn-query-error'].split(';')[0]
42+
query_header = context.http_response.headers['x-amzn-query-error']
43+
error, _type = query_header.split(';') # type not supported
4344
remove_prefix(error, context)
4445
else
4546
data['__type']

gems/aws-sdk-core/lib/aws-sdk-core/rpc_v2/handler.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def with_metric(&block)
2020
end
2121

2222
def build_request(context)
23-
context.http_request.headers['smithy-protocol'] = 'rpc-v2-cbor'
23+
context.http_request.headers['Smithy-Protocol'] = 'rpc-v2-cbor'
24+
context.http_request.headers['X-Amzn-Query-Mode'] = 'true' if query_compatible?(context)
2425
context.http_request.http_method = 'POST'
2526
context.http_request.body = build_body(context)
2627
build_url(context)

gems/aws-sdk-core/lib/aws-sdk-core/stubbing.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module Aws
4-
# setup autoloading for Stubbing module
4+
# @api private
55
module Stubbing
66
autoload :EmptyStub, 'aws-sdk-core/stubbing/empty_stub'
77
autoload :DataApplicator, 'aws-sdk-core/stubbing/data_applicator'
@@ -19,4 +19,4 @@ module Protocols
1919
autoload :ApiGateway, 'aws-sdk-core/stubbing/protocols/api_gateway'
2020
end
2121
end
22-
end
22+
end

gems/aws-sdk-core/lib/aws-sdk-core/stubbing/protocols/ec2.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Aws
44
module Stubbing
55
module Protocols
6+
# @api private
67
class EC2
78

89
def stub_data(api, operation, data)
@@ -16,17 +17,17 @@ def stub_data(api, operation, data)
1617
end
1718

1819
def stub_error(error_code)
19-
http_resp = Seahorse::Client::Http::Response.new
20-
http_resp.status_code = 400
21-
http_resp.body = <<-XML.strip
22-
<ErrorResponse>
23-
<Error>
24-
<Code>#{error_code}</Code>
25-
<Message>stubbed-response-error-message</Message>
26-
</Error>
27-
</ErrorResponse>
20+
resp = Seahorse::Client::Http::Response.new
21+
resp.status_code = 400
22+
resp.body = <<~XML.strip
23+
<ErrorResponse>
24+
<Error>
25+
<Code>#{error_code}</Code>
26+
<Message>stubbed-response-error-message</Message>
27+
</Error>
28+
</ErrorResponse>
2829
XML
29-
http_resp
30+
resp
3031
end
3132

3233
private
@@ -37,7 +38,7 @@ def build_body(api, operation, data)
3738
xml.shift
3839
xml.pop
3940
xmlns = "http://ec2.amazonaws.com/doc/#{api.version}/".inspect
40-
xml.unshift(" <requestId>stubbed-request-id</requestId>")
41+
xml.unshift(' <requestId>stubbed-request-id</requestId>')
4142
xml.unshift("<#{operation.name}Response xmlns=#{xmlns}>\n")
4243
xml.push("</#{operation.name}Response>\n")
4344
xml.join

gems/aws-sdk-core/lib/aws-sdk-core/stubbing/protocols/json.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
module Aws
44
module Stubbing
55
module Protocols
6+
# @api private
67
class Json
78

89
def stub_data(api, operation, data)
910
resp = Seahorse::Client::Http::Response.new
1011
resp.status_code = 200
11-
resp.headers["Content-Type"] = content_type(api)
12-
resp.headers["x-amzn-RequestId"] = "stubbed-request-id"
12+
resp.headers['Content-Type'] = content_type(api)
13+
resp.headers['x-amzn-RequestId'] = 'stubbed-request-id'
1314
resp.body = build_body(operation, data)
1415
resp
1516
end
1617

1718
def stub_error(error_code)
18-
http_resp = Seahorse::Client::Http::Response.new
19-
http_resp.status_code = 400
20-
http_resp.body = <<-JSON.strip
21-
{
22-
"code": #{error_code.inspect},
23-
"message": "stubbed-response-error-message"
24-
}
19+
resp = Seahorse::Client::Http::Response.new
20+
resp.status_code = 400
21+
resp.body = <<~JSON.strip
22+
{
23+
"code": #{error_code.inspect},
24+
"message": "stubbed-response-error-message"
25+
}
2526
JSON
26-
http_resp
27+
resp
2728
end
2829

2930
private

gems/aws-sdk-core/lib/aws-sdk-core/stubbing/protocols/query.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Aws
44
module Stubbing
55
module Protocols
6+
# @api private
67
class Query
78

89
def stub_data(api, operation, data)
@@ -13,20 +14,20 @@ def stub_data(api, operation, data)
1314
end
1415

1516
def stub_error(error_code)
16-
http_resp = Seahorse::Client::Http::Response.new
17-
http_resp.status_code = 400
18-
http_resp.body = XmlError.new(error_code).to_xml
19-
http_resp
17+
resp = Seahorse::Client::Http::Response.new
18+
resp.status_code = 400
19+
resp.body = XmlError.new(error_code).to_xml
20+
resp
2021
end
2122

2223
private
2324

2425
def build_body(api, operation, data)
2526
xml = []
2627
builder = Aws::Xml::DocBuilder.new(target: xml, indent: ' ')
27-
builder.node(operation.name + 'Response', xmlns: xmlns(api)) do
28+
builder.node("#{operation.name}Response", xmlns: xmlns(api)) do
2829
if (rules = operation.output)
29-
rules.location_name = operation.name + 'Result'
30+
rules.location_name = "#{operation.name}Result"
3031
Xml::Builder.new(rules, target: xml, pad:' ').to_xml(data)
3132
end
3233
builder.node('ResponseMetadata') do

0 commit comments

Comments
 (0)