aws-sdk-core 3.197.0 → 3.201.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +54 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-sdk-core/binary/decode_handler.rb +3 -4
  5. data/lib/aws-sdk-core/binary/encode_handler.rb +1 -1
  6. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +1 -0
  7. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +4 -3
  8. data/lib/aws-sdk-core/cbor/cbor_engine.rb +19 -0
  9. data/lib/aws-sdk-core/cbor/decoder.rb +310 -0
  10. data/lib/aws-sdk-core/cbor/encoder.rb +243 -0
  11. data/lib/aws-sdk-core/cbor.rb +106 -0
  12. data/lib/aws-sdk-core/client_stubs.rb +3 -2
  13. data/lib/aws-sdk-core/endpoints/matchers.rb +5 -1
  14. data/lib/aws-sdk-core/endpoints.rb +64 -18
  15. data/lib/aws-sdk-core/error_handler.rb +41 -0
  16. data/lib/aws-sdk-core/errors.rb +9 -0
  17. data/lib/aws-sdk-core/json/error_handler.rb +6 -8
  18. data/lib/aws-sdk-core/json/handler.rb +5 -6
  19. data/lib/aws-sdk-core/json/json_engine.rb +3 -1
  20. data/lib/aws-sdk-core/json/oj_engine.rb +7 -1
  21. data/lib/aws-sdk-core/json/parser.rb +2 -0
  22. data/lib/aws-sdk-core/json.rb +43 -14
  23. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +2 -0
  24. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +2 -1
  25. data/lib/aws-sdk-core/plugins/global_configuration.rb +8 -9
  26. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +3 -1
  27. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -24
  28. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +6 -8
  29. data/lib/aws-sdk-core/plugins/protocols/query.rb +4 -2
  30. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +4 -3
  31. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +5 -1
  32. data/lib/aws-sdk-core/plugins/protocols/rpc_v2.rb +17 -0
  33. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +32 -3
  34. data/lib/aws-sdk-core/plugins/retry_errors.rb +0 -1
  35. data/lib/aws-sdk-core/plugins/sign.rb +10 -7
  36. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -1
  37. data/lib/aws-sdk-core/plugins/signature_v4.rb +2 -1
  38. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +16 -9
  39. data/lib/aws-sdk-core/process_credentials.rb +45 -27
  40. data/lib/aws-sdk-core/query/ec2_handler.rb +27 -0
  41. data/lib/aws-sdk-core/query/handler.rb +4 -4
  42. data/lib/aws-sdk-core/query.rb +2 -1
  43. data/lib/aws-sdk-core/rest/{request/content_type.rb → content_type_handler.rb} +1 -1
  44. data/lib/aws-sdk-core/rest/handler.rb +3 -4
  45. data/lib/aws-sdk-core/rest/request/endpoint.rb +3 -1
  46. data/lib/aws-sdk-core/rest.rb +1 -1
  47. data/lib/aws-sdk-core/rpc_v2/builder.rb +62 -0
  48. data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +45 -0
  49. data/lib/aws-sdk-core/rpc_v2/error_handler.rb +84 -0
  50. data/lib/aws-sdk-core/rpc_v2/handler.rb +74 -0
  51. data/lib/aws-sdk-core/rpc_v2/parser.rb +90 -0
  52. data/lib/aws-sdk-core/rpc_v2.rb +6 -0
  53. data/lib/aws-sdk-core/shared_config.rb +1 -0
  54. data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +41 -0
  55. data/lib/aws-sdk-core/xml/error_handler.rb +11 -37
  56. data/lib/aws-sdk-core/xml/parser.rb +2 -6
  57. data/lib/aws-sdk-core.rb +6 -2
  58. data/lib/aws-sdk-sso/client.rb +15 -3
  59. data/lib/aws-sdk-sso/client_api.rb +6 -0
  60. data/lib/aws-sdk-sso.rb +1 -1
  61. data/lib/aws-sdk-ssooidc/client.rb +15 -3
  62. data/lib/aws-sdk-ssooidc/client_api.rb +4 -0
  63. data/lib/aws-sdk-ssooidc.rb +1 -1
  64. data/lib/aws-sdk-sts/client.rb +15 -3
  65. data/lib/aws-sdk-sts/client_api.rb +4 -2
  66. data/lib/aws-sdk-sts.rb +1 -1
  67. data/lib/seahorse/client/base.rb +17 -7
  68. data/lib/seahorse/client/handler.rb +1 -1
  69. data/lib/seahorse/client/plugins/endpoint.rb +0 -1
  70. metadata +22 -8
  71. /data/lib/aws-sdk-core/xml/parser/{engines/libxml.rb → libxml_engine.rb} +0 -0
  72. /data/lib/aws-sdk-core/xml/parser/{engines/nokogiri.rb → nokogiri_engine.rb} +0 -0
  73. /data/lib/aws-sdk-core/xml/parser/{engines/oga.rb → oga_engine.rb} +0 -0
  74. /data/lib/aws-sdk-core/xml/parser/{engines/ox.rb → ox_engine.rb} +0 -0
  75. /data/lib/aws-sdk-core/xml/parser/{engines/rexml.rb → rexml_engine.rb} +0 -0
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../query'
4
-
5
3
  module Aws
6
4
  module Plugins
7
5
  module Protocols
8
6
  class Query < Seahorse::Client::Plugin
7
+
8
+ option(:protocol, 'query')
9
+
9
10
  handler(Aws::Query::Handler)
10
11
  handler(Xml::ErrorHandler, step: :sign)
12
+
11
13
  end
12
14
  end
13
15
  end
@@ -4,13 +4,14 @@ module Aws
4
4
  module Plugins
5
5
  module Protocols
6
6
  class RestJson < Seahorse::Client::Plugin
7
+
8
+ option(:protocol, 'rest-json')
9
+
7
10
  handler(Rest::Handler)
8
- # Rest::Handler will set a default JSON body, so size can be checked
9
- # if this handler is run after serialization.
10
11
  handler(Rest::ContentTypeHandler, priority: 30)
11
12
  handler(Json::ErrorHandler, step: :sign)
12
- end
13
13
 
14
+ end
14
15
  end
15
16
  end
16
17
  end
@@ -4,9 +4,13 @@ module Aws
4
4
  module Plugins
5
5
  module Protocols
6
6
  class RestXml < Seahorse::Client::Plugin
7
+
8
+ option(:protocol, 'rest-xml')
9
+
7
10
  handler(Rest::Handler)
8
- handler(Rest::ContentTypeHandler)
11
+ handler(Rest::ContentTypeHandler, priority: 30)
9
12
  handler(Xml::ErrorHandler, step: :sign)
13
+
10
14
  end
11
15
  end
12
16
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Plugins
5
+ module Protocols
6
+ class RpcV2 < Seahorse::Client::Plugin
7
+
8
+ option(:protocol, 'smithy-rpc-v2-cbor')
9
+
10
+ handler(Aws::RpcV2::Handler)
11
+ handler(Aws::RpcV2::ContentTypeHandler, priority: 30)
12
+ handler(Aws::RpcV2::ErrorHandler, step: :sign)
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -24,6 +24,21 @@ a default `:region` is searched for in the following locations:
24
24
  resolve_region(cfg)
25
25
  end
26
26
 
27
+ option(:sigv4a_signing_region_set,
28
+ doc_type: Array,
29
+ rbs_type: 'Array[String]',
30
+ docstring: <<-DOCS) do |cfg|
31
+ A list of regions that should be signed with SigV4a signing. When
32
+ not passed, a default `:sigv4a_signing_region_set` is searched for
33
+ in the following locations:
34
+
35
+ * `Aws.config[:sigv4a_signing_region_set]`
36
+ * `ENV['AWS_SIGV4A_SIGNING_REGION_SET']`
37
+ * `~/.aws/config`
38
+ DOCS
39
+ resolve_sigv4a_signing_region_set(cfg)
40
+ end
41
+
27
42
  option(:use_dualstack_endpoint,
28
43
  doc_type: 'Boolean',
29
44
  docstring: <<-DOCS) do |cfg|
@@ -65,9 +80,17 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
65
80
  end
66
81
 
67
82
  def after_initialize(client)
68
- if client.config.region.nil? || client.config.region == ''
69
- raise Errors::MissingRegionError
70
- end
83
+ region = client.config.region
84
+ raise Errors::MissingRegionError if region.nil? || region == ''
85
+
86
+ region_set = client.config.sigv4a_signing_region_set
87
+ return if region_set.nil?
88
+ raise Errors::InvalidRegionSetError unless region_set.is_a?(Array)
89
+
90
+ region_set = region_set.compact.reject(&:empty?)
91
+ raise Errors::InvalidRegionSetError if region_set.empty?
92
+
93
+ client.config.sigv4a_signing_region_set = region_set
71
94
  end
72
95
 
73
96
  class << self
@@ -81,6 +104,12 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
81
104
  env_region || cfg_region
82
105
  end
83
106
 
107
+ def resolve_sigv4a_signing_region_set(cfg)
108
+ value = ENV['AWS_SIGV4A_SIGNING_REGION_SET']
109
+ value ||= Aws.shared_config.sigv4a_signing_region_set(profile: cfg.profile)
110
+ value.split(',') if value
111
+ end
112
+
84
113
  def resolve_use_dualstack_endpoint(cfg)
85
114
  value = ENV['AWS_USE_DUALSTACK_ENDPOINT']
86
115
  value ||= Aws.shared_config.use_dualstack_endpoint(
@@ -113,7 +113,6 @@ Specifies which retry algorithm to use. Values are:
113
113
  functionality of `standard` mode along with automatic client side
114
114
  throttling. This is a provisional mode that may change behavior
115
115
  in the future.
116
-
117
116
  DOCS
118
117
  resolve_retry_mode(cfg)
119
118
  end
@@ -102,7 +102,7 @@ module Aws
102
102
  end
103
103
 
104
104
  region = if scheme_name == 'sigv4a'
105
- auth_scheme['signingRegionSet'].first
105
+ auth_scheme['signingRegionSet'].join(',')
106
106
  else
107
107
  auth_scheme['signingRegion']
108
108
  end
@@ -159,17 +159,20 @@ module Aws
159
159
  private
160
160
 
161
161
  def apply_authtype(context, req)
162
- # only used for eventstreaming at input
162
+ # only used for event streaming at input
163
163
  if context[:input_event_emitter]
164
164
  req.headers['X-Amz-Content-Sha256'] = 'STREAMING-AWS4-HMAC-SHA256-EVENTS'
165
- else
166
- if context.operation['authtype'].eql?('v4-unsigned-body') &&
167
- req.endpoint.scheme.eql?('https')
168
- req.headers['X-Amz-Content-Sha256'] ||= 'UNSIGNED-PAYLOAD'
169
- end
165
+ elsif unsigned_payload?(context, req)
166
+ req.headers['X-Amz-Content-Sha256'] ||= 'UNSIGNED-PAYLOAD'
170
167
  end
171
168
  end
172
169
 
170
+ def unsigned_payload?(context, req)
171
+ (context.operation['unsignedPayload'] ||
172
+ context.operation['authtype'] == 'v4-unsigned-body') &&
173
+ req.endpoint.scheme == 'https'
174
+ end
175
+
173
176
  def reset_signature(req)
174
177
  # in case this request is being re-signed
175
178
  req.headers.delete('Authorization')
@@ -3,7 +3,8 @@
3
3
  module Aws
4
4
  module Plugins
5
5
  # @api private
6
- # Necessary to keep after Endpoints 2.0
6
+ # Deprecated - does not look at new traits like `auth` and `unsignedPayload`
7
+ # Necessary to exist after endpoints 2.0 for old service clients + new core
7
8
  class SignatureV2 < Seahorse::Client::Plugin
8
9
 
9
10
  option(:v2_signer) do |cfg|
@@ -5,7 +5,8 @@ require 'aws-sigv4'
5
5
  module Aws
6
6
  module Plugins
7
7
  # @api private
8
- # Necessary to exist after endpoints 2.0
8
+ # Deprecated - does not look at new traits like `auth` and `unsignedPayload`
9
+ # Necessary to exist after endpoints 2.0 for old service clients + new core
9
10
  class SignatureV4 < Seahorse::Client::Plugin
10
11
 
11
12
  V4_AUTH = %w[v4 v4-unsigned-payload v4-unsigned-body]
@@ -5,7 +5,8 @@ module Aws
5
5
 
6
6
  # For Streaming Input Operations, when `requiresLength` is enabled
7
7
  # checking whether `Content-Length` header can be set,
8
- # for `v4-unsigned-body` operations, set `Transfer-Encoding` header
8
+ # for `unsignedPayload` and `v4-unsigned-body` operations,
9
+ # set `Transfer-Encoding` header.
9
10
  class TransferEncoding < Seahorse::Client::Plugin
10
11
 
11
12
  # @api private
@@ -16,8 +17,8 @@ module Aws
16
17
  unless context.http_request.body.respond_to?(:size)
17
18
  if requires_length?(context.operation.input)
18
19
  # if size of the IO is not available but required
19
- raise Aws::Errors::MissingContentLength.new
20
- elsif context.operation['authtype'] == "v4-unsigned-body"
20
+ raise Aws::Errors::MissingContentLength
21
+ elsif unsigned_payload?(context.operation)
21
22
  context.http_request.headers['Transfer-Encoding'] = 'chunked'
22
23
  end
23
24
  end
@@ -29,18 +30,24 @@ module Aws
29
30
  private
30
31
 
31
32
  def streaming?(ref)
32
- if payload = ref[:payload_member]
33
- payload["streaming"] || # checking ref and shape
34
- payload.shape["streaming"]
33
+ if (payload = ref[:payload_member])
34
+ payload['streaming'] || payload.shape['streaming']
35
35
  else
36
36
  false
37
37
  end
38
38
  end
39
39
 
40
+ def unsigned_payload?(operation)
41
+ operation['unsignedPayload'] ||
42
+ operation['authtype'] == 'v4-unsigned-body'
43
+ end
44
+
40
45
  def requires_length?(ref)
41
- payload = ref[:payload_member]
42
- payload["requiresLength"] || # checking ref and shape
43
- payload.shape["requiresLength"]
46
+ if (payload = ref[:payload_member])
47
+ payload['requiresLength'] || payload.shape['requiresLength']
48
+ else
49
+ false
50
+ end
44
51
  end
45
52
 
46
53
  end
@@ -2,9 +2,15 @@
2
2
 
3
3
  module Aws
4
4
  # A credential provider that executes a given process and attempts
5
- # to read its stdout to recieve a JSON payload containing the credentials.
5
+ # to read its stdout to receive a JSON payload containing the credentials.
6
6
  #
7
- # credentials = Aws::ProcessCredentials.new('/usr/bin/credential_proc')
7
+ # credentials = Aws::ProcessCredentials.new(['/usr/bin/credential_proc'])
8
+ # ec2 = Aws::EC2::Client.new(credentials: credentials)
9
+ #
10
+ # Arguments should be provided as strings in the array, for example:
11
+ #
12
+ # process = ['/usr/bin/credential_proc', 'arg1', 'arg2']
13
+ # credentials = Aws::ProcessCredentials.new(process)
8
14
  # ec2 = Aws::EC2::Client.new(credentials: credentials)
9
15
  #
10
16
  # Automatically handles refreshing credentials if an Expiration time is
@@ -19,40 +25,49 @@ module Aws
19
25
  # Creates a new ProcessCredentials object, which allows an
20
26
  # external process to be used as a credential provider.
21
27
  #
22
- # @param [String] process Invocation string for process
23
- # credentials provider.
28
+ # @param [Array<String>, String] process An array of strings including
29
+ # the process name and its arguments to execute, or a single string to be
30
+ # executed by the shell (deprecated and insecure).
24
31
  def initialize(process)
32
+ if process.is_a?(String)
33
+ warn('Passing a single string to Aws::ProcessCredentials.new '\
34
+ 'is insecure, please use use an array of system arguments instead')
35
+ end
25
36
  @process = process
26
- @credentials = credentials_from_process(@process)
37
+ @credentials = credentials_from_process
27
38
  @async_refresh = false
28
39
 
29
40
  super
30
41
  end
31
42
 
32
43
  private
33
- def credentials_from_process(proc_invocation)
34
- begin
35
- raw_out = `#{proc_invocation}`
36
- process_status = $?
37
- rescue Errno::ENOENT
38
- raise Errors::InvalidProcessCredentialsPayload.new("Could not find process #{proc_invocation}")
44
+
45
+ def credentials_from_process
46
+ r, w = IO.pipe
47
+ success = system(*@process, out: w)
48
+ w.close
49
+ raw_out = r.read
50
+ r.close
51
+
52
+ unless success
53
+ raise Errors::InvalidProcessCredentialsPayload.new(
54
+ 'credential_process provider failure, the credential process had '\
55
+ 'non zero exit status and failed to provide credentials'
56
+ )
39
57
  end
40
58
 
41
- if process_status.success?
42
- begin
43
- creds_json = Aws::Json.load(raw_out)
44
- rescue Aws::Json::ParseError
45
- raise Errors::InvalidProcessCredentialsPayload.new("Invalid JSON response")
46
- end
47
- payload_version = creds_json['Version']
48
- if payload_version == 1
49
- _parse_payload_format_v1(creds_json)
50
- else
51
- raise Errors::InvalidProcessCredentialsPayload.new("Invalid version #{payload_version} for credentials payload")
52
- end
53
- else
54
- raise Errors::InvalidProcessCredentialsPayload.new('credential_process provider failure, the credential process had non zero exit status and failed to provide credentials')
59
+ begin
60
+ creds_json = Aws::Json.load(raw_out)
61
+ rescue Aws::Json::ParseError
62
+ raise Errors::InvalidProcessCredentialsPayload.new('Invalid JSON response')
55
63
  end
64
+
65
+ payload_version = creds_json['Version']
66
+ return _parse_payload_format_v1(creds_json) if payload_version == 1
67
+
68
+ raise Errors::InvalidProcessCredentialsPayload.new(
69
+ "Invalid version #{payload_version} for credentials payload"
70
+ )
56
71
  end
57
72
 
58
73
  def _parse_payload_format_v1(creds_json)
@@ -64,11 +79,14 @@ module Aws
64
79
 
65
80
  @expiration = creds_json['Expiration'] ? Time.iso8601(creds_json['Expiration']) : nil
66
81
  return creds if creds.set?
67
- raise Errors::InvalidProcessCredentialsPayload.new("Invalid payload for JSON credentials version 1")
82
+
83
+ raise Errors::InvalidProcessCredentialsPayload.new(
84
+ 'Invalid payload for JSON credentials version 1'
85
+ )
68
86
  end
69
87
 
70
88
  def refresh
71
- @credentials = credentials_from_process(@process)
89
+ @credentials = credentials_from_process
72
90
  end
73
91
 
74
92
  def near_expiration?(expiration_length)
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # @api private
5
+ module Query
6
+ class EC2Handler < Aws::Query::Handler
7
+
8
+ def apply_params(param_list, params, rules)
9
+ Aws::Query::EC2ParamBuilder.new(param_list).apply(rules, params)
10
+ end
11
+
12
+ def parse_xml(context)
13
+ if (rules = context.operation.output)
14
+ parser = Xml::Parser.new(rules)
15
+ parser.parse(xml(context)) do |path, value|
16
+ if path.size == 2 && path.last == 'requestId'
17
+ context.metadata[:request_id] = value
18
+ end
19
+ end
20
+ else
21
+ EmptyStructure.new
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -27,13 +27,13 @@ module Aws
27
27
  # @return [Seahorse::Client::Response]
28
28
  def call(context)
29
29
  build_request(context)
30
- @handler.call(context).on_success do |response|
31
- response.error = nil
30
+ @handler.call(context).on_success do |resp|
31
+ resp.error = nil
32
32
  parsed = parse_xml(context)
33
33
  if parsed.nil? || parsed == EmptyStructure
34
- response.data = EmptyStructure.new
34
+ resp.data = EmptyStructure.new
35
35
  else
36
- response.data = parsed
36
+ resp.data = parsed
37
37
  end
38
38
  end
39
39
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'query/ec2_param_builder'
4
3
  require_relative 'query/handler'
4
+ require_relative 'query/ec2_handler'
5
5
  require_relative 'query/param'
6
6
  require_relative 'query/param_builder'
7
+ require_relative 'query/ec2_param_builder'
7
8
  require_relative 'query/param_list'
@@ -35,7 +35,7 @@ module Aws
35
35
 
36
36
  def eventstream?(context)
37
37
  context.operation.input.shape.members.each do |_, ref|
38
- return ref if ref.eventstream
38
+ return true if ref.eventstream
39
39
  end
40
40
  false
41
41
  end
@@ -7,10 +7,9 @@ module Aws
7
7
 
8
8
  def call(context)
9
9
  Rest::Request::Builder.new.apply(context)
10
- resp = @handler.call(context)
11
- resp.on(200..299) { |response| Response::Parser.new.apply(response) }
12
- resp.on(200..599) { |response| apply_request_id(context) }
13
- resp
10
+ response = @handler.call(context)
11
+ response.on(200..299) { |resp| Response::Parser.new.apply(resp) }
12
+ response.on(200..599) { |_resp| apply_request_id(context) }
14
13
  end
15
14
 
16
15
  private
@@ -30,7 +30,9 @@ module Aws
30
30
  private
31
31
 
32
32
  def apply_path_params(uri, params)
33
- path = uri.path.sub(%r{/$}, '') + @path_pattern.split('?')[0]
33
+ path = uri.path.sub(%r{/$}, '')
34
+ # handle trailing slash
35
+ path += @path_pattern.split('?')[0] if path.empty? || @path_pattern != '/'
34
36
  uri.path = path.gsub(/{.+?}/) do |placeholder|
35
37
  param_value_for_placeholder(placeholder, params)
36
38
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'rest/handler'
4
+ require_relative 'rest/content_type_handler'
4
5
  require_relative 'rest/request/body'
5
6
  require_relative 'rest/request/builder'
6
7
  require_relative 'rest/request/endpoint'
7
8
  require_relative 'rest/request/headers'
8
9
  require_relative 'rest/request/querystring_builder'
9
- require_relative 'rest/request/content_type'
10
10
  require_relative 'rest/response/body'
11
11
  require_relative 'rest/response/headers'
12
12
  require_relative 'rest/response/parser'
@@ -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