aws-sdk-core 3.100.0 → 3.130.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.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1294 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -1
  5. data/lib/aws-defaults/default_configuration.rb +153 -0
  6. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  7. data/lib/aws-defaults.rb +3 -0
  8. data/lib/aws-sdk-core/arn.rb +15 -0
  9. data/lib/aws-sdk-core/arn_parser.rb +2 -0
  10. data/lib/aws-sdk-core/assume_role_credentials.rb +21 -0
  11. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +9 -1
  12. data/lib/aws-sdk-core/async_client_stubs.rb +2 -0
  13. data/lib/aws-sdk-core/binary/decode_handler.rb +2 -0
  14. data/lib/aws-sdk-core/binary/encode_handler.rb +2 -0
  15. data/lib/aws-sdk-core/binary/event_builder.rb +2 -0
  16. data/lib/aws-sdk-core/binary/event_parser.rb +2 -0
  17. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +2 -0
  18. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +2 -0
  19. data/lib/aws-sdk-core/binary.rb +2 -0
  20. data/lib/aws-sdk-core/client_side_monitoring/publisher.rb +2 -0
  21. data/lib/aws-sdk-core/client_side_monitoring/request_metrics.rb +2 -0
  22. data/lib/aws-sdk-core/client_stubs.rb +7 -1
  23. data/lib/aws-sdk-core/credential_provider.rb +2 -0
  24. data/lib/aws-sdk-core/credential_provider_chain.rb +23 -1
  25. data/lib/aws-sdk-core/credentials.rb +2 -0
  26. data/lib/aws-sdk-core/deprecations.rb +2 -0
  27. data/lib/aws-sdk-core/eager_loader.rb +2 -0
  28. data/lib/aws-sdk-core/ec2_metadata.rb +238 -0
  29. data/lib/aws-sdk-core/ecs_credentials.rb +10 -4
  30. data/lib/aws-sdk-core/endpoint_cache.rb +2 -0
  31. data/lib/aws-sdk-core/errors.rb +11 -2
  32. data/lib/aws-sdk-core/event_emitter.rb +2 -0
  33. data/lib/aws-sdk-core/ini_parser.rb +2 -0
  34. data/lib/aws-sdk-core/instance_profile_credentials.rb +124 -22
  35. data/lib/aws-sdk-core/json/builder.rb +2 -0
  36. data/lib/aws-sdk-core/json/error_handler.rb +2 -0
  37. data/lib/aws-sdk-core/json/handler.rb +2 -0
  38. data/lib/aws-sdk-core/json/json_engine.rb +12 -8
  39. data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
  40. data/lib/aws-sdk-core/json/parser.rb +10 -0
  41. data/lib/aws-sdk-core/json.rb +10 -26
  42. data/lib/aws-sdk-core/log/formatter.rb +9 -3
  43. data/lib/aws-sdk-core/log/handler.rb +2 -0
  44. data/lib/aws-sdk-core/log/param_filter.rb +37 -12
  45. data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
  46. data/lib/aws-sdk-core/pageable_response.rb +82 -32
  47. data/lib/aws-sdk-core/pager.rb +5 -0
  48. data/lib/aws-sdk-core/param_converter.rb +2 -0
  49. data/lib/aws-sdk-core/param_validator.rb +54 -4
  50. data/lib/aws-sdk-core/plugins/api_key.rb +5 -1
  51. data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +2 -0
  52. data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +2 -0
  53. data/lib/aws-sdk-core/plugins/apig_user_agent.rb +2 -0
  54. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +340 -0
  55. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +2 -0
  56. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
  57. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +26 -7
  58. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  59. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +2 -0
  60. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
  61. data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +2 -0
  62. data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
  63. data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
  64. data/lib/aws-sdk-core/plugins/http_checksum.rb +10 -1
  65. data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
  66. data/lib/aws-sdk-core/plugins/invocation_id.rb +2 -0
  67. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +2 -0
  68. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  69. data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
  70. data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
  71. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
  72. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
  73. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
  74. data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
  75. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
  76. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
  77. data/lib/aws-sdk-core/plugins/recursion_detection.rb +27 -0
  78. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +50 -2
  79. data/lib/aws-sdk-core/plugins/response_paging.rb +3 -1
  80. data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +2 -0
  81. data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +2 -0
  82. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +7 -3
  83. data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +2 -0
  84. data/lib/aws-sdk-core/plugins/retry_errors.rb +15 -6
  85. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -0
  86. data/lib/aws-sdk-core/plugins/signature_v4.rb +17 -24
  87. data/lib/aws-sdk-core/plugins/stub_responses.rb +9 -1
  88. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +2 -0
  89. data/lib/aws-sdk-core/plugins/user_agent.rb +2 -0
  90. data/lib/aws-sdk-core/process_credentials.rb +8 -6
  91. data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
  92. data/lib/aws-sdk-core/query/handler.rb +2 -0
  93. data/lib/aws-sdk-core/query/param.rb +2 -0
  94. data/lib/aws-sdk-core/query/param_builder.rb +2 -0
  95. data/lib/aws-sdk-core/query/param_list.rb +2 -0
  96. data/lib/aws-sdk-core/query.rb +2 -0
  97. data/lib/aws-sdk-core/refreshing_credentials.rb +42 -11
  98. data/lib/aws-sdk-core/resources/collection.rb +2 -0
  99. data/lib/aws-sdk-core/rest/handler.rb +2 -0
  100. data/lib/aws-sdk-core/rest/request/body.rb +21 -1
  101. data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
  102. data/lib/aws-sdk-core/rest/request/endpoint.rb +2 -0
  103. data/lib/aws-sdk-core/rest/request/headers.rb +20 -6
  104. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +2 -0
  105. data/lib/aws-sdk-core/rest/response/body.rb +2 -0
  106. data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
  107. data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
  108. data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
  109. data/lib/aws-sdk-core/rest.rb +2 -0
  110. data/lib/aws-sdk-core/shared_config.rb +62 -8
  111. data/lib/aws-sdk-core/shared_credentials.rb +9 -1
  112. data/lib/aws-sdk-core/sso_credentials.rb +137 -0
  113. data/lib/aws-sdk-core/structure.rb +13 -2
  114. data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
  115. data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
  116. data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
  117. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
  118. data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
  119. data/lib/aws-sdk-core/stubbing/protocols/query.rb +2 -0
  120. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +3 -1
  121. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
  122. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
  123. data/lib/aws-sdk-core/stubbing/stub_data.rb +2 -0
  124. data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
  125. data/lib/aws-sdk-core/type_builder.rb +2 -0
  126. data/lib/aws-sdk-core/util.rb +2 -0
  127. data/lib/aws-sdk-core/waiters/errors.rb +2 -0
  128. data/lib/aws-sdk-core/waiters/poller.rb +2 -0
  129. data/lib/aws-sdk-core/waiters/waiter.rb +2 -0
  130. data/lib/aws-sdk-core/waiters.rb +2 -0
  131. data/lib/aws-sdk-core/xml/builder.rb +4 -2
  132. data/lib/aws-sdk-core/xml/default_list.rb +2 -0
  133. data/lib/aws-sdk-core/xml/default_map.rb +2 -0
  134. data/lib/aws-sdk-core/xml/doc_builder.rb +8 -1
  135. data/lib/aws-sdk-core/xml/error_handler.rb +2 -0
  136. data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
  137. data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
  138. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  139. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
  140. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +2 -0
  141. data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
  142. data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
  143. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  144. data/lib/aws-sdk-core/xml/parser.rb +7 -0
  145. data/lib/aws-sdk-core/xml.rb +2 -0
  146. data/lib/aws-sdk-core.rb +15 -3
  147. data/lib/aws-sdk-sso/client.rb +570 -0
  148. data/lib/aws-sdk-sso/client_api.rb +190 -0
  149. data/lib/aws-sdk-sso/customizations.rb +1 -0
  150. data/lib/aws-sdk-sso/errors.rb +102 -0
  151. data/lib/aws-sdk-sso/resource.rb +26 -0
  152. data/lib/aws-sdk-sso/types.rb +352 -0
  153. data/lib/aws-sdk-sso.rb +55 -0
  154. data/lib/aws-sdk-sts/client.rb +538 -435
  155. data/lib/aws-sdk-sts/client_api.rb +9 -1
  156. data/lib/aws-sdk-sts/customizations.rb +2 -0
  157. data/lib/aws-sdk-sts/errors.rb +3 -1
  158. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +7 -1
  159. data/lib/aws-sdk-sts/presigner.rb +9 -1
  160. data/lib/aws-sdk-sts/resource.rb +3 -1
  161. data/lib/aws-sdk-sts/types.rb +360 -191
  162. data/lib/aws-sdk-sts.rb +10 -3
  163. data/lib/seahorse/client/async_base.rb +2 -0
  164. data/lib/seahorse/client/async_response.rb +2 -0
  165. data/lib/seahorse/client/base.rb +3 -0
  166. data/lib/seahorse/client/block_io.rb +5 -2
  167. data/lib/seahorse/client/configuration.rb +6 -0
  168. data/lib/seahorse/client/events.rb +2 -0
  169. data/lib/seahorse/client/h2/connection.rb +17 -13
  170. data/lib/seahorse/client/h2/handler.rb +6 -5
  171. data/lib/seahorse/client/handler.rb +2 -0
  172. data/lib/seahorse/client/handler_builder.rb +2 -0
  173. data/lib/seahorse/client/handler_list.rb +2 -0
  174. data/lib/seahorse/client/handler_list_entry.rb +2 -0
  175. data/lib/seahorse/client/http/async_response.rb +2 -0
  176. data/lib/seahorse/client/http/headers.rb +2 -0
  177. data/lib/seahorse/client/http/request.rb +2 -0
  178. data/lib/seahorse/client/http/response.rb +3 -1
  179. data/lib/seahorse/client/logging/formatter.rb +2 -0
  180. data/lib/seahorse/client/logging/handler.rb +2 -0
  181. data/lib/seahorse/client/managed_file.rb +2 -0
  182. data/lib/seahorse/client/net_http/connection_pool.rb +12 -4
  183. data/lib/seahorse/client/net_http/handler.rb +19 -8
  184. data/lib/seahorse/client/net_http/patches.rb +15 -84
  185. data/lib/seahorse/client/networking_error.rb +2 -0
  186. data/lib/seahorse/client/plugin.rb +2 -0
  187. data/lib/seahorse/client/plugin_list.rb +2 -0
  188. data/lib/seahorse/client/plugins/content_length.rb +13 -5
  189. data/lib/seahorse/client/plugins/endpoint.rb +2 -0
  190. data/lib/seahorse/client/plugins/h2.rb +6 -1
  191. data/lib/seahorse/client/plugins/logging.rb +2 -0
  192. data/lib/seahorse/client/plugins/net_http.rb +39 -3
  193. data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
  194. data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
  195. data/lib/seahorse/client/plugins/request_callback.rb +110 -0
  196. data/lib/seahorse/client/plugins/response_target.rb +8 -8
  197. data/lib/seahorse/client/request.rb +2 -0
  198. data/lib/seahorse/client/request_context.rb +2 -0
  199. data/lib/seahorse/client/response.rb +2 -0
  200. data/lib/seahorse/model/api.rb +2 -0
  201. data/lib/seahorse/model/authorizer.rb +2 -0
  202. data/lib/seahorse/model/operation.rb +5 -0
  203. data/lib/seahorse/model/shapes.rb +27 -0
  204. data/lib/seahorse/util.rb +8 -1
  205. data/lib/seahorse/version.rb +2 -0
  206. data/lib/seahorse.rb +3 -0
  207. metadata +26 -9
@@ -0,0 +1,27 @@
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-amz-trace-id')
13
+ if ENV['AWS_LAMBDA_FUNCTION_NAME'] &&
14
+ (trace_id = ENV['_X_AMZ_TRACE_ID'])
15
+ context.http_request.headers['x-amz-trace-id'] = trace_id
16
+ end
17
+ end
18
+ @handler.call(context)
19
+ end
20
+ end
21
+
22
+ # should be at the end of build so that
23
+ # modeled traits / service customizations apply first
24
+ handler(Handler, step: :build, order: 99)
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -22,6 +24,25 @@ a default `:region` is searched for in the following locations:
22
24
  resolve_region(cfg)
23
25
  end
24
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
+
25
46
  option(:regional_endpoint, false)
26
47
 
27
48
  option(:endpoint, doc_type: String, docstring: <<-DOCS) do |cfg|
@@ -36,14 +57,27 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
36
57
  end
37
58
 
38
59
  # check region is a valid RFC host label
39
- unless cfg.region =~ /^(?![0-9]+$)(?!-)[a-zA-Z0-9-]{,63}(?<!-)$/
60
+ unless Seahorse::Util.host_label?(cfg.region)
40
61
  raise Errors::InvalidRegionError
41
62
  end
42
63
 
64
+ region = cfg.region
65
+ new_region = region.gsub('fips-', '').gsub('-fips', '')
66
+ if region != new_region
67
+ warn("Legacy region #{region} was transformed to #{new_region}."\
68
+ '`use_fips_endpoint` config was set to true.')
69
+ cfg.override_config(:use_fips_endpoint, true)
70
+ cfg.override_config(:region, new_region)
71
+ end
72
+
43
73
  Aws::Partitions::EndpointProvider.resolve(
44
74
  cfg.region,
45
75
  endpoint_prefix,
46
- sts_regional
76
+ sts_regional,
77
+ {
78
+ dualstack: cfg.use_dualstack_endpoint,
79
+ fips: cfg.use_fips_endpoint
80
+ }
47
81
  )
48
82
  end
49
83
  end
@@ -64,6 +98,20 @@ to test or custom endpoints. This should be a valid HTTP(S) URI.
64
98
  cfg_region = Aws.shared_config.region(profile: cfg.profile)
65
99
  env_region || cfg_region
66
100
  end
101
+
102
+ def resolve_use_dualstack_endpoint(cfg)
103
+ value = ENV['AWS_USE_DUALSTACK_ENDPOINT']
104
+ value ||= Aws.shared_config.use_dualstack_endpoint(
105
+ profile: cfg.profile
106
+ )
107
+ Aws::Util.str_2_bool(value) || false
108
+ end
109
+
110
+ def resolve_use_fips_endpoint(cfg)
111
+ value = ENV['AWS_USE_FIPS_ENDPOINT']
112
+ value ||= Aws.shared_config.use_fips_endpoint(profile: cfg.profile)
113
+ Aws::Util.str_2_bool(value) || false
114
+ end
67
115
  end
68
116
  end
69
117
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -8,7 +10,7 @@ module Aws
8
10
  def call(context)
9
11
  context[:original_params] = context.params
10
12
  resp = @handler.call(context)
11
- resp.extend(PageableResponse)
13
+ PageableResponse.apply(resp)
12
14
  resp.pager = context.operation[:pager] || Aws::Pager::NullPager.new
13
15
  resp
14
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  module Retries
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  module Retries
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  module Retries
@@ -11,7 +13,8 @@ module Aws
11
13
  'InvalidAccessKeyId', # s3
12
14
  'AuthFailure', # ec2
13
15
  'InvalidIdentityToken', # sts
14
- 'ExpiredToken' # route53
16
+ 'ExpiredToken', # route53
17
+ 'ExpiredTokenException' # kinesis
15
18
  ]
16
19
  )
17
20
 
@@ -43,6 +46,7 @@ module Aws
43
46
  NETWORKING_ERRORS = Set.new(
44
47
  [
45
48
  'RequestTimeout', # s3
49
+ 'InternalError', # s3
46
50
  'RequestTimeoutException', # glacier
47
51
  'IDPCommunicationError' # sts
48
52
  ]
@@ -78,7 +82,7 @@ module Aws
78
82
  end
79
83
 
80
84
  def checksum?
81
- CHECKSUM_ERRORS.include?(@name) || @error.is_a?(Errors::ChecksumError)
85
+ CHECKSUM_ERRORS.include?(@name)
82
86
  end
83
87
 
84
88
  def networking?
@@ -139,4 +143,4 @@ module Aws
139
143
  end
140
144
  end
141
145
  end
142
- end
146
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  module Retries
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'set'
2
4
  require_relative 'retries/error_inspector'
3
5
  require_relative 'retries/retry_quota'
@@ -161,9 +163,15 @@ a clock skew correction and retry requests with skewed client clocks.
161
163
  option(:clock_skew) { Retries::ClockSkew.new }
162
164
 
163
165
  def self.resolve_retry_mode(cfg)
164
- value = ENV['AWS_RETRY_MODE'] ||
165
- Aws.shared_config.retry_mode(profile: cfg.profile) ||
166
- 'legacy'
166
+ default_mode_value =
167
+ if cfg.respond_to?(:defaults_mode_config_resolver)
168
+ cfg.defaults_mode_config_resolver.resolve(:retry_mode)
169
+ end
170
+
171
+ value = ENV['AWS_RETRY_MODE'] ||
172
+ Aws.shared_config.retry_mode(profile: cfg.profile) ||
173
+ default_mode_value ||
174
+ 'legacy'
167
175
  # Raise if provided value is not one of the retry modes
168
176
  if value != 'legacy' && value != 'standard' && value != 'adaptive'
169
177
  raise ArgumentError,
@@ -174,11 +182,12 @@ a clock skew correction and retry requests with skewed client clocks.
174
182
  end
175
183
 
176
184
  def self.resolve_max_attempts(cfg)
177
- value = (ENV['AWS_MAX_ATTEMPTS'] && ENV['AWS_MAX_ATTEMPTS'].to_i) ||
185
+ value = (ENV['AWS_MAX_ATTEMPTS']) ||
178
186
  Aws.shared_config.max_attempts(profile: cfg.profile) ||
179
- 3
187
+ '3'
188
+ value = value.to_i
180
189
  # Raise if provided value is not a positive integer
181
- if !value.is_a?(Integer) || value <= 0
190
+ if value <= 0
182
191
  raise ArgumentError,
183
192
  'Must provide a positive integer for max_attempts profile '\
184
193
  'option or for ENV[\'AWS_MAX_ATTEMPTS\']'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-sigv4'
2
4
 
3
5
  module Aws
@@ -10,32 +12,22 @@ module Aws
10
12
  end
11
13
 
12
14
  option(:sigv4_name) do |cfg|
13
- cfg.api.metadata['signingName'] || cfg.api.metadata['endpointPrefix']
15
+ signingName = if cfg.region
16
+ Aws::Partitions::EndpointProvider.signing_service(
17
+ cfg.region, cfg.api.metadata['endpointPrefix']
18
+ )
19
+ end
20
+ signingName || cfg.api.metadata['signingName'] || cfg.api.metadata['endpointPrefix']
14
21
  end
15
22
 
16
23
  option(:sigv4_region) do |cfg|
17
-
18
- # The signature version 4 signing region is most
19
- # commonly the configured region. There are a few
20
- # notable exceptions:
21
- #
22
- # * Some services have a global endpoint to the entire
23
- # partition. For example, when constructing a route53
24
- # client for a region like "us-west-2", we will
25
- # always use "route53.amazonaws.com". This endpoint
26
- # is actually global to the entire partition,
27
- # and must be signed as "us-east-1".
28
- #
29
- # * When the region is configured, but it is configured
30
- # to a non region, such as "aws-global". This is similar
31
- # to the previous case. We use the Aws::Partitions::EndpointProvider
32
- # to resolve to the actual signing region.
33
- #
34
- prefix = cfg.api.metadata['endpointPrefix']
35
- if prefix && cfg.endpoint.to_s.match(/#{prefix}\.amazonaws\.com/)
36
- 'us-east-1'
37
- elsif cfg.region
38
- Aws::Partitions::EndpointProvider.signing_region(cfg.region, cfg.sigv4_name)
24
+ if cfg.region
25
+ if cfg.respond_to?(:sts_regional_endpoints)
26
+ sts_regional = cfg.sts_regional_endpoints
27
+ end
28
+ Aws::Partitions::EndpointProvider.signing_region(
29
+ cfg.region, cfg.api.metadata['endpointPrefix'], sts_regional
30
+ )
39
31
  end
40
32
  end
41
33
 
@@ -106,6 +98,7 @@ module Aws
106
98
  req.headers.delete('Authorization')
107
99
  req.headers.delete('X-Amz-Security-Token')
108
100
  req.headers.delete('X-Amz-Date')
101
+ req.headers.delete('x-Amz-Region-Set')
109
102
 
110
103
  if context.config.respond_to?(:clock_skew) &&
111
104
  context.config.clock_skew &&
@@ -142,7 +135,7 @@ module Aws
142
135
  def apply_authtype(context)
143
136
  if context.operation['authtype'].eql?('v4-unsigned-body') &&
144
137
  context.http_request.endpoint.scheme.eql?('https')
145
- context.http_request.headers['X-Amz-Content-Sha256'] = 'UNSIGNED-PAYLOAD'
138
+ context.http_request.headers['X-Amz-Content-Sha256'] ||= 'UNSIGNED-PAYLOAD'
146
139
  end
147
140
  context
148
141
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -38,6 +40,8 @@ requests are made, and retries are disabled.
38
40
  client.handlers.remove(ClientMetricsPlugin::Handler)
39
41
  client.handlers.remove(ClientMetricsSendPlugin::LatencyHandler)
40
42
  client.handlers.remove(ClientMetricsSendPlugin::AttemptHandler)
43
+ client.handlers.remove(Seahorse::Client::Plugins::RequestCallback::OptionHandler)
44
+ client.handlers.remove(Seahorse::Client::Plugins::RequestCallback::ReadCallbackHandler)
41
45
  end
42
46
  end
43
47
 
@@ -47,7 +51,11 @@ requests are made, and retries are disabled.
47
51
  stub = context.client.next_stub(context)
48
52
  resp = Seahorse::Client::Response.new(context: context)
49
53
  async_mode = context.client.is_a? Seahorse::Client::AsyncBase
50
- apply_stub(stub, resp, async_mode)
54
+ if Hash === stub && stub[:mutex]
55
+ stub[:mutex].synchronize { apply_stub(stub, resp, async_mode) }
56
+ else
57
+ apply_stub(stub, resp, async_mode)
58
+ end
51
59
 
52
60
  async_mode ? Seahorse::Client::AsyncResponse.new(
53
61
  context: context, stream: context[:input_event_stream_handler].event_emitter.stream, sync_queue: Queue.new) : resp
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Plugins
3
5
  # @api private
@@ -1,4 +1,4 @@
1
- require 'open3'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Aws
4
4
 
@@ -27,6 +27,7 @@ module Aws
27
27
  def initialize(process)
28
28
  @process = process
29
29
  @credentials = credentials_from_process(@process)
30
+ @async_refresh = false
30
31
 
31
32
  super
32
33
  end
@@ -34,15 +35,16 @@ module Aws
34
35
  private
35
36
  def credentials_from_process(proc_invocation)
36
37
  begin
37
- raw_out, process_status = Open3.capture2(proc_invocation)
38
+ raw_out = `#{proc_invocation}`
39
+ process_status = $?
38
40
  rescue Errno::ENOENT
39
41
  raise Errors::InvalidProcessCredentialsPayload.new("Could not find process #{proc_invocation}")
40
42
  end
41
43
 
42
44
  if process_status.success?
43
45
  begin
44
- creds_json = JSON.parse(raw_out)
45
- rescue JSON::ParserError
46
+ creds_json = Aws::Json.load(raw_out)
47
+ rescue Aws::Json::ParseError
46
48
  raise Errors::InvalidProcessCredentialsPayload.new("Invalid JSON response")
47
49
  end
48
50
  payload_version = creds_json['Version']
@@ -72,9 +74,9 @@ module Aws
72
74
  @credentials = credentials_from_process(@process)
73
75
  end
74
76
 
75
- def near_expiration?
77
+ def near_expiration?(expiration_length)
76
78
  # are we within 5 minutes of expiration?
77
- @expiration && (Time.now.to_i + 5 * 60) > @expiration.to_i
79
+ @expiration && (Time.now.to_i + expiration_length) > @expiration.to_i
78
80
  end
79
81
  end
80
82
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  module Query
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Query
3
5
  class Param
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stringio'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'query/ec2_param_builder'
2
4
  require_relative 'query/handler'
3
5
  require_relative 'query/param'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thread'
2
4
 
3
5
  module Aws
@@ -15,45 +17,74 @@ module Aws
15
17
  # @api private
16
18
  module RefreshingCredentials
17
19
 
20
+ SYNC_EXPIRATION_LENGTH = 300 # 5 minutes
21
+ ASYNC_EXPIRATION_LENGTH = 600 # 10 minutes
22
+
18
23
  def initialize(options = {})
19
24
  @mutex = Mutex.new
25
+ @before_refresh = options.delete(:before_refresh) if Hash === options
26
+
27
+ @before_refresh.call(self) if @before_refresh
20
28
  refresh
21
29
  end
22
30
 
23
31
  # @return [Credentials]
24
32
  def credentials
25
- refresh_if_near_expiration
33
+ refresh_if_near_expiration!
26
34
  @credentials
27
35
  end
28
36
 
29
37
  # @return [Time,nil]
30
38
  def expiration
31
- refresh_if_near_expiration
39
+ refresh_if_near_expiration!
32
40
  @expiration
33
41
  end
34
42
 
35
43
  # Refresh credentials.
36
44
  # @return [void]
37
45
  def refresh!
38
- @mutex.synchronize { refresh }
46
+ @mutex.synchronize do
47
+ @before_refresh.call(self) if @before_refresh
48
+
49
+ refresh
50
+ end
39
51
  end
40
52
 
41
53
  private
42
54
 
43
- # Refreshes instance metadata credentials if they are within
44
- # 5 minutes of expiration.
45
- def refresh_if_near_expiration
46
- if near_expiration?
55
+ # Refreshes credentials asynchronously and synchronously.
56
+ # If we are near to expiration, block while getting new credentials.
57
+ # Otherwise, if we're approaching expiration, use the existing credentials
58
+ # but attempt a refresh in the background.
59
+ def refresh_if_near_expiration!
60
+ # Note: This check is an optimization. Rather than acquire the mutex on every #refresh_if_near_expiration
61
+ # call, we check before doing so, and then we check within the mutex to avoid a race condition.
62
+ # See issue: https://github.com/aws/aws-sdk-ruby/issues/2641 for more info.
63
+ if near_expiration?(SYNC_EXPIRATION_LENGTH)
47
64
  @mutex.synchronize do
48
- refresh if near_expiration?
65
+ if near_expiration?(SYNC_EXPIRATION_LENGTH)
66
+ @before_refresh.call(self) if @before_refresh
67
+ refresh
68
+ end
69
+ end
70
+ elsif @async_refresh && near_expiration?(ASYNC_EXPIRATION_LENGTH)
71
+ unless @mutex.locked?
72
+ Thread.new do
73
+ @mutex.synchronize do
74
+ if near_expiration?(ASYNC_EXPIRATION_LENGTH)
75
+ @before_refresh.call(self) if @before_refresh
76
+ refresh
77
+ end
78
+ end
79
+ end
49
80
  end
50
81
  end
51
82
  end
52
83
 
53
- def near_expiration?
84
+ def near_expiration?(expiration_length)
54
85
  if @expiration
55
- # are we within 5 minutes of expiration?
56
- (Time.now.to_i + 5 * 60) > @expiration.to_i
86
+ # Are we within expiration?
87
+ (Time.now.to_i + expiration_length) > @expiration.to_i
57
88
  else
58
89
  true
59
90
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Resources
3
5
  class Collection
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  module Rest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Rest
3
5
  module Request
@@ -15,11 +17,29 @@ module Aws
15
17
  # @param [Seahorse::Client::Http::Request] http_req
16
18
  # @param [Hash] params
17
19
  def apply(http_req, params)
18
- http_req.body = build_body(params)
20
+ body = build_body(params)
21
+ # for rest-json, ensure we send at least an empty object
22
+ # don't send an empty object for streaming? case.
23
+ if body.nil? && @serializer_class == Json::Builder &&
24
+ modeled_body? && !streaming?
25
+ body = '{}'
26
+ end
27
+ http_req.body = body
19
28
  end
20
29
 
21
30
  private
22
31
 
32
+ # operation is modeled for body when it is modeled for a payload
33
+ # either with payload trait or normal members.
34
+ def modeled_body?
35
+ return true if @rules[:payload]
36
+ @rules.shape.members.each do |member|
37
+ _name, shape = member
38
+ return true if shape.location.nil?
39
+ end
40
+ false
41
+ end
42
+
23
43
  def build_body(params)
24
44
  if streaming?
25
45
  params[@rules[:payload]]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Rest
3
5
  module Request
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'uri'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
  require 'base64'
3
5
 
@@ -30,11 +32,11 @@ module Aws
30
32
 
31
33
  def apply_header_value(headers, ref, value)
32
34
  value = apply_json_trait(value) if ref['jsonvalue']
33
- headers[ref.location_name] =
34
- case ref.shape
35
- when TimestampShape then timestamp(ref, value)
36
- else value.to_s
37
- end
35
+ case ref.shape
36
+ when TimestampShape then headers[ref.location_name] = timestamp(ref, value)
37
+ when ListShape then list(headers, ref, value)
38
+ else headers[ref.location_name] = value.to_s
39
+ end
38
40
  end
39
41
 
40
42
  def timestamp(ref, value)
@@ -47,6 +49,18 @@ module Aws
47
49
  end
48
50
  end
49
51
 
52
+ def list(headers, ref, value)
53
+ return if !value || value.empty?
54
+ headers[ref.location_name] = value
55
+ .compact
56
+ .map { |s| escape_header_list_string(s.to_s) }
57
+ .join(",")
58
+ end
59
+
60
+ def escape_header_list_string(s)
61
+ (s.include?('"') || s.include?(",")) ? "\"#{s.gsub('"', '\"')}\"" : s
62
+ end
63
+
50
64
  def apply_header_map(headers, ref, values)
51
65
  prefix = ref.location_name || ''
52
66
  values.each_pair do |name, value|
@@ -55,7 +69,7 @@ module Aws
55
69
  end
56
70
 
57
71
  # With complex headers value in json syntax,
58
- # base64 encodes value to aviod weird characters
72
+ # base64 encodes value to avoid weird characters
59
73
  # causing potential issues in headers
60
74
  def apply_json_trait(value)
61
75
  Base64.strict_encode64(value)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Rest
3
5
  module Request
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Rest
3
5
  module Response