aws-sdk-core 3.191.0 → 3.199.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +153 -1
- data/VERSION +1 -1
- data/lib/aws-sdk-core/binary/decode_handler.rb +3 -9
- data/lib/aws-sdk-core/binary/encode_handler.rb +1 -1
- data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
- data/lib/aws-sdk-core/binary/event_stream_decoder.rb +1 -0
- data/lib/aws-sdk-core/binary/event_stream_encoder.rb +4 -3
- data/lib/aws-sdk-core/cbor/cbor_engine.rb +19 -0
- data/lib/aws-sdk-core/cbor/decoder.rb +310 -0
- data/lib/aws-sdk-core/cbor/encoder.rb +243 -0
- data/lib/aws-sdk-core/cbor.rb +106 -0
- data/lib/aws-sdk-core/client_stubs.rb +3 -2
- data/lib/aws-sdk-core/credential_provider.rb +1 -1
- data/lib/aws-sdk-core/ec2_metadata.rb +1 -1
- data/lib/aws-sdk-core/ecs_credentials.rb +2 -1
- data/lib/aws-sdk-core/endpoints/matchers.rb +5 -1
- data/lib/aws-sdk-core/error_handler.rb +41 -0
- data/lib/aws-sdk-core/event_emitter.rb +0 -16
- data/lib/aws-sdk-core/instance_profile_credentials.rb +3 -2
- data/lib/aws-sdk-core/json/builder.rb +8 -1
- data/lib/aws-sdk-core/json/error_handler.rb +15 -10
- data/lib/aws-sdk-core/json/handler.rb +5 -6
- data/lib/aws-sdk-core/json/json_engine.rb +3 -1
- data/lib/aws-sdk-core/json/oj_engine.rb +7 -1
- data/lib/aws-sdk-core/json/parser.rb +6 -1
- data/lib/aws-sdk-core/json.rb +43 -14
- data/lib/aws-sdk-core/lru_cache.rb +75 -0
- data/lib/aws-sdk-core/pageable_response.rb +1 -1
- data/lib/aws-sdk-core/param_validator.rb +7 -2
- data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
- data/lib/aws-sdk-core/plugins/global_configuration.rb +8 -9
- data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
- data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +3 -1
- data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -24
- data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +6 -8
- data/lib/aws-sdk-core/plugins/protocols/query.rb +4 -2
- data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +3 -15
- data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +3 -0
- data/lib/aws-sdk-core/plugins/protocols/rpc_v2.rb +17 -0
- data/lib/aws-sdk-core/plugins/request_compression.rb +11 -2
- data/lib/aws-sdk-core/plugins/retry_errors.rb +10 -3
- data/lib/aws-sdk-core/plugins/sign.rb +8 -3
- data/lib/aws-sdk-core/plugins/user_agent.rb +61 -26
- data/lib/aws-sdk-core/process_credentials.rb +45 -27
- data/lib/aws-sdk-core/query/ec2_handler.rb +27 -0
- data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
- data/lib/aws-sdk-core/query/handler.rb +4 -4
- data/lib/aws-sdk-core/query/param_builder.rb +2 -2
- data/lib/aws-sdk-core/query.rb +2 -1
- data/lib/aws-sdk-core/rest/content_type_handler.rb +60 -0
- data/lib/aws-sdk-core/rest/handler.rb +3 -4
- data/lib/aws-sdk-core/rest/request/body.rb +32 -5
- data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
- data/lib/aws-sdk-core/rest/request/headers.rb +15 -7
- data/lib/aws-sdk-core/rest/request/querystring_builder.rb +23 -11
- data/lib/aws-sdk-core/rest/response/body.rb +15 -1
- data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
- data/lib/aws-sdk-core/rest/response/headers.rb +8 -3
- data/lib/aws-sdk-core/rest.rb +1 -0
- data/lib/aws-sdk-core/rpc_v2/builder.rb +62 -0
- data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +45 -0
- data/lib/aws-sdk-core/rpc_v2/error_handler.rb +84 -0
- data/lib/aws-sdk-core/rpc_v2/handler.rb +74 -0
- data/lib/aws-sdk-core/rpc_v2/parser.rb +90 -0
- data/lib/aws-sdk-core/rpc_v2.rb +6 -0
- data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +41 -0
- data/lib/aws-sdk-core/util.rb +39 -0
- data/lib/aws-sdk-core/waiters/poller.rb +1 -1
- data/lib/aws-sdk-core/xml/builder.rb +17 -9
- data/lib/aws-sdk-core/xml/error_handler.rb +32 -42
- data/lib/aws-sdk-core/xml/parser/frame.rb +4 -20
- data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
- data/lib/aws-sdk-core/xml/parser.rb +2 -6
- data/lib/aws-sdk-core.rb +7 -2
- data/lib/aws-sdk-sso/client.rb +77 -49
- data/lib/aws-sdk-sso.rb +1 -1
- data/lib/aws-sdk-ssooidc/client.rb +127 -51
- data/lib/aws-sdk-ssooidc/client_api.rb +22 -0
- data/lib/aws-sdk-ssooidc/errors.rb +21 -0
- data/lib/aws-sdk-ssooidc/types.rb +77 -9
- data/lib/aws-sdk-ssooidc.rb +1 -1
- data/lib/aws-sdk-sts/client.rb +77 -49
- data/lib/aws-sdk-sts/client_api.rb +8 -8
- data/lib/aws-sdk-sts.rb +1 -1
- data/lib/seahorse/client/async_base.rb +1 -1
- data/lib/seahorse/client/async_response.rb +19 -0
- data/lib/seahorse/client/base.rb +18 -7
- data/lib/seahorse/client/h2/handler.rb +1 -0
- data/lib/seahorse/client/handler.rb +1 -1
- data/lib/seahorse/client/net_http/connection_pool.rb +3 -9
- data/lib/seahorse/client/plugin.rb +8 -0
- data/lib/seahorse/client/plugins/endpoint.rb +0 -1
- data/lib/seahorse/client/plugins/net_http.rb +48 -16
- data/lib/seahorse/model/shapes.rb +2 -2
- metadata +24 -7
- /data/lib/aws-sdk-core/xml/parser/{engines/libxml.rb → libxml_engine.rb} +0 -0
- /data/lib/aws-sdk-core/xml/parser/{engines/nokogiri.rb → nokogiri_engine.rb} +0 -0
- /data/lib/aws-sdk-core/xml/parser/{engines/oga.rb → oga_engine.rb} +0 -0
- /data/lib/aws-sdk-core/xml/parser/{engines/ox.rb → ox_engine.rb} +0 -0
- /data/lib/aws-sdk-core/xml/parser/{engines/rexml.rb → rexml_engine.rb} +0 -0
|
@@ -20,7 +20,8 @@ module Aws
|
|
|
20
20
|
if event_stream?
|
|
21
21
|
data[@rules[:payload]] = parse_eventstream(body)
|
|
22
22
|
elsif streaming?
|
|
23
|
-
|
|
23
|
+
# empty blob payloads are omitted
|
|
24
|
+
data[@rules[:payload]] = body unless empty_blob_payload?(body)
|
|
24
25
|
elsif @rules[:payload]
|
|
25
26
|
data[@rules[:payload]] = parse(body.read, @rules[:payload_member])
|
|
26
27
|
elsif !@rules.shape.member_names.empty?
|
|
@@ -30,6 +31,19 @@ module Aws
|
|
|
30
31
|
|
|
31
32
|
private
|
|
32
33
|
|
|
34
|
+
def empty_blob_payload?(body)
|
|
35
|
+
true if non_streaming_blob_payload? && empty_body?(body)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def non_streaming_blob_payload?
|
|
39
|
+
@rules[:payload_member].shape.is_a?(BlobShape) &&
|
|
40
|
+
!@rules[:payload_member]['streaming']
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def empty_body?(body)
|
|
44
|
+
body.respond_to?(:size) && body.size.zero?
|
|
45
|
+
end
|
|
46
|
+
|
|
33
47
|
def event_stream?
|
|
34
48
|
@rules[:payload] && @rules[:payload_member].eventstream
|
|
35
49
|
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'strscan'
|
|
4
|
+
|
|
5
|
+
module Aws
|
|
6
|
+
module Rest
|
|
7
|
+
module Response
|
|
8
|
+
# @api private
|
|
9
|
+
module HeaderListParser
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
# parse a list of possibly quoted and escaped string values
|
|
13
|
+
# Follows:
|
|
14
|
+
# # [RFC-7230's specification of header values](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6).
|
|
15
|
+
def parse_string_list(value)
|
|
16
|
+
buffer = StringScanner.new(value)
|
|
17
|
+
parsed = []
|
|
18
|
+
|
|
19
|
+
parsed << read_value(buffer) until buffer.eos?
|
|
20
|
+
|
|
21
|
+
parsed
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def parse_timestamp_list(value, ref)
|
|
25
|
+
# timestamp lists use an http-date by default and are unescaped
|
|
26
|
+
# eg: Mon, 16 Dec 2019 23:48:18 GMT, Mon, 16 Dec 2019 23:48:18 GMT
|
|
27
|
+
case ref['timestampFormat'] || ref.shape['timestampFormat']
|
|
28
|
+
when 'unixTimestamp'
|
|
29
|
+
value.split(', ').map { |v| Time.at(v.to_f) }
|
|
30
|
+
when 'iso8601' then value.split(', ').map { |v| Time.parse(v) }
|
|
31
|
+
else
|
|
32
|
+
# header default to rfc822/http-date, which has a comma after day
|
|
33
|
+
value.split(',').each_slice(2).map { |v| Time.parse(v[0] + v[1])}
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def read_value(buffer)
|
|
40
|
+
until buffer.eos?
|
|
41
|
+
case buffer.peek(1)
|
|
42
|
+
when ' ', "\t"
|
|
43
|
+
# drop leading whitespace
|
|
44
|
+
buffer.getch
|
|
45
|
+
next
|
|
46
|
+
when '"'
|
|
47
|
+
buffer.getch # drop the quote and advance
|
|
48
|
+
return read_quoted_value(buffer)
|
|
49
|
+
else
|
|
50
|
+
return read_unquoted_value(buffer)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
# buffer is only whitespace
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def read_unquoted_value(buffer)
|
|
58
|
+
# there cannot be any escaped values
|
|
59
|
+
value = buffer.scan_until(/,|$/)
|
|
60
|
+
# drop the comma if we matched it
|
|
61
|
+
buffer.matched == ',' ? value.chop : value
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def read_quoted_value(buffer)
|
|
65
|
+
# scan until we have an unescaped double quote
|
|
66
|
+
value = buffer.scan_until(/[^\\]"/)
|
|
67
|
+
raise ArgumentError, 'Invalid String list: No closing quote found' unless value
|
|
68
|
+
|
|
69
|
+
# drop any remaining whitespace/commas
|
|
70
|
+
buffer.scan_until(/[\s,]*/)
|
|
71
|
+
# the last character will always be the closing quote.
|
|
72
|
+
# Add a starting quote and then unescape (undump)
|
|
73
|
+
"\"#{value}".undump
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'time'
|
|
4
4
|
require 'base64'
|
|
5
|
+
require_relative 'header_list_parser'
|
|
5
6
|
|
|
6
7
|
module Aws
|
|
7
8
|
module Rest
|
|
@@ -36,12 +37,16 @@ module Aws
|
|
|
36
37
|
def cast_value(ref, value)
|
|
37
38
|
value = extract_json_trait(value) if ref['jsonvalue']
|
|
38
39
|
case ref.shape
|
|
39
|
-
when StringShape then value
|
|
40
|
+
when StringShape then value.to_s
|
|
40
41
|
when IntegerShape then value.to_i
|
|
41
|
-
when FloatShape then value
|
|
42
|
+
when FloatShape then Util.deserialize_number(value)
|
|
42
43
|
when BooleanShape then value == 'true'
|
|
43
44
|
when ListShape then
|
|
44
|
-
|
|
45
|
+
case ref.shape.member.shape
|
|
46
|
+
when StringShape then HeaderListParser.parse_string_list(value)
|
|
47
|
+
when TimestampShape then HeaderListParser.parse_timestamp_list(value, ref.shape.member)
|
|
48
|
+
else value.split(', ').map { |v| cast_value(ref.shape.member, v) }
|
|
49
|
+
end
|
|
45
50
|
when TimestampShape
|
|
46
51
|
if value =~ /^\d+(\.\d*)/
|
|
47
52
|
Time.at(value.to_f)
|
data/lib/aws-sdk-core/rest.rb
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
|
|
5
|
+
module Aws
|
|
6
|
+
module RpcV2
|
|
7
|
+
class Builder
|
|
8
|
+
include Seahorse::Model::Shapes
|
|
9
|
+
|
|
10
|
+
def initialize(rules, _options = {})
|
|
11
|
+
@rules = rules
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def serialize(params)
|
|
15
|
+
# If the input shape is empty, do not set a body. This is
|
|
16
|
+
# different than if the input shape is a structure with no members.
|
|
17
|
+
return nil if @rules.shape.struct_class == EmptyStructure
|
|
18
|
+
|
|
19
|
+
Cbor.encode(format(@rules, params))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def structure(ref, values)
|
|
25
|
+
shape = ref.shape
|
|
26
|
+
values.each_pair.with_object({}) do |(key, value), data|
|
|
27
|
+
if shape.member?(key) && !value.nil?
|
|
28
|
+
member_ref = shape.member(key)
|
|
29
|
+
member_name = member_ref.location_name || key
|
|
30
|
+
data[member_name] = format(member_ref, value)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def list(ref, values)
|
|
36
|
+
member_ref = ref.shape.member
|
|
37
|
+
values.collect { |value| format(member_ref, value) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def map(ref, values)
|
|
41
|
+
value_ref = ref.shape.value
|
|
42
|
+
values.each.with_object({}) do |(key, value), data|
|
|
43
|
+
data[key] = format(value_ref, value)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def blob(value)
|
|
48
|
+
(String === value ? value : value.read).force_encoding(Encoding::BINARY)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def format(ref, value)
|
|
52
|
+
case ref.shape
|
|
53
|
+
when StructureShape then structure(ref, value)
|
|
54
|
+
when ListShape then list(ref, value)
|
|
55
|
+
when MapShape then map(ref, value)
|
|
56
|
+
when BlobShape then blob(value)
|
|
57
|
+
else value
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module RpcV2
|
|
5
|
+
class ContentTypeHandler < Seahorse::Client::Handler
|
|
6
|
+
def call(context)
|
|
7
|
+
content_type =
|
|
8
|
+
if eventstream_input?(context)
|
|
9
|
+
'application/vnd.amazon.eventstream'
|
|
10
|
+
elsif !empty_input_structure?(context)
|
|
11
|
+
'application/cbor'
|
|
12
|
+
end
|
|
13
|
+
accept =
|
|
14
|
+
if eventstream_output?(context)
|
|
15
|
+
'application/vnd.amazon.eventstream'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
headers = context.http_request.headers
|
|
19
|
+
headers['Content-Type'] ||= content_type if content_type
|
|
20
|
+
headers['Accept'] ||= accept if accept
|
|
21
|
+
@handler.call(context)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def eventstream_input?(context)
|
|
27
|
+
context.operation.input.shape.members.each do |_, ref|
|
|
28
|
+
return true if ref.eventstream
|
|
29
|
+
end
|
|
30
|
+
false
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def eventstream_output?(context)
|
|
34
|
+
context.operation.output.shape.members.each do |_, ref|
|
|
35
|
+
return true if ref.eventstream
|
|
36
|
+
end
|
|
37
|
+
false
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def empty_input_structure?(context)
|
|
41
|
+
context.operation.input.shape.struct_class == EmptyStructure
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module RpcV2
|
|
5
|
+
class ErrorHandler < Aws::ErrorHandler
|
|
6
|
+
|
|
7
|
+
def call(context)
|
|
8
|
+
# Malformed responses should throw an http based error, so we check
|
|
9
|
+
# 200 range for error handling only for this case.
|
|
10
|
+
@handler.call(context).on(200..599) do |response|
|
|
11
|
+
if !valid_response?(context)
|
|
12
|
+
code, message, data = http_status_error(context)
|
|
13
|
+
response.error = build_error(context, code, message, data)
|
|
14
|
+
elsif (300..599).cover?(context.http_response.status_code)
|
|
15
|
+
response.error = error(context)
|
|
16
|
+
end
|
|
17
|
+
response.data = nil
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def valid_response?(context)
|
|
24
|
+
req_header = context.http_request.headers['smithy-protocol']
|
|
25
|
+
resp_header = context.http_response.headers['smithy-protocol']
|
|
26
|
+
req_header == resp_header
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def extract_error(body, context)
|
|
30
|
+
data = Cbor.decode(body)
|
|
31
|
+
code = error_code(data, context)
|
|
32
|
+
message = data['message']
|
|
33
|
+
data = parse_error_data(context, body, code)
|
|
34
|
+
[code, message, data]
|
|
35
|
+
rescue Cbor::Error
|
|
36
|
+
[http_status_error_code(context), '', EmptyStructure.new]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def error_code(data, context)
|
|
40
|
+
code =
|
|
41
|
+
if aws_query_error?(context)
|
|
42
|
+
error = context.http_response.headers['x-amzn-query-error'].split(';')[0]
|
|
43
|
+
remove_prefix(error, context)
|
|
44
|
+
else
|
|
45
|
+
data['__type']
|
|
46
|
+
end
|
|
47
|
+
if code
|
|
48
|
+
code.split('#').last
|
|
49
|
+
else
|
|
50
|
+
http_status_error_code(context)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def parse_error_data(context, body, code)
|
|
55
|
+
data = EmptyStructure.new
|
|
56
|
+
if (error_rules = context.operation.errors)
|
|
57
|
+
error_rules.each do |rule|
|
|
58
|
+
# match modeled shape name with the type(code) only
|
|
59
|
+
# some type(code) might contains invalid characters
|
|
60
|
+
# such as ':' (efs) etc
|
|
61
|
+
match = rule.shape.name == code.gsub(/[^^a-zA-Z0-9]/, '')
|
|
62
|
+
next unless match && rule.shape.members.any?
|
|
63
|
+
|
|
64
|
+
data = Parser.new(rule).parse(body)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
data
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def aws_query_error?(context)
|
|
71
|
+
context.config.api.metadata['awsQueryCompatible'] &&
|
|
72
|
+
context.http_response.headers['x-amzn-query-error']
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def remove_prefix(error_code, context)
|
|
76
|
+
if (prefix = context.config.api.metadata['errorPrefix'])
|
|
77
|
+
error_code.sub(/^#{prefix}/, '')
|
|
78
|
+
else
|
|
79
|
+
error_code
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module RpcV2
|
|
5
|
+
class Handler < Seahorse::Client::Handler
|
|
6
|
+
# @param [Seahorse::Client::RequestContext] context
|
|
7
|
+
# @return [Seahorse::Client::Response]
|
|
8
|
+
def call(context)
|
|
9
|
+
build_request(context)
|
|
10
|
+
response = @handler.call(context)
|
|
11
|
+
response.on(200..299) { |resp| resp.data = parse_body(context) }
|
|
12
|
+
response.on(200..599) { |_resp| apply_request_id(context) }
|
|
13
|
+
response
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def build_request(context)
|
|
19
|
+
context.http_request.headers['smithy-protocol'] = 'rpc-v2-cbor'
|
|
20
|
+
context.http_request.http_method = 'POST'
|
|
21
|
+
context.http_request.body = build_body(context)
|
|
22
|
+
build_url(context)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def build_url(context)
|
|
26
|
+
base = context.http_request.endpoint
|
|
27
|
+
service_name = context.config.api.metadata['targetPrefix']
|
|
28
|
+
base.path += "/service/#{service_name}/operation/#{context.operation.name}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def build_body(context)
|
|
32
|
+
Builder.new(context.operation.input).serialize(context.params)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def parse_body(context)
|
|
36
|
+
cbor = context.http_response.body_contents
|
|
37
|
+
if (rules = context.operation.output)
|
|
38
|
+
if cbor.is_a?(Array)
|
|
39
|
+
# an array of emitted events
|
|
40
|
+
if cbor[0].respond_to?(:response)
|
|
41
|
+
# initial response exists
|
|
42
|
+
# it must be the first event arrived
|
|
43
|
+
resp_struct = cbor.shift.response
|
|
44
|
+
else
|
|
45
|
+
resp_struct = context.operation.output.shape.struct_class.new
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
rules.shape.members.each do |name, ref|
|
|
49
|
+
if ref.eventstream
|
|
50
|
+
resp_struct.send("#{name}=", cbor.to_enum)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
resp_struct
|
|
54
|
+
else
|
|
55
|
+
Parser.new(
|
|
56
|
+
rules,
|
|
57
|
+
query_compatible: query_compatible?(context)
|
|
58
|
+
).parse(cbor)
|
|
59
|
+
end
|
|
60
|
+
else
|
|
61
|
+
EmptyStructure.new
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def apply_request_id(context)
|
|
66
|
+
context[:request_id] = context.http_response.headers['x-amzn-requestid']
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def query_compatible?(context)
|
|
70
|
+
context.config.api.metadata.key?('awsQueryCompatible')
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module Aws
|
|
6
|
+
module RpcV2
|
|
7
|
+
class Parser
|
|
8
|
+
include Seahorse::Model::Shapes
|
|
9
|
+
|
|
10
|
+
# @param [Seahorse::Model::ShapeRef] rules
|
|
11
|
+
def initialize(rules, query_compatible: false)
|
|
12
|
+
@rules = rules
|
|
13
|
+
@query_compatible = query_compatible
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def parse(cbor, target = nil)
|
|
17
|
+
return {} if cbor.empty?
|
|
18
|
+
|
|
19
|
+
parse_ref(@rules, Cbor.decode(cbor), target)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def structure(ref, values, target = nil)
|
|
25
|
+
shape = ref.shape
|
|
26
|
+
target = ref.shape.struct_class.new if target.nil?
|
|
27
|
+
values.each do |key, value|
|
|
28
|
+
member_name, member_ref = shape.member_by_location_name(key)
|
|
29
|
+
if member_ref
|
|
30
|
+
target[member_name] = parse_ref(member_ref, value)
|
|
31
|
+
elsif shape.union && key != '__type'
|
|
32
|
+
target[:unknown] = { 'name' => key, 'value' => value }
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
# In services that were previously Query/XML, members that were
|
|
36
|
+
# "flattened" defaulted to empty lists. In JSON, these values are nil,
|
|
37
|
+
# which is backwards incompatible. To preserve backwards compatibility,
|
|
38
|
+
# we set a default value of [] for these members.
|
|
39
|
+
if @query_compatible
|
|
40
|
+
ref.shape.members.each do |member_name, member_target|
|
|
41
|
+
next unless target[member_name].nil?
|
|
42
|
+
|
|
43
|
+
if flattened_list?(member_target.shape)
|
|
44
|
+
target[member_name] = []
|
|
45
|
+
elsif flattened_map?(member_target.shape)
|
|
46
|
+
target[member_name] = {}
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if shape.union
|
|
52
|
+
# convert to subclass
|
|
53
|
+
member_subclass = shape.member_subclass(target.member).new
|
|
54
|
+
member_subclass[target.member] = target.value
|
|
55
|
+
target = member_subclass
|
|
56
|
+
end
|
|
57
|
+
target
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def list(ref, values, target = nil)
|
|
61
|
+
target = [] if target.nil?
|
|
62
|
+
values.each do |value|
|
|
63
|
+
target << parse_ref(ref.shape.member, value)
|
|
64
|
+
end
|
|
65
|
+
target
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def map(ref, values, target = nil)
|
|
69
|
+
target = {} if target.nil?
|
|
70
|
+
values.each do |key, value|
|
|
71
|
+
target[key] = parse_ref(ref.shape.value, value) unless value.nil?
|
|
72
|
+
end
|
|
73
|
+
target
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def parse_ref(ref, value, target = nil)
|
|
77
|
+
if value.nil?
|
|
78
|
+
nil
|
|
79
|
+
else
|
|
80
|
+
case ref.shape
|
|
81
|
+
when StructureShape then structure(ref, value, target)
|
|
82
|
+
when ListShape then list(ref, value, target)
|
|
83
|
+
when MapShape then map(ref, value, target)
|
|
84
|
+
else value
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Aws
|
|
4
|
+
module Stubbing
|
|
5
|
+
module Protocols
|
|
6
|
+
class RpcV2
|
|
7
|
+
|
|
8
|
+
def stub_data(api, operation, data)
|
|
9
|
+
resp = Seahorse::Client::Http::Response.new
|
|
10
|
+
resp.status_code = 200
|
|
11
|
+
resp.headers['Content-Type'] = content_type(api)
|
|
12
|
+
resp.headers['x-amzn-RequestId'] = 'stubbed-request-id'
|
|
13
|
+
resp.body = build_body(operation, data)
|
|
14
|
+
resp
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
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
|
+
}
|
|
25
|
+
JSON
|
|
26
|
+
http_resp
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def content_type(api)
|
|
32
|
+
'application/cbor'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def build_body(operation, data)
|
|
36
|
+
Aws::RpcV2::Builder.new(operation.output).serialize(data)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/aws-sdk-core/util.rb
CHANGED
|
@@ -67,6 +67,45 @@ module Aws
|
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
# @param [Number] input
|
|
71
|
+
# @return [Number, String] The serialized number
|
|
72
|
+
def serialize_number(input)
|
|
73
|
+
if input == ::Float::INFINITY then 'Infinity'
|
|
74
|
+
elsif input == -::Float::INFINITY then '-Infinity'
|
|
75
|
+
elsif input&.nan? then 'NaN'
|
|
76
|
+
else
|
|
77
|
+
input
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# @param [String] str
|
|
82
|
+
# @return [Number] The input as a number
|
|
83
|
+
def deserialize_number(str)
|
|
84
|
+
case str
|
|
85
|
+
when 'Infinity' then ::Float::INFINITY
|
|
86
|
+
when '-Infinity' then -::Float::INFINITY
|
|
87
|
+
when 'NaN' then ::Float::NAN
|
|
88
|
+
when nil then nil
|
|
89
|
+
else str.to_f
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @param [String] value
|
|
94
|
+
# @return [Time]
|
|
95
|
+
def deserialize_time(value)
|
|
96
|
+
case value
|
|
97
|
+
when nil then nil
|
|
98
|
+
when /^[\d.]+$/ then Time.at(value.to_f).utc
|
|
99
|
+
else
|
|
100
|
+
begin
|
|
101
|
+
fractional_time = Time.parse(value).to_f
|
|
102
|
+
Time.at(fractional_time).utc
|
|
103
|
+
rescue ArgumentError
|
|
104
|
+
raise "unhandled timestamp format `#{value}'"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
70
109
|
end
|
|
71
110
|
end
|
|
72
111
|
end
|
|
@@ -62,7 +62,7 @@ module Aws
|
|
|
62
62
|
def send_request(options)
|
|
63
63
|
req = options[:client].build_request(@operation_name, options[:params])
|
|
64
64
|
req.handlers.remove(RAISE_HANDLER)
|
|
65
|
-
Aws::Plugins::UserAgent.
|
|
65
|
+
Aws::Plugins::UserAgent.metric('WAITER') do
|
|
66
66
|
req.send_request
|
|
67
67
|
end
|
|
68
68
|
end
|
|
@@ -10,6 +10,8 @@ module Aws
|
|
|
10
10
|
|
|
11
11
|
def initialize(rules, options = {})
|
|
12
12
|
@rules = rules
|
|
13
|
+
@location_name =
|
|
14
|
+
options[:location_name].nil? ? @rules.location_name : options[:location_name]
|
|
13
15
|
@xml = options[:target] || []
|
|
14
16
|
indent = options[:indent] || ''
|
|
15
17
|
pad = options[:pad] || ''
|
|
@@ -17,7 +19,7 @@ module Aws
|
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def to_xml(params)
|
|
20
|
-
structure(@
|
|
22
|
+
structure(@location_name, @rules, params)
|
|
21
23
|
@xml.join
|
|
22
24
|
end
|
|
23
25
|
alias serialize to_xml
|
|
@@ -50,7 +52,7 @@ module Aws
|
|
|
50
52
|
def list(name, ref, values)
|
|
51
53
|
if ref[:flattened] || ref.shape.flattened
|
|
52
54
|
values.each do |value|
|
|
53
|
-
member(
|
|
55
|
+
member(name, ref.shape.member, value)
|
|
54
56
|
end
|
|
55
57
|
else
|
|
56
58
|
node(name, ref) do
|
|
@@ -65,7 +67,7 @@ module Aws
|
|
|
65
67
|
def map(name, ref, hash)
|
|
66
68
|
key_ref = ref.shape.key
|
|
67
69
|
value_ref = ref.shape.value
|
|
68
|
-
if ref.shape.flattened
|
|
70
|
+
if ref[:flattened] || ref.shape.flattened
|
|
69
71
|
hash.each do |key, value|
|
|
70
72
|
node(name, ref) do
|
|
71
73
|
member(key_ref.location_name || 'key', key_ref, key)
|
|
@@ -75,7 +77,8 @@ module Aws
|
|
|
75
77
|
else
|
|
76
78
|
node(name, ref) do
|
|
77
79
|
hash.each do |key, value|
|
|
78
|
-
|
|
80
|
+
# Pass in a new ShapeRef to create an entry node
|
|
81
|
+
node('entry', ShapeRef.new) do
|
|
79
82
|
member(key_ref.location_name || 'key', key_ref, key)
|
|
80
83
|
member(value_ref.location_name || 'value', value_ref, value)
|
|
81
84
|
end
|
|
@@ -129,11 +132,16 @@ module Aws
|
|
|
129
132
|
end
|
|
130
133
|
|
|
131
134
|
def shape_attrs(ref)
|
|
132
|
-
if xmlns = ref['xmlNamespace']
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
135
|
+
if (xmlns = ref['xmlNamespace'])
|
|
136
|
+
case xmlns
|
|
137
|
+
when String
|
|
138
|
+
{ 'xmlns' => xmlns }
|
|
139
|
+
when Hash
|
|
140
|
+
if (prefix = xmlns['prefix'])
|
|
141
|
+
{ "xmlns:#{prefix}" => xmlns['uri'] }
|
|
142
|
+
else
|
|
143
|
+
{ 'xmlns' => xmlns['uri'] }
|
|
144
|
+
end
|
|
137
145
|
end
|
|
138
146
|
else
|
|
139
147
|
{}
|