aws-sdk-core 3.100.0 → 3.191.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1815 -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 +28 -0
  9. data/lib/aws-sdk-core/arn_parser.rb +2 -0
  10. data/lib/aws-sdk-core/assume_role_credentials.rb +23 -7
  11. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +16 -10
  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 +14 -1
  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 +22 -13
  23. data/lib/aws-sdk-core/credential_provider.rb +5 -0
  24. data/lib/aws-sdk-core/credential_provider_chain.rb +31 -6
  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 +188 -53
  30. data/lib/aws-sdk-core/endpoint_cache.rb +2 -0
  31. data/lib/aws-sdk-core/endpoints/condition.rb +41 -0
  32. data/lib/aws-sdk-core/endpoints/endpoint.rb +17 -0
  33. data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +75 -0
  34. data/lib/aws-sdk-core/endpoints/error_rule.rb +42 -0
  35. data/lib/aws-sdk-core/endpoints/function.rb +80 -0
  36. data/lib/aws-sdk-core/endpoints/matchers.rb +131 -0
  37. data/lib/aws-sdk-core/endpoints/reference.rb +31 -0
  38. data/lib/aws-sdk-core/endpoints/rule.rb +25 -0
  39. data/lib/aws-sdk-core/endpoints/rule_set.rb +52 -0
  40. data/lib/aws-sdk-core/endpoints/rules_provider.rb +37 -0
  41. data/lib/aws-sdk-core/endpoints/templater.rb +58 -0
  42. data/lib/aws-sdk-core/endpoints/tree_rule.rb +45 -0
  43. data/lib/aws-sdk-core/endpoints/url.rb +60 -0
  44. data/lib/aws-sdk-core/endpoints.rb +78 -0
  45. data/lib/aws-sdk-core/errors.rb +27 -5
  46. data/lib/aws-sdk-core/event_emitter.rb +2 -0
  47. data/lib/aws-sdk-core/ini_parser.rb +9 -0
  48. data/lib/aws-sdk-core/instance_profile_credentials.rb +167 -38
  49. data/lib/aws-sdk-core/json/builder.rb +2 -0
  50. data/lib/aws-sdk-core/json/error_handler.rb +22 -1
  51. data/lib/aws-sdk-core/json/handler.rb +10 -1
  52. data/lib/aws-sdk-core/json/json_engine.rb +12 -8
  53. data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
  54. data/lib/aws-sdk-core/json/parser.rb +36 -1
  55. data/lib/aws-sdk-core/json.rb +10 -26
  56. data/lib/aws-sdk-core/log/formatter.rb +15 -3
  57. data/lib/aws-sdk-core/log/handler.rb +2 -0
  58. data/lib/aws-sdk-core/log/param_filter.rb +37 -12
  59. data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
  60. data/lib/aws-sdk-core/pageable_response.rb +91 -32
  61. data/lib/aws-sdk-core/pager.rb +5 -0
  62. data/lib/aws-sdk-core/param_converter.rb +2 -0
  63. data/lib/aws-sdk-core/param_validator.rb +56 -6
  64. data/lib/aws-sdk-core/plugins/api_key.rb +5 -1
  65. data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +2 -0
  66. data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +2 -0
  67. data/lib/aws-sdk-core/plugins/apig_user_agent.rb +2 -0
  68. data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
  69. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +342 -0
  70. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +3 -0
  71. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
  72. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +52 -7
  73. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  74. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +8 -2
  75. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
  76. data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +2 -0
  77. data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
  78. data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
  79. data/lib/aws-sdk-core/plugins/http_checksum.rb +11 -1
  80. data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
  81. data/lib/aws-sdk-core/plugins/invocation_id.rb +2 -0
  82. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +36 -6
  83. data/lib/aws-sdk-core/plugins/logging.rb +4 -0
  84. data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
  85. data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
  86. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
  87. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
  88. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
  89. data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
  90. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
  91. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
  92. data/lib/aws-sdk-core/plugins/recursion_detection.rb +38 -0
  93. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +146 -17
  94. data/lib/aws-sdk-core/plugins/request_compression.rb +217 -0
  95. data/lib/aws-sdk-core/plugins/response_paging.rb +3 -1
  96. data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +2 -0
  97. data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +2 -0
  98. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +9 -4
  99. data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +2 -0
  100. data/lib/aws-sdk-core/plugins/retry_errors.rb +29 -8
  101. data/lib/aws-sdk-core/plugins/sign.rb +206 -0
  102. data/lib/aws-sdk-core/plugins/signature_v2.rb +3 -0
  103. data/lib/aws-sdk-core/plugins/signature_v4.rb +30 -31
  104. data/lib/aws-sdk-core/plugins/stub_responses.rb +10 -1
  105. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +2 -0
  106. data/lib/aws-sdk-core/plugins/user_agent.rb +119 -14
  107. data/lib/aws-sdk-core/process_credentials.rb +14 -15
  108. data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
  109. data/lib/aws-sdk-core/query/handler.rb +2 -0
  110. data/lib/aws-sdk-core/query/param.rb +2 -0
  111. data/lib/aws-sdk-core/query/param_builder.rb +2 -0
  112. data/lib/aws-sdk-core/query/param_list.rb +2 -0
  113. data/lib/aws-sdk-core/query.rb +2 -0
  114. data/lib/aws-sdk-core/refreshing_credentials.rb +50 -17
  115. data/lib/aws-sdk-core/refreshing_token.rb +71 -0
  116. data/lib/aws-sdk-core/resources/collection.rb +2 -0
  117. data/lib/aws-sdk-core/rest/handler.rb +3 -1
  118. data/lib/aws-sdk-core/rest/request/body.rb +21 -1
  119. data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
  120. data/lib/aws-sdk-core/rest/request/endpoint.rb +2 -0
  121. data/lib/aws-sdk-core/rest/request/headers.rb +16 -6
  122. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +45 -29
  123. data/lib/aws-sdk-core/rest/response/body.rb +2 -0
  124. data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
  125. data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
  126. data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
  127. data/lib/aws-sdk-core/rest.rb +2 -0
  128. data/lib/aws-sdk-core/shared_config.rb +163 -8
  129. data/lib/aws-sdk-core/shared_credentials.rb +9 -1
  130. data/lib/aws-sdk-core/sso_credentials.rb +172 -0
  131. data/lib/aws-sdk-core/sso_token_provider.rb +135 -0
  132. data/lib/aws-sdk-core/static_token_provider.rb +14 -0
  133. data/lib/aws-sdk-core/structure.rb +19 -6
  134. data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
  135. data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
  136. data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
  137. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
  138. data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
  139. data/lib/aws-sdk-core/stubbing/protocols/query.rb +2 -0
  140. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +3 -1
  141. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
  142. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
  143. data/lib/aws-sdk-core/stubbing/stub_data.rb +13 -0
  144. data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
  145. data/lib/aws-sdk-core/token.rb +31 -0
  146. data/lib/aws-sdk-core/token_provider.rb +15 -0
  147. data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
  148. data/lib/aws-sdk-core/type_builder.rb +2 -0
  149. data/lib/aws-sdk-core/util.rb +2 -0
  150. data/lib/aws-sdk-core/waiters/errors.rb +2 -0
  151. data/lib/aws-sdk-core/waiters/poller.rb +6 -2
  152. data/lib/aws-sdk-core/waiters/waiter.rb +2 -0
  153. data/lib/aws-sdk-core/waiters.rb +2 -0
  154. data/lib/aws-sdk-core/xml/builder.rb +4 -2
  155. data/lib/aws-sdk-core/xml/default_list.rb +2 -0
  156. data/lib/aws-sdk-core/xml/default_map.rb +2 -0
  157. data/lib/aws-sdk-core/xml/doc_builder.rb +8 -1
  158. data/lib/aws-sdk-core/xml/error_handler.rb +9 -0
  159. data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
  160. data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
  161. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +4 -0
  162. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
  163. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +2 -0
  164. data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
  165. data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
  166. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  167. data/lib/aws-sdk-core/xml/parser.rb +7 -0
  168. data/lib/aws-sdk-core/xml.rb +2 -0
  169. data/lib/aws-sdk-core.rb +29 -3
  170. data/lib/aws-sdk-sso/client.rb +630 -0
  171. data/lib/aws-sdk-sso/client_api.rb +190 -0
  172. data/lib/aws-sdk-sso/customizations.rb +1 -0
  173. data/lib/aws-sdk-sso/endpoint_parameters.rb +66 -0
  174. data/lib/aws-sdk-sso/endpoint_provider.rb +57 -0
  175. data/lib/aws-sdk-sso/endpoints.rb +72 -0
  176. data/lib/aws-sdk-sso/errors.rb +102 -0
  177. data/lib/aws-sdk-sso/plugins/endpoints.rb +78 -0
  178. data/lib/aws-sdk-sso/resource.rb +26 -0
  179. data/lib/aws-sdk-sso/types.rb +317 -0
  180. data/lib/aws-sdk-sso.rb +59 -0
  181. data/lib/aws-sdk-ssooidc/client.rb +935 -0
  182. data/lib/aws-sdk-ssooidc/client_api.rb +271 -0
  183. data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
  184. data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +66 -0
  185. data/lib/aws-sdk-ssooidc/endpoint_provider.rb +57 -0
  186. data/lib/aws-sdk-ssooidc/endpoints.rb +72 -0
  187. data/lib/aws-sdk-ssooidc/errors.rb +321 -0
  188. data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +78 -0
  189. data/lib/aws-sdk-ssooidc/resource.rb +26 -0
  190. data/lib/aws-sdk-ssooidc/types.rb +755 -0
  191. data/lib/aws-sdk-ssooidc.rb +59 -0
  192. data/lib/aws-sdk-sts/client.rb +655 -490
  193. data/lib/aws-sdk-sts/client_api.rb +21 -2
  194. data/lib/aws-sdk-sts/customizations.rb +2 -0
  195. data/lib/aws-sdk-sts/endpoint_parameters.rb +78 -0
  196. data/lib/aws-sdk-sts/endpoint_provider.rb +112 -0
  197. data/lib/aws-sdk-sts/endpoints.rb +136 -0
  198. data/lib/aws-sdk-sts/errors.rb +3 -1
  199. data/lib/aws-sdk-sts/plugins/endpoints.rb +86 -0
  200. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +7 -1
  201. data/lib/aws-sdk-sts/presigner.rb +16 -10
  202. data/lib/aws-sdk-sts/resource.rb +3 -1
  203. data/lib/aws-sdk-sts/types.rb +416 -316
  204. data/lib/aws-sdk-sts.rb +14 -3
  205. data/lib/seahorse/client/async_base.rb +2 -1
  206. data/lib/seahorse/client/async_response.rb +2 -0
  207. data/lib/seahorse/client/base.rb +3 -0
  208. data/lib/seahorse/client/block_io.rb +5 -2
  209. data/lib/seahorse/client/configuration.rb +7 -5
  210. data/lib/seahorse/client/events.rb +2 -0
  211. data/lib/seahorse/client/h2/connection.rb +29 -24
  212. data/lib/seahorse/client/h2/handler.rb +6 -5
  213. data/lib/seahorse/client/handler.rb +2 -0
  214. data/lib/seahorse/client/handler_builder.rb +2 -0
  215. data/lib/seahorse/client/handler_list.rb +2 -0
  216. data/lib/seahorse/client/handler_list_entry.rb +2 -0
  217. data/lib/seahorse/client/http/async_response.rb +2 -0
  218. data/lib/seahorse/client/http/headers.rb +2 -0
  219. data/lib/seahorse/client/http/request.rb +2 -0
  220. data/lib/seahorse/client/http/response.rb +3 -1
  221. data/lib/seahorse/client/logging/formatter.rb +2 -0
  222. data/lib/seahorse/client/logging/handler.rb +2 -0
  223. data/lib/seahorse/client/managed_file.rb +2 -0
  224. data/lib/seahorse/client/net_http/connection_pool.rb +12 -4
  225. data/lib/seahorse/client/net_http/handler.rb +19 -8
  226. data/lib/seahorse/client/net_http/patches.rb +14 -86
  227. data/lib/seahorse/client/networking_error.rb +2 -0
  228. data/lib/seahorse/client/plugin.rb +3 -0
  229. data/lib/seahorse/client/plugin_list.rb +2 -0
  230. data/lib/seahorse/client/plugins/content_length.rb +13 -5
  231. data/lib/seahorse/client/plugins/endpoint.rb +2 -0
  232. data/lib/seahorse/client/plugins/h2.rb +9 -4
  233. data/lib/seahorse/client/plugins/logging.rb +2 -0
  234. data/lib/seahorse/client/plugins/net_http.rb +39 -3
  235. data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
  236. data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
  237. data/lib/seahorse/client/plugins/request_callback.rb +141 -0
  238. data/lib/seahorse/client/plugins/response_target.rb +8 -8
  239. data/lib/seahorse/client/request.rb +2 -0
  240. data/lib/seahorse/client/request_context.rb +2 -0
  241. data/lib/seahorse/client/response.rb +8 -0
  242. data/lib/seahorse/model/api.rb +2 -0
  243. data/lib/seahorse/model/authorizer.rb +2 -0
  244. data/lib/seahorse/model/operation.rb +8 -0
  245. data/lib/seahorse/model/shapes.rb +27 -0
  246. data/lib/seahorse/util.rb +12 -1
  247. data/lib/seahorse/version.rb +2 -0
  248. data/lib/seahorse.rb +3 -0
  249. data/sig/aws-sdk-core/client_stubs.rbs +10 -0
  250. data/sig/aws-sdk-core/errors.rbs +22 -0
  251. data/sig/aws-sdk-core/resources/collection.rbs +21 -0
  252. data/sig/aws-sdk-core/structure.rbs +4 -0
  253. data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
  254. data/sig/aws-sdk-core.rbs +7 -0
  255. data/sig/seahorse/client/base.rbs +25 -0
  256. data/sig/seahorse/client/handler_builder.rbs +16 -0
  257. data/sig/seahorse/client/response.rbs +61 -0
  258. metadata +93 -19
@@ -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,4 +1,4 @@
1
- require 'thread'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Aws
4
4
 
@@ -15,45 +15,78 @@ module Aws
15
15
  # @api private
16
16
  module RefreshingCredentials
17
17
 
18
+ SYNC_EXPIRATION_LENGTH = 300 # 5 minutes
19
+ ASYNC_EXPIRATION_LENGTH = 600 # 10 minutes
20
+
21
+ CLIENT_EXCLUDE_OPTIONS = Set.new([:before_refresh]).freeze
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
- # @return [Time,nil]
30
- def expiration
31
- refresh_if_near_expiration
32
- @expiration
33
- end
34
-
35
37
  # Refresh credentials.
36
38
  # @return [void]
37
39
  def refresh!
38
- @mutex.synchronize { refresh }
40
+ @mutex.synchronize do
41
+ @before_refresh.call(self) if @before_refresh
42
+
43
+ refresh
44
+ end
39
45
  end
40
46
 
41
47
  private
42
48
 
43
- # Refreshes instance metadata credentials if they are within
44
- # 5 minutes of expiration.
45
- def refresh_if_near_expiration
46
- if near_expiration?
49
+ def sync_expiration_length
50
+ self.class::SYNC_EXPIRATION_LENGTH
51
+ end
52
+
53
+ def async_expiration_length
54
+ self.class::ASYNC_EXPIRATION_LENGTH
55
+ end
56
+
57
+ # Refreshes credentials asynchronously and synchronously.
58
+ # If we are near to expiration, block while getting new credentials.
59
+ # Otherwise, if we're approaching expiration, use the existing credentials
60
+ # but attempt a refresh in the background.
61
+ def refresh_if_near_expiration!
62
+ # Note: This check is an optimization. Rather than acquire the mutex on every #refresh_if_near_expiration
63
+ # call, we check before doing so, and then we check within the mutex to avoid a race condition.
64
+ # See issue: https://github.com/aws/aws-sdk-ruby/issues/2641 for more info.
65
+ if near_expiration?(sync_expiration_length)
47
66
  @mutex.synchronize do
48
- refresh if near_expiration?
67
+ if near_expiration?(sync_expiration_length)
68
+ @before_refresh.call(self) if @before_refresh
69
+ refresh
70
+ end
71
+ end
72
+ elsif @async_refresh && near_expiration?(async_expiration_length)
73
+ unless @mutex.locked?
74
+ Thread.new do
75
+ @mutex.synchronize do
76
+ if near_expiration?(async_expiration_length)
77
+ @before_refresh.call(self) if @before_refresh
78
+ refresh
79
+ end
80
+ end
81
+ end
49
82
  end
50
83
  end
51
84
  end
52
85
 
53
- def near_expiration?
86
+ def near_expiration?(expiration_length)
54
87
  if @expiration
55
- # are we within 5 minutes of expiration?
56
- (Time.now.to_i + 5 * 60) > @expiration.to_i
88
+ # Are we within expiration?
89
+ (Time.now.to_i + expiration_length) > @expiration.to_i
57
90
  else
58
91
  true
59
92
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thread'
4
+
5
+ module Aws
6
+
7
+ # Module/mixin used by token provider classes that can be refreshed. This
8
+ # provides basic refresh logic in a thread-safe manner. Classes mixing in
9
+ # this module are expected to implement a #refresh method that populates
10
+ # the following instance variable:
11
+ #
12
+ # * `@token` [Token] - {Aws::Token} object with the `expiration` and `token`
13
+ # fields set.
14
+ #
15
+ # @api private
16
+ module RefreshingToken
17
+
18
+ def initialize(options = {})
19
+ @mutex = Mutex.new
20
+ @before_refresh = options.delete(:before_refresh) if Hash === options
21
+
22
+ @before_refresh.call(self) if @before_refresh
23
+ refresh
24
+ end
25
+
26
+ # @return [Token]
27
+ def token
28
+ refresh_if_near_expiration
29
+ @token
30
+ end
31
+
32
+ # @return [Time,nil]
33
+ def expiration
34
+ refresh_if_near_expiration
35
+ @expiration
36
+ end
37
+
38
+ # Refresh token.
39
+ # @return [void]
40
+ def refresh!
41
+ @mutex.synchronize do
42
+ @before_refresh.call(self) if @before_refresh
43
+ refresh
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ # Refreshes token if it is within
50
+ # 5 minutes of expiration.
51
+ def refresh_if_near_expiration
52
+ if near_expiration?
53
+ @mutex.synchronize do
54
+ if near_expiration?
55
+ @before_refresh.call(self) if @before_refresh
56
+ refresh
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def near_expiration?
63
+ if @token && @token.expiration
64
+ # are we within 5 minutes of expiration?
65
+ (Time.now.to_i + 5 * 60) > @token.expiration.to_i
66
+ else
67
+ true
68
+ end
69
+ end
70
+ end
71
+ 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
@@ -15,7 +17,7 @@ module Aws
15
17
 
16
18
  def apply_request_id(context)
17
19
  h = context.http_response.headers
18
- context[:request_id] = h['x-amz-request-id'] || h['x-amzn-requestid']
20
+ context[:request_id] ||= h['x-amz-request-id'] || h['x-amzn-requestid']
19
21
  end
20
22
 
21
23
  end
@@ -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,14 @@ 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| Seahorse::Util.escape_header_list_string(s.to_s) }
57
+ .join(',')
58
+ end
59
+
50
60
  def apply_header_map(headers, ref, values)
51
61
  prefix = ref.location_name || ''
52
62
  values.each_pair do |name, value|
@@ -55,7 +65,7 @@ module Aws
55
65
  end
56
66
 
57
67
  # With complex headers value in json syntax,
58
- # base64 encodes value to aviod weird characters
68
+ # base64 encodes value to avoid weird characters
59
69
  # causing potential issues in headers
60
70
  def apply_json_trait(value)
61
71
  Base64.strict_encode64(value)
@@ -1,10 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Rest
3
5
  module Request
4
6
  class QuerystringBuilder
5
-
6
7
  include Seahorse::Model::Shapes
7
8
 
9
+ SUPPORTED_TYPES = [
10
+ BooleanShape,
11
+ FloatShape,
12
+ IntegerShape,
13
+ StringShape,
14
+ TimestampShape
15
+ ].freeze
16
+
8
17
  # Provide shape references and param values:
9
18
  #
10
19
  # [
@@ -31,29 +40,12 @@ module Aws
31
40
  def build_part(shape_ref, param_value)
32
41
  case shape_ref.shape
33
42
  # supported scalar types
34
- when StringShape, BooleanShape, FloatShape, IntegerShape, StringShape
35
- param_name = shape_ref.location_name
36
- "#{param_name}=#{escape(param_value.to_s)}"
37
- when TimestampShape
38
- param_name = shape_ref.location_name
39
- "#{param_name}=#{escape(timestamp(shape_ref, param_value))}"
43
+ when *SUPPORTED_TYPES
44
+ "#{shape_ref.location_name}=#{query_value(shape_ref, param_value)}"
40
45
  when MapShape
41
- if StringShape === shape_ref.shape.value.shape
42
- query_map_of_string(param_value)
43
- elsif ListShape === shape_ref.shape.value.shape
44
- query_map_of_string_list(param_value)
45
- else
46
- msg = "only map of string and string list supported"
47
- raise NotImplementedError, msg
48
- end
46
+ generate_query_map(shape_ref, param_value)
49
47
  when ListShape
50
- if StringShape === shape_ref.shape.member.shape
51
- list_of_strings(shape_ref.location_name, param_value)
52
- else
53
- msg = "Only list of strings supported, got "\
54
- "#{shape_ref.shape.member.shape.class.name}"
55
- raise NotImplementedError, msg
56
- end
48
+ generate_query_list(shape_ref, param_value)
57
49
  else
58
50
  raise NotImplementedError
59
51
  end
@@ -69,6 +61,37 @@ module Aws
69
61
  end
70
62
  end
71
63
 
64
+ def query_value(ref, value)
65
+ case ref.shape
66
+ when TimestampShape
67
+ escape(timestamp(ref, value))
68
+ when *SUPPORTED_TYPES
69
+ escape(value.to_s)
70
+ else
71
+ raise NotImplementedError
72
+ end
73
+ end
74
+
75
+ def generate_query_list(ref, values)
76
+ member_ref = ref.shape.member
77
+ values.map do |value|
78
+ value = query_value(member_ref, value)
79
+ "#{ref.location_name}=#{value}"
80
+ end
81
+ end
82
+
83
+ def generate_query_map(ref, value)
84
+ case ref.shape.value.shape
85
+ when StringShape
86
+ query_map_of_string(value)
87
+ when ListShape
88
+ query_map_of_string_list(value)
89
+ else
90
+ msg = 'Only map of string and string list supported'
91
+ raise NotImplementedError, msg
92
+ end
93
+ end
94
+
72
95
  def query_map_of_string(hash)
73
96
  list = []
74
97
  hash.each_pair do |key, value|
@@ -87,16 +110,9 @@ module Aws
87
110
  list
88
111
  end
89
112
 
90
- def list_of_strings(name, values)
91
- values.map do |value|
92
- "#{name}=#{escape(value)}"
93
- end
94
- end
95
-
96
113
  def escape(string)
97
114
  Seahorse::Util.uri_escape(string)
98
115
  end
99
-
100
116
  end
101
117
  end
102
118
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Rest
3
5
  module Response
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'time'
2
4
  require 'base64'
3
- require 'json'
4
5
 
5
6
  module Aws
6
7
  module Rest
@@ -39,8 +40,10 @@ module Aws
39
40
  when IntegerShape then value.to_i
40
41
  when FloatShape then value.to_f
41
42
  when BooleanShape then value == 'true'
43
+ when ListShape then
44
+ value.split(",").map { |v| cast_value(ref.shape.member, v) }
42
45
  when TimestampShape
43
- if value =~ /\d+(\.\d*)/
46
+ if value =~ /^\d+(\.\d*)/
44
47
  Time.at(value.to_f)
45
48
  elsif value =~ /^\d+$/
46
49
  Time.at(value.to_i)
@@ -66,7 +69,7 @@ module Aws
66
69
  end
67
70
 
68
71
  def extract_json_trait(value)
69
- JSON.parse(Base64.decode64(value))
72
+ Aws::Json.load(Base64.decode64(value))
70
73
  end
71
74
 
72
75
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Rest
3
5
  module Response
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Rest
3
5
  module Response
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'rest/handler'
2
4
  require_relative 'rest/request/body'
3
5
  require_relative 'rest/request/builder'