aws-sdk-core 3.117.0 → 3.197.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +836 -0
  3. data/VERSION +1 -1
  4. data/lib/aws-defaults/default_configuration.rb +153 -0
  5. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  6. data/lib/aws-defaults.rb +3 -0
  7. data/lib/aws-sdk-core/arn.rb +13 -0
  8. data/lib/aws-sdk-core/assume_role_credentials.rb +21 -7
  9. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +14 -10
  10. data/lib/aws-sdk-core/binary/decode_handler.rb +0 -5
  11. data/lib/aws-sdk-core/binary/encode_handler.rb +12 -1
  12. data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
  13. data/lib/aws-sdk-core/client_stubs.rb +20 -13
  14. data/lib/aws-sdk-core/credential_provider.rb +4 -1
  15. data/lib/aws-sdk-core/credential_provider_chain.rb +8 -5
  16. data/lib/aws-sdk-core/ec2_metadata.rb +4 -3
  17. data/lib/aws-sdk-core/ecs_credentials.rb +187 -52
  18. data/lib/aws-sdk-core/endpoints/condition.rb +41 -0
  19. data/lib/aws-sdk-core/endpoints/endpoint.rb +17 -0
  20. data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +75 -0
  21. data/lib/aws-sdk-core/endpoints/error_rule.rb +42 -0
  22. data/lib/aws-sdk-core/endpoints/function.rb +80 -0
  23. data/lib/aws-sdk-core/endpoints/matchers.rb +135 -0
  24. data/lib/aws-sdk-core/endpoints/reference.rb +31 -0
  25. data/lib/aws-sdk-core/endpoints/rule.rb +25 -0
  26. data/lib/aws-sdk-core/endpoints/rule_set.rb +52 -0
  27. data/lib/aws-sdk-core/endpoints/rules_provider.rb +37 -0
  28. data/lib/aws-sdk-core/endpoints/templater.rb +58 -0
  29. data/lib/aws-sdk-core/endpoints/tree_rule.rb +45 -0
  30. data/lib/aws-sdk-core/endpoints/url.rb +60 -0
  31. data/lib/aws-sdk-core/endpoints.rb +78 -0
  32. data/lib/aws-sdk-core/errors.rb +17 -4
  33. data/lib/aws-sdk-core/event_emitter.rb +0 -16
  34. data/lib/aws-sdk-core/ini_parser.rb +7 -0
  35. data/lib/aws-sdk-core/instance_profile_credentials.rb +127 -33
  36. data/lib/aws-sdk-core/json/builder.rb +8 -1
  37. data/lib/aws-sdk-core/json/error_handler.rb +30 -4
  38. data/lib/aws-sdk-core/json/handler.rb +8 -1
  39. data/lib/aws-sdk-core/json/json_engine.rb +10 -8
  40. data/lib/aws-sdk-core/json/oj_engine.rb +33 -6
  41. data/lib/aws-sdk-core/json/parser.rb +38 -2
  42. data/lib/aws-sdk-core/json.rb +8 -26
  43. data/lib/aws-sdk-core/log/formatter.rb +6 -0
  44. data/lib/aws-sdk-core/log/param_filter.rb +9 -1
  45. data/lib/aws-sdk-core/lru_cache.rb +75 -0
  46. data/lib/aws-sdk-core/pageable_response.rb +81 -32
  47. data/lib/aws-sdk-core/param_validator.rb +36 -2
  48. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
  49. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +342 -0
  50. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +1 -0
  51. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
  52. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +29 -1
  53. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  54. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +6 -2
  55. data/lib/aws-sdk-core/plugins/http_checksum.rb +9 -1
  56. data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
  57. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +34 -6
  58. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  59. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +17 -0
  60. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +4 -2
  61. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +1 -2
  62. data/lib/aws-sdk-core/plugins/recursion_detection.rb +38 -0
  63. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +144 -17
  64. data/lib/aws-sdk-core/plugins/request_compression.rb +226 -0
  65. data/lib/aws-sdk-core/plugins/response_paging.rb +1 -1
  66. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +7 -4
  67. data/lib/aws-sdk-core/plugins/retry_errors.rb +33 -7
  68. data/lib/aws-sdk-core/plugins/sign.rb +211 -0
  69. data/lib/aws-sdk-core/plugins/signature_v2.rb +1 -0
  70. data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -31
  71. data/lib/aws-sdk-core/plugins/stub_responses.rb +6 -1
  72. data/lib/aws-sdk-core/plugins/user_agent.rb +152 -14
  73. data/lib/aws-sdk-core/process_credentials.rb +50 -34
  74. data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
  75. data/lib/aws-sdk-core/query/param_builder.rb +2 -2
  76. data/lib/aws-sdk-core/refreshing_credentials.rb +49 -18
  77. data/lib/aws-sdk-core/refreshing_token.rb +71 -0
  78. data/lib/aws-sdk-core/rest/handler.rb +1 -1
  79. data/lib/aws-sdk-core/rest/request/body.rb +49 -4
  80. data/lib/aws-sdk-core/rest/request/content_type.rb +60 -0
  81. data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
  82. data/lib/aws-sdk-core/rest/request/headers.rb +23 -7
  83. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +62 -36
  84. data/lib/aws-sdk-core/rest/response/body.rb +15 -1
  85. data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
  86. data/lib/aws-sdk-core/rest/response/headers.rb +10 -3
  87. data/lib/aws-sdk-core/rest.rb +1 -0
  88. data/lib/aws-sdk-core/shared_config.rb +112 -12
  89. data/lib/aws-sdk-core/sso_credentials.rb +92 -51
  90. data/lib/aws-sdk-core/sso_token_provider.rb +135 -0
  91. data/lib/aws-sdk-core/static_token_provider.rb +14 -0
  92. data/lib/aws-sdk-core/structure.rb +16 -5
  93. data/lib/aws-sdk-core/stubbing/stub_data.rb +11 -0
  94. data/lib/aws-sdk-core/token.rb +31 -0
  95. data/lib/aws-sdk-core/token_provider.rb +15 -0
  96. data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
  97. data/lib/aws-sdk-core/util.rb +39 -0
  98. data/lib/aws-sdk-core/waiters/poller.rb +4 -2
  99. data/lib/aws-sdk-core/xml/builder.rb +17 -9
  100. data/lib/aws-sdk-core/xml/error_handler.rb +31 -8
  101. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  102. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +1 -1
  103. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +0 -8
  104. data/lib/aws-sdk-core/xml/parser/frame.rb +27 -20
  105. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  106. data/lib/aws-sdk-core.rb +21 -0
  107. data/lib/aws-sdk-sso/client.rb +157 -50
  108. data/lib/aws-sdk-sso/endpoint_parameters.rb +66 -0
  109. data/lib/aws-sdk-sso/endpoint_provider.rb +57 -0
  110. data/lib/aws-sdk-sso/endpoints.rb +72 -0
  111. data/lib/aws-sdk-sso/plugins/endpoints.rb +78 -0
  112. data/lib/aws-sdk-sso/types.rb +8 -43
  113. data/lib/aws-sdk-sso.rb +5 -1
  114. data/lib/aws-sdk-ssooidc/client.rb +1008 -0
  115. data/lib/aws-sdk-ssooidc/client_api.rb +293 -0
  116. data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
  117. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +66 -0
  118. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +57 -0
  119. data/lib/aws-sdk-ssooidc/endpoints.rb +72 -0
  120. data/lib/aws-sdk-ssooidc/errors.rb +342 -0
  121. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +78 -0
  122. data/lib/aws-sdk-ssooidc/resource.rb +26 -0
  123. data/lib/aws-sdk-ssooidc/types.rb +823 -0
  124. data/lib/aws-sdk-ssooidc.rb +59 -0
  125. data/lib/aws-sdk-sts/client.rb +472 -398
  126. data/lib/aws-sdk-sts/client_api.rb +20 -9
  127. data/lib/aws-sdk-sts/endpoint_parameters.rb +78 -0
  128. data/lib/aws-sdk-sts/endpoint_provider.rb +112 -0
  129. data/lib/aws-sdk-sts/endpoints.rb +136 -0
  130. data/lib/aws-sdk-sts/plugins/endpoints.rb +86 -0
  131. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +5 -1
  132. data/lib/aws-sdk-sts/presigner.rb +14 -10
  133. data/lib/aws-sdk-sts/types.rb +168 -227
  134. data/lib/aws-sdk-sts.rb +5 -1
  135. data/lib/seahorse/client/async_base.rb +1 -2
  136. data/lib/seahorse/client/async_response.rb +19 -0
  137. data/lib/seahorse/client/base.rb +1 -0
  138. data/lib/seahorse/client/configuration.rb +5 -5
  139. data/lib/seahorse/client/h2/connection.rb +15 -16
  140. data/lib/seahorse/client/h2/handler.rb +5 -5
  141. data/lib/seahorse/client/net_http/connection_pool.rb +10 -9
  142. data/lib/seahorse/client/net_http/handler.rb +15 -7
  143. data/lib/seahorse/client/net_http/patches.rb +12 -86
  144. data/lib/seahorse/client/plugin.rb +9 -0
  145. data/lib/seahorse/client/plugins/content_length.rb +11 -5
  146. data/lib/seahorse/client/plugins/h2.rb +3 -3
  147. data/lib/seahorse/client/plugins/net_http.rb +73 -10
  148. data/lib/seahorse/client/plugins/request_callback.rb +40 -9
  149. data/lib/seahorse/client/response.rb +6 -0
  150. data/lib/seahorse/model/operation.rb +6 -0
  151. data/lib/seahorse/model/shapes.rb +27 -2
  152. data/lib/seahorse/util.rb +4 -0
  153. data/sig/aws-sdk-core/client_stubs.rbs +10 -0
  154. data/sig/aws-sdk-core/errors.rbs +22 -0
  155. data/sig/aws-sdk-core/resources/collection.rbs +21 -0
  156. data/sig/aws-sdk-core/structure.rbs +4 -0
  157. data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
  158. data/sig/aws-sdk-core.rbs +7 -0
  159. data/sig/seahorse/client/base.rbs +25 -0
  160. data/sig/seahorse/client/handler_builder.rbs +16 -0
  161. data/sig/seahorse/client/response.rbs +61 -0
  162. metadata +82 -17
  163. data/lib/aws-sdk-sso/plugins/content_type.rb +0 -25
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Plugins
5
+ # @api private
6
+ class RecursionDetection < Seahorse::Client::Plugin
7
+
8
+ # @api private
9
+ class Handler < Seahorse::Client::Handler
10
+ def call(context)
11
+
12
+ unless context.http_request.headers.key?('x-amzn-trace-id')
13
+ if ENV['AWS_LAMBDA_FUNCTION_NAME'] &&
14
+ (trace_id = validate_header(ENV['_X_AMZN_TRACE_ID']))
15
+ context.http_request.headers['x-amzn-trace-id'] = trace_id
16
+ end
17
+ end
18
+ @handler.call(context)
19
+ end
20
+
21
+ private
22
+ def validate_header(header_value)
23
+ return unless header_value
24
+
25
+ if (header_value.chars & (0..31).map(&:chr)).any?
26
+ raise ArgumentError, 'Invalid _X_AMZN_TRACE_ID value: '\
27
+ 'contains ASCII control characters'
28
+ end
29
+ header_value
30
+ end
31
+ end
32
+
33
+ # should be at the end of build so that
34
+ # modeled traits / service customizations apply first
35
+ handler(Handler, step: :build, order: 99)
36
+ end
37
+ end
38
+ end
@@ -24,30 +24,44 @@ a default `:region` is searched for in the following locations:
24
24
  resolve_region(cfg)
25
25
  end
26
26
 
27
+ option(:use_dualstack_endpoint,
28
+ doc_type: 'Boolean',
29
+ docstring: <<-DOCS) do |cfg|
30
+ When set to `true`, dualstack enabled endpoints (with `.aws` TLD)
31
+ will be used if available.
32
+ DOCS
33
+ resolve_use_dualstack_endpoint(cfg)
34
+ end
35
+
36
+ option(:use_fips_endpoint,
37
+ doc_type: 'Boolean',
38
+ docstring: <<-DOCS) do |cfg|
39
+ When set to `true`, fips compatible endpoints will be used if available.
40
+ When a `fips` region is used, the region is normalized and this config
41
+ is set to `true`.
42
+ DOCS
43
+ resolve_use_fips_endpoint(cfg)
44
+ end
45
+
46
+ # This option signals whether :endpoint was provided or not.
47
+ # Legacy endpoints must continue to be generated at client time.
27
48
  option(:regional_endpoint, false)
28
49
 
50
+ option(:ignore_configured_endpoint_urls,
51
+ doc_type: 'Boolean',
52
+ docstring: <<-DOCS) do |cfg|
53
+ Setting to true disables use of endpoint URLs provided via environment
54
+ variables and the shared configuration file.
55
+ DOCS
56
+ resolve_ignore_configured_endpoint_urls(cfg)
57
+ end
58
+
29
59
  option(:endpoint, doc_type: String, docstring: <<-DOCS) do |cfg|
30
60
  The client endpoint is normally constructed from the `:region`
31
61
  option. You should only configure an `:endpoint` when connecting
32
62
  to test or custom endpoints. This should be a valid HTTP(S) URI.
33
63
  DOCS
34
- endpoint_prefix = cfg.api.metadata['endpointPrefix']
35
- if cfg.region && endpoint_prefix
36
- if cfg.respond_to?(:sts_regional_endpoints)
37
- sts_regional = cfg.sts_regional_endpoints
38
- end
39
-
40
- # check region is a valid RFC host label
41
- unless Seahorse::Util.host_label?(cfg.region)
42
- raise Errors::InvalidRegionError
43
- end
44
-
45
- Aws::Partitions::EndpointProvider.resolve(
46
- cfg.region,
47
- endpoint_prefix,
48
- sts_regional
49
- )
50
- end
64
+ resolve_endpoint(cfg)
51
65
  end
52
66
 
53
67
  def after_initialize(client)
@@ -66,6 +80,119 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
66
80
  cfg_region = Aws.shared_config.region(profile: cfg.profile)
67
81
  env_region || cfg_region
68
82
  end
83
+
84
+ def resolve_use_dualstack_endpoint(cfg)
85
+ value = ENV['AWS_USE_DUALSTACK_ENDPOINT']
86
+ value ||= Aws.shared_config.use_dualstack_endpoint(
87
+ profile: cfg.profile
88
+ )
89
+ Aws::Util.str_2_bool(value) || false
90
+ end
91
+
92
+ def resolve_use_fips_endpoint(cfg)
93
+ value = ENV['AWS_USE_FIPS_ENDPOINT']
94
+ value ||= Aws.shared_config.use_fips_endpoint(profile: cfg.profile)
95
+ Aws::Util.str_2_bool(value) || false
96
+ end
97
+
98
+ def resolve_ignore_configured_endpoint_urls(cfg)
99
+ value = ENV['AWS_IGNORE_CONFIGURED_ENDPOINT_URLS']
100
+ value ||= Aws.shared_config.ignore_configured_endpoint_urls(profile: cfg.profile)
101
+ Aws::Util.str_2_bool(value&.downcase) || false
102
+ end
103
+
104
+ # NOTE: with Endpoints 2.0, some of this logic is deprecated
105
+ # but because new old service gems may depend on new core versions
106
+ # we must preserve that behavior.
107
+ # Additional behavior controls the setting of the custom SDK::Endpoint
108
+ # parameter.
109
+ # When the `regional_endpoint` config is set to true - this indicates to
110
+ # Endpoints2.0 that a custom endpoint has NOT been configured by the user.
111
+ def resolve_endpoint(cfg)
112
+ endpoint = resolve_custom_config_endpoint(cfg)
113
+ endpoint_prefix = cfg.api.metadata['endpointPrefix']
114
+
115
+ return endpoint unless endpoint.nil? && cfg.region && endpoint_prefix
116
+
117
+ validate_region!(cfg.region)
118
+ handle_legacy_pseudo_regions(cfg)
119
+
120
+ # set regional_endpoint flag - this indicates to Endpoints 2.0
121
+ # that a custom endpoint has NOT been configured by the user
122
+ cfg.override_config(:regional_endpoint, true)
123
+
124
+ resolve_legacy_endpoint(cfg)
125
+ end
126
+
127
+ # get a custom configured endpoint from ENV or configuration
128
+ def resolve_custom_config_endpoint(cfg)
129
+ return if cfg.ignore_configured_endpoint_urls
130
+
131
+
132
+ env_service_endpoint(cfg) || env_global_endpoint(cfg) || shared_config_endpoint(cfg)
133
+ end
134
+
135
+ def env_service_endpoint(cfg)
136
+ service_id = cfg.api.metadata['serviceId'] || cfg.api.metadata['endpointPrefix']
137
+ env_service_id = service_id.gsub(" ", "_").upcase
138
+ return unless endpoint = ENV["AWS_ENDPOINT_URL_#{env_service_id}"]
139
+
140
+ cfg.logger&.debug(
141
+ "Endpoint configured from ENV['AWS_ENDPOINT_URL_#{env_service_id}']: #{endpoint}\n")
142
+ endpoint
143
+ end
144
+
145
+ def env_global_endpoint(cfg)
146
+ return unless endpoint = ENV['AWS_ENDPOINT_URL']
147
+
148
+ cfg.logger&.debug(
149
+ "Endpoint configured from ENV['AWS_ENDPOINT_URL']: #{endpoint}\n")
150
+ endpoint
151
+ end
152
+
153
+ def shared_config_endpoint(cfg)
154
+ service_id = cfg.api.metadata['serviceId'] || cfg.api.metadata['endpointPrefix']
155
+ return unless endpoint = Aws.shared_config.configured_endpoint(profile: cfg.profile, service_id: service_id)
156
+
157
+ cfg.logger&.debug(
158
+ "Endpoint configured from shared config(profile: #{cfg.profile}): #{endpoint}\n")
159
+ endpoint
160
+ end
161
+
162
+ # check region is a valid RFC host label
163
+ def validate_region!(region)
164
+ unless Seahorse::Util.host_label?(region)
165
+ raise Errors::InvalidRegionError
166
+ end
167
+ end
168
+
169
+ def handle_legacy_pseudo_regions(cfg)
170
+ region = cfg.region
171
+ new_region = region.gsub('fips-', '').gsub('-fips', '')
172
+ if region != new_region
173
+ warn("Legacy region #{region} was transformed to #{new_region}."\
174
+ '`use_fips_endpoint` config was set to true.')
175
+ cfg.override_config(:use_fips_endpoint, true)
176
+ cfg.override_config(:region, new_region)
177
+ end
178
+ end
179
+ # set a default endpoint in config using legacy (endpoints.json) resolver
180
+ def resolve_legacy_endpoint(cfg)
181
+ endpoint_prefix = cfg.api.metadata['endpointPrefix']
182
+ if cfg.respond_to?(:sts_regional_endpoints)
183
+ sts_regional = cfg.sts_regional_endpoints
184
+ end
185
+
186
+ Aws::Partitions::EndpointProvider.resolve(
187
+ cfg.region,
188
+ endpoint_prefix,
189
+ sts_regional,
190
+ {
191
+ dualstack: cfg.use_dualstack_endpoint,
192
+ fips: cfg.use_fips_endpoint
193
+ }
194
+ )
195
+ end
69
196
  end
70
197
  end
71
198
  end
@@ -0,0 +1,226 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Plugins
5
+ # @api private
6
+ class RequestCompression < Seahorse::Client::Plugin
7
+ DEFAULT_MIN_COMPRESSION_SIZE = 10_240
8
+ MIN_COMPRESSION_SIZE_LIMIT = 10_485_760
9
+ SUPPORTED_ENCODINGS = %w[gzip].freeze
10
+ CHUNK_SIZE = 1 * 1024 * 1024 # one MB
11
+
12
+ option(
13
+ :disable_request_compression,
14
+ default: false,
15
+ doc_type: 'Boolean',
16
+ docstring: <<-DOCS) do |cfg|
17
+ When set to 'true' the request body will not be compressed
18
+ for supported operations.
19
+ DOCS
20
+ resolve_disable_request_compression(cfg)
21
+ end
22
+
23
+ option(
24
+ :request_min_compression_size_bytes,
25
+ default: 10_240,
26
+ doc_type: 'Integer',
27
+ docstring: <<-DOCS) do |cfg|
28
+ The minimum size in bytes that triggers compression for request
29
+ bodies. The value must be non-negative integer value between 0
30
+ and 10485780 bytes inclusive.
31
+ DOCS
32
+ resolve_request_min_compression_size_bytes(cfg)
33
+ end
34
+
35
+ def after_initialize(client)
36
+ validate_disable_request_compression_input(client.config)
37
+ validate_request_min_compression_size_bytes_input(client.config)
38
+ end
39
+
40
+ def validate_disable_request_compression_input(cfg)
41
+ unless [true, false].include?(cfg.disable_request_compression)
42
+ raise ArgumentError,
43
+ 'Must provide either `true` or `false` for the '\
44
+ '`disable_request_compression` configuration option.'
45
+ end
46
+ end
47
+
48
+ def validate_request_min_compression_size_bytes_input(cfg)
49
+ value = Integer(cfg.request_min_compression_size_bytes)
50
+ unless value.between?(0, MIN_COMPRESSION_SIZE_LIMIT)
51
+ raise ArgumentError,
52
+ 'Must provide a non-negative integer value between '\
53
+ '`0` and `10485760` bytes inclusive for the '\
54
+ '`request_min_compression_size_bytes` configuration option.'
55
+ end
56
+ end
57
+
58
+ def add_handlers(handlers, _config)
59
+ # priority set to ensure compression happens BEFORE checksum
60
+ handlers.add(CompressionHandler, priority: 16, step: :build)
61
+ end
62
+
63
+ class << self
64
+ private
65
+
66
+ def resolve_disable_request_compression(cfg)
67
+ value = ENV['AWS_DISABLE_REQUEST_COMPRESSION'] ||
68
+ Aws.shared_config.disable_request_compression(profile: cfg.profile) ||
69
+ 'false'
70
+ Aws::Util.str_2_bool(value)
71
+ end
72
+
73
+ def resolve_request_min_compression_size_bytes(cfg)
74
+ value = ENV['AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES'] ||
75
+ Aws.shared_config.request_min_compression_size_bytes(profile: cfg.profile) ||
76
+ DEFAULT_MIN_COMPRESSION_SIZE.to_s
77
+ Integer(value)
78
+ end
79
+ end
80
+
81
+ # @api private
82
+ class CompressionHandler < Seahorse::Client::Handler
83
+ def call(context)
84
+ if should_compress?(context)
85
+ selected_encoding = request_encoding_selection(context)
86
+ if selected_encoding
87
+ if streaming?(context.operation.input)
88
+ process_streaming_compression(selected_encoding, context)
89
+ elsif context.http_request.body.size >= context.config.request_min_compression_size_bytes
90
+ process_compression(selected_encoding, context)
91
+ end
92
+ end
93
+ end
94
+ with_metric(selected_encoding) { @handler.call(context) }
95
+ end
96
+
97
+ private
98
+
99
+ def with_metric(encoding, &block)
100
+ case encoding
101
+ when 'gzip'
102
+ Aws::Plugins::UserAgent.metric('GZIP_REQUEST_COMPRESSION', &block)
103
+ else
104
+ block.call
105
+ end
106
+ end
107
+
108
+ def request_encoding_selection(context)
109
+ encoding_list = context.operation.request_compression['encodings']
110
+ encoding_list.find { |encoding| RequestCompression::SUPPORTED_ENCODINGS.include?(encoding) }
111
+ end
112
+
113
+ def update_content_encoding(encoding, context)
114
+ headers = context.http_request.headers
115
+ if headers['Content-Encoding']
116
+ headers['Content-Encoding'] += ", #{encoding}"
117
+ else
118
+ headers['Content-Encoding'] = encoding
119
+ end
120
+ end
121
+
122
+ def should_compress?(context)
123
+ context.operation.request_compression &&
124
+ !context.config.disable_request_compression
125
+ end
126
+
127
+ def streaming?(input)
128
+ if payload = input[:payload_member] # checking ref and shape
129
+ payload['streaming'] || payload.shape['streaming']
130
+ else
131
+ false
132
+ end
133
+ end
134
+
135
+ def process_compression(encoding, context)
136
+ case encoding
137
+ when 'gzip'
138
+ gzip_compress(context)
139
+ else
140
+ raise StandardError, "We currently do not support #{encoding} encoding"
141
+ end
142
+ update_content_encoding(encoding, context)
143
+ end
144
+
145
+ def gzip_compress(context)
146
+ compressed = StringIO.new
147
+ compressed.binmode
148
+ gzip_writer = Zlib::GzipWriter.new(compressed)
149
+ if context.http_request.body.respond_to?(:read)
150
+ update_in_chunks(gzip_writer, context.http_request.body)
151
+ else
152
+ gzip_writer.write(context.http_request.body)
153
+ end
154
+ gzip_writer.close
155
+ new_body = StringIO.new(compressed.string)
156
+ context.http_request.body = new_body
157
+ end
158
+
159
+ def update_in_chunks(compressor, io)
160
+ loop do
161
+ chunk = io.read(CHUNK_SIZE)
162
+ break unless chunk
163
+
164
+ compressor.write(chunk)
165
+ end
166
+ end
167
+
168
+ def process_streaming_compression(encoding, context)
169
+ case encoding
170
+ when 'gzip'
171
+ context.http_request.body = GzipIO.new(context.http_request.body)
172
+ else
173
+ raise StandardError, "We currently do not support #{encoding} encoding"
174
+ end
175
+ update_content_encoding(encoding, context)
176
+ end
177
+
178
+ # @api private
179
+ class GzipIO
180
+ def initialize(body)
181
+ @body = body
182
+ @buffer = ChunkBuffer.new
183
+ @gzip_writer = Zlib::GzipWriter.new(@buffer)
184
+ end
185
+
186
+ def read(length, buff = nil)
187
+ if @gzip_writer.closed?
188
+ # an empty string to signify an end as
189
+ # there will be nothing remaining to be read
190
+ StringIO.new('').read(length, buff)
191
+ return
192
+ end
193
+
194
+ chunk = @body.read(length)
195
+ if !chunk || chunk.empty?
196
+ # closing the writer will write one last chunk
197
+ # with a trailer (to be read from the @buffer)
198
+ @gzip_writer.close
199
+ else
200
+ # flush happens first to ensure that header fields
201
+ # are being sent over since write will override
202
+ @gzip_writer.flush
203
+ @gzip_writer.write(chunk)
204
+ end
205
+
206
+ StringIO.new(@buffer.last_chunk).read(length, buff)
207
+ end
208
+ end
209
+
210
+ # @api private
211
+ class ChunkBuffer
212
+ def initialize
213
+ @last_chunk = nil
214
+ end
215
+
216
+ attr_reader :last_chunk
217
+
218
+ def write(data)
219
+ @last_chunk = data
220
+ end
221
+ end
222
+ end
223
+
224
+ end
225
+ end
226
+ end
@@ -10,7 +10,7 @@ module Aws
10
10
  def call(context)
11
11
  context[:original_params] = context.params
12
12
  resp = @handler.call(context)
13
- resp.extend(PageableResponse)
13
+ PageableResponse.apply(resp)
14
14
  resp.pager = context.operation[:pager] || Aws::Pager::NullPager.new
15
15
  resp
16
16
  end
@@ -13,7 +13,8 @@ module Aws
13
13
  'InvalidAccessKeyId', # s3
14
14
  'AuthFailure', # ec2
15
15
  'InvalidIdentityToken', # sts
16
- 'ExpiredToken' # route53
16
+ 'ExpiredToken', # route53
17
+ 'ExpiredTokenException' # kinesis
17
18
  ]
18
19
  )
19
20
 
@@ -38,13 +39,15 @@ module Aws
38
39
 
39
40
  CHECKSUM_ERRORS = Set.new(
40
41
  [
41
- 'CRC32CheckFailed' # dynamodb
42
+ 'CRC32CheckFailed', # dynamodb
43
+ 'BadDigest' # s3
42
44
  ]
43
45
  )
44
46
 
45
47
  NETWORKING_ERRORS = Set.new(
46
48
  [
47
49
  'RequestTimeout', # s3
50
+ 'InternalError', # s3
48
51
  'RequestTimeoutException', # glacier
49
52
  'IDPCommunicationError' # sts
50
53
  ]
@@ -80,7 +83,7 @@ module Aws
80
83
  end
81
84
 
82
85
  def checksum?
83
- CHECKSUM_ERRORS.include?(@name) || @error.is_a?(Errors::ChecksumError)
86
+ CHECKSUM_ERRORS.include?(@name)
84
87
  end
85
88
 
86
89
  def networking?
@@ -141,4 +144,4 @@ module Aws
141
144
  end
142
145
  end
143
146
  end
144
- end
147
+ end
@@ -73,6 +73,7 @@ is only used in the `legacy` retry mode.
73
73
  :retry_jitter,
74
74
  default: :none,
75
75
  doc_type: Symbol,
76
+ rbs_type: '(:none | :equal | :full | ^(Integer) -> Integer)',
76
77
  docstring: <<-DOCS)
77
78
  A delay randomiser function used by the default backoff function.
78
79
  Some predefined functions can be referenced by name - :none, :equal, :full,
@@ -97,6 +98,7 @@ This option is only used in the `legacy` retry mode.
97
98
  :retry_mode,
98
99
  default: 'legacy',
99
100
  doc_type: String,
101
+ rbs_type: '("legacy" | "standard" | "adaptive")',
100
102
  docstring: <<-DOCS) do |cfg|
101
103
  Specifies which retry algorithm to use. Values are:
102
104
 
@@ -163,9 +165,15 @@ a clock skew correction and retry requests with skewed client clocks.
163
165
  option(:clock_skew) { Retries::ClockSkew.new }
164
166
 
165
167
  def self.resolve_retry_mode(cfg)
166
- value = ENV['AWS_RETRY_MODE'] ||
167
- Aws.shared_config.retry_mode(profile: cfg.profile) ||
168
- 'legacy'
168
+ default_mode_value =
169
+ if cfg.respond_to?(:defaults_mode_config_resolver)
170
+ cfg.defaults_mode_config_resolver.resolve(:retry_mode)
171
+ end
172
+
173
+ value = ENV['AWS_RETRY_MODE'] ||
174
+ Aws.shared_config.retry_mode(profile: cfg.profile) ||
175
+ default_mode_value ||
176
+ 'legacy'
169
177
  # Raise if provided value is not one of the retry modes
170
178
  if value != 'legacy' && value != 'standard' && value != 'adaptive'
171
179
  raise ArgumentError,
@@ -227,7 +235,7 @@ a clock skew correction and retry requests with skewed client clocks.
227
235
 
228
236
  get_send_token(config)
229
237
  add_retry_headers(context)
230
- response = @handler.call(context)
238
+ response = with_metric(config.retry_mode) { @handler.call(context) }
231
239
  error_inspector = Retries::ErrorInspector.new(
232
240
  response.error, response.context.http_response.status_code
233
241
  )
@@ -264,6 +272,10 @@ a clock skew correction and retry requests with skewed client clocks.
264
272
 
265
273
  private
266
274
 
275
+ def with_metric(retry_mode, &block)
276
+ Aws::Plugins::UserAgent.metric("RETRY_MODE_#{retry_mode.upcase}", &block)
277
+ end
278
+
267
279
  def get_send_token(config)
268
280
  # either fail fast or block until a token becomes available
269
281
  # must be configurable
@@ -307,12 +319,17 @@ a clock skew correction and retry requests with skewed client clocks.
307
319
 
308
320
  def retry_request(context, error)
309
321
  context.retries += 1
310
- context.config.credentials.refresh! if error.expired_credentials?
322
+ context.config.credentials.refresh! if refresh_credentials?(context, error)
311
323
  context.http_request.body.rewind
312
324
  context.http_response.reset
313
325
  call(context)
314
326
  end
315
327
 
328
+ def refresh_credentials?(context, error)
329
+ error.expired_credentials? &&
330
+ context.config.credentials.respond_to?(:refresh!)
331
+ end
332
+
316
333
  def add_retry_headers(context)
317
334
  request_pairs = {
318
335
  'attempt' => context.retries,
@@ -346,7 +363,7 @@ a clock skew correction and retry requests with skewed client clocks.
346
363
  class LegacyHandler < Seahorse::Client::Handler
347
364
 
348
365
  def call(context)
349
- response = @handler.call(context)
366
+ response = with_metric { @handler.call(context) }
350
367
  if response.error
351
368
  error_inspector = Retries::ErrorInspector.new(
352
369
  response.error, response.context.http_response.status_code
@@ -365,6 +382,10 @@ a clock skew correction and retry requests with skewed client clocks.
365
382
 
366
383
  private
367
384
 
385
+ def with_metric(&block)
386
+ Aws::Plugins::UserAgent.metric('RETRY_MODE_LEGACY', &block)
387
+ end
388
+
368
389
  def retry_if_possible(response, error_inspector)
369
390
  context = response.context
370
391
  if should_retry?(context, error_inspector)
@@ -377,7 +398,7 @@ a clock skew correction and retry requests with skewed client clocks.
377
398
  def retry_request(context, error)
378
399
  delay_retry(context)
379
400
  context.retries += 1
380
- context.config.credentials.refresh! if error.expired_credentials?
401
+ context.config.credentials.refresh! if refresh_credentials?(context, error)
381
402
  context.http_request.body.rewind
382
403
  context.http_response.reset
383
404
  call(context)
@@ -393,6 +414,11 @@ a clock skew correction and retry requests with skewed client clocks.
393
414
  response_truncatable?(context)
394
415
  end
395
416
 
417
+ def refresh_credentials?(context, error)
418
+ error.expired_credentials? &&
419
+ context.config.credentials.respond_to?(:refresh!)
420
+ end
421
+
396
422
  def retry_limit(context)
397
423
  context.config.retry_limit
398
424
  end