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,6 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  class SharedConfig
6
+ SSO_CREDENTIAL_PROFILE_KEYS = %w[sso_account_id sso_role_name].freeze
7
+ SSO_PROFILE_KEYS = %w[sso_session sso_start_url sso_region sso_account_id sso_role_name].freeze
8
+ SSO_TOKEN_PROFILE_KEYS = %w[sso_session].freeze
9
+ SSO_SESSION_KEYS = %w[sso_region sso_start_url].freeze
10
+
11
+
4
12
  # @return [String]
5
13
  attr_reader :credentials_path
6
14
 
@@ -47,10 +55,12 @@ module Aws
47
55
  @config_enabled = options[:config_enabled]
48
56
  @credentials_path = options[:credentials_path] ||
49
57
  determine_credentials_path
58
+ @credentials_path = File.expand_path(@credentials_path) if @credentials_path
50
59
  @parsed_credentials = {}
51
60
  load_credentials_file if loadable?(@credentials_path)
52
61
  if @config_enabled
53
62
  @config_path = options[:config_path] || determine_config_path
63
+ @config_path = File.expand_path(@config_path) if @config_path
54
64
  load_config_file if loadable?(@config_path)
55
65
  end
56
66
  end
@@ -96,7 +106,7 @@ module Aws
96
106
  # or `nil` if no valid credentials were found.
97
107
  def credentials(opts = {})
98
108
  p = opts[:profile] || @profile_name
99
- validate_profile_exists(p) if credentials_present?
109
+ validate_profile_exists(p)
100
110
  if (credentials = credentials_from_shared(p, opts))
101
111
  credentials
102
112
  elsif (credentials = credentials_from_config(p, opts))
@@ -133,6 +143,50 @@ module Aws
133
143
  end
134
144
  end
135
145
 
146
+ # Attempts to load from shared config or shared credentials file.
147
+ # Will always attempt first to load from the shared credentials
148
+ # file, if present.
149
+ def sso_credentials_from_config(opts = {})
150
+ p = opts[:profile] || @profile_name
151
+ credentials = sso_credentials_from_profile(@parsed_credentials, p)
152
+ if @parsed_config
153
+ credentials ||= sso_credentials_from_profile(@parsed_config, p)
154
+ end
155
+ credentials
156
+ end
157
+
158
+ # Attempts to load from shared config or shared credentials file.
159
+ # Will always attempt first to load from the shared credentials
160
+ # file, if present.
161
+ def sso_token_from_config(opts = {})
162
+ p = opts[:profile] || @profile_name
163
+ token = sso_token_from_profile(@parsed_credentials, p)
164
+ if @parsed_config
165
+ token ||= sso_token_from_profile(@parsed_config, p)
166
+ end
167
+ token
168
+ end
169
+
170
+ # Source a custom configured endpoint from the shared configuration file
171
+ #
172
+ # @param [Hash] opts
173
+ # @option opts [String] :profile
174
+ # @option opts [String] :service_id
175
+ def configured_endpoint(opts = {})
176
+ # services section is only allowed in the shared config file (not credentials)
177
+ profile = opts[:profile] || @profile_name
178
+ service_id = opts[:service_id]&.gsub(" ", "_")&.downcase
179
+ if @parsed_config && (prof_config = @parsed_config[profile])
180
+ services_section_name = prof_config['services']
181
+ if (services_config = @parsed_config["services #{services_section_name}"]) &&
182
+ (service_config = services_config[service_id])
183
+ return service_config['endpoint_url'] if service_config['endpoint_url']
184
+ end
185
+ return prof_config['endpoint_url']
186
+ end
187
+ nil
188
+ end
189
+
136
190
  # Add an accessor method (similar to attr_reader) to return a configuration value
137
191
  # Uses the get_config_value below to control where
138
192
  # values are loaded from
@@ -144,8 +198,14 @@ module Aws
144
198
 
145
199
  config_reader(
146
200
  :region,
201
+ :ca_bundle,
147
202
  :credential_process,
148
203
  :endpoint_discovery_enabled,
204
+ :use_dualstack_endpoint,
205
+ :use_fips_endpoint,
206
+ :ec2_metadata_service_endpoint,
207
+ :ec2_metadata_service_endpoint_mode,
208
+ :ec2_metadata_v1_disabled,
149
209
  :max_attempts,
150
210
  :retry_mode,
151
211
  :adaptive_retry_wait_to_fill,
@@ -156,7 +216,14 @@ module Aws
156
216
  :csm_port,
157
217
  :sts_regional_endpoints,
158
218
  :s3_use_arn_region,
159
- :s3_us_east_1_regional_endpoint
219
+ :s3_us_east_1_regional_endpoint,
220
+ :s3_disable_multiregion_access_points,
221
+ :s3_disable_express_session_auth,
222
+ :defaults_mode,
223
+ :sdk_ua_app_id,
224
+ :disable_request_compression,
225
+ :request_min_compression_size_bytes,
226
+ :ignore_configured_endpoint_urls
160
227
  )
161
228
 
162
229
  private
@@ -172,11 +239,6 @@ module Aws
172
239
  value
173
240
  end
174
241
 
175
- def credentials_present?
176
- (@parsed_credentials && !@parsed_credentials.empty?) ||
177
- (@parsed_config && !@parsed_config.empty?)
178
- end
179
-
180
242
  def assume_role_from_profile(cfg, profile, opts, chain_config)
181
243
  if cfg && prof_cfg = cfg[profile]
182
244
  opts[:source_profile] ||= prof_cfg['source_profile']
@@ -188,6 +250,7 @@ module Aws
188
250
  'a credential_source. For assume role credentials, must '\
189
251
  'provide only source_profile or credential_source, not both.'
190
252
  elsif opts[:source_profile]
253
+ opts[:visited_profiles] ||= Set.new
191
254
  opts[:credentials] = resolve_source_profile(opts[:source_profile], opts)
192
255
  if opts[:credentials]
193
256
  opts[:role_session_name] ||= prof_cfg['role_session_name']
@@ -197,6 +260,7 @@ module Aws
197
260
  opts[:external_id] ||= prof_cfg['external_id']
198
261
  opts[:serial_number] ||= prof_cfg['mfa_serial']
199
262
  opts[:profile] = opts.delete(:source_profile)
263
+ opts.delete(:visited_profiles)
200
264
  AssumeRoleCredentials.new(opts)
201
265
  else
202
266
  raise Errors::NoSourceProfileError,
@@ -229,12 +293,27 @@ module Aws
229
293
  end
230
294
 
231
295
  def resolve_source_profile(profile, opts = {})
296
+ if opts[:visited_profiles] && opts[:visited_profiles].include?(profile)
297
+ raise Errors::SourceProfileCircularReferenceError
298
+ end
299
+ opts[:visited_profiles].add(profile) if opts[:visited_profiles]
300
+
301
+ profile_config = @parsed_credentials[profile]
302
+ if @config_enabled
303
+ profile_config ||= @parsed_config[profile]
304
+ end
305
+
232
306
  if (creds = credentials(profile: profile))
233
307
  creds # static credentials
308
+ elsif profile_config && profile_config['source_profile']
309
+ opts.delete(:source_profile)
310
+ assume_role_credentials_from_config(opts.merge(profile: profile))
234
311
  elsif (provider = assume_role_web_identity_credentials_from_config(opts.merge(profile: profile)))
235
312
  provider.credentials if provider.credentials.set?
236
313
  elsif (provider = assume_role_process_credentials_from_config(profile))
237
314
  provider.credentials if provider.credentials.set?
315
+ elsif (provider = sso_credentials_from_config(profile: profile))
316
+ provider.credentials if provider.credentials.set?
238
317
  end
239
318
  end
240
319
 
@@ -255,7 +334,10 @@ module Aws
255
334
 
256
335
  def assume_role_process_credentials_from_config(profile)
257
336
  validate_profile_exists(profile)
258
- credential_process = @parsed_config[profile]['credential_process']
337
+ credential_process = @parsed_credentials.fetch(profile, {})['credential_process']
338
+ if @parsed_config
339
+ credential_process ||= @parsed_config.fetch(profile, {})['credential_process']
340
+ end
259
341
  ProcessCredentials.new(credential_process) if credential_process
260
342
  end
261
343
 
@@ -271,6 +353,62 @@ module Aws
271
353
  end
272
354
  end
273
355
 
356
+ # If any of the sso_ profile values are present, attempt to construct
357
+ # SSOCredentials
358
+ def sso_credentials_from_profile(cfg, profile)
359
+ if @parsed_config &&
360
+ (prof_config = cfg[profile]) &&
361
+ !(prof_config.keys & SSO_CREDENTIAL_PROFILE_KEYS).empty?
362
+
363
+ if sso_session_name = prof_config['sso_session']
364
+ sso_session = sso_session(cfg, profile, sso_session_name)
365
+
366
+ sso_region = sso_session['sso_region']
367
+ sso_start_url = sso_session['sso_start_url']
368
+
369
+ # validate sso_region and sso_start_url don't conflict if set on profile and session
370
+ if prof_config['sso_region'] && prof_config['sso_region'] != sso_region
371
+ raise ArgumentError,
372
+ "sso-session #{sso_session_name}'s sso_region (#{sso_region}) " \
373
+ "does not match the profile #{profile}'s sso_region (#{prof_config['sso_region']}'"
374
+ end
375
+ if prof_config['sso_start_url'] && prof_config['sso_start_url'] != sso_start_url
376
+ raise ArgumentError,
377
+ "sso-session #{sso_session_name}'s sso_start_url (#{sso_start_url}) " \
378
+ "does not match the profile #{profile}'s sso_start_url (#{prof_config['sso_start_url']}'"
379
+ end
380
+ else
381
+ sso_region = prof_config['sso_region']
382
+ sso_start_url = prof_config['sso_start_url']
383
+ end
384
+
385
+ SSOCredentials.new(
386
+ sso_account_id: prof_config['sso_account_id'],
387
+ sso_role_name: prof_config['sso_role_name'],
388
+ sso_session: prof_config['sso_session'],
389
+ sso_region: sso_region,
390
+ sso_start_url: sso_start_url
391
+ )
392
+ end
393
+ end
394
+
395
+ # If the required sso_ profile values are present, attempt to construct
396
+ # SSOTokenProvider
397
+ def sso_token_from_profile(cfg, profile)
398
+ if @parsed_config &&
399
+ (prof_config = cfg[profile]) &&
400
+ !(prof_config.keys & SSO_TOKEN_PROFILE_KEYS).empty?
401
+
402
+ sso_session_name = prof_config['sso_session']
403
+ sso_session = sso_session(cfg, profile, sso_session_name)
404
+
405
+ SSOTokenProvider.new(
406
+ sso_session: sso_session_name,
407
+ sso_region: sso_session['sso_region']
408
+ )
409
+ end
410
+ end
411
+
274
412
  def credentials_from_profile(prof_config)
275
413
  creds = Credentials.new(
276
414
  prof_config['aws_access_key_id'],
@@ -320,5 +458,22 @@ module Aws
320
458
  ret ||= 'default'
321
459
  ret
322
460
  end
461
+
462
+ def sso_session(cfg, profile, sso_session_name)
463
+ # aws sso-configure may add quotes around sso session names with whitespace
464
+ sso_session = cfg["sso-session #{sso_session_name}"] || cfg["sso-session '#{sso_session_name}'"]
465
+
466
+ unless sso_session
467
+ raise ArgumentError,
468
+ "sso-session #{sso_session_name} must be defined in the config file. " \
469
+ "Referenced by profile #{profile}"
470
+ end
471
+
472
+ unless sso_session['sso_region']
473
+ raise ArgumentError, "sso-session #{sso_session_name} missing required parameter: sso_region"
474
+ end
475
+
476
+ sso_session
477
+ end
323
478
  end
324
479
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'ini_parser'
2
4
 
3
5
  module Aws
@@ -12,11 +14,17 @@ module Aws
12
14
  'aws_session_token' => 'session_token',
13
15
  }
14
16
 
15
- # Constructs a new SharedCredentials object. This will load AWS access
17
+ # Constructs a new SharedCredentials object. This will load static
18
+ # (access_key_id, secret_access_key and session_token) AWS access
16
19
  # credentials from an ini file, which supports profiles. The default
17
20
  # profile name is 'default'. You can specify the profile name with the
18
21
  # `ENV['AWS_PROFILE']` or with the `:profile_name` option.
19
22
  #
23
+ # To use credentials from the default credential resolution chain
24
+ # create a client without the credential option specified.
25
+ # You may access the resolved credentials through
26
+ # `client.config.credentials`.
27
+ #
20
28
  # @option [String] :path Path to the shared file. Defaults
21
29
  # to "#{Dir.home}/.aws/credentials".
22
30
  #
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # An auto-refreshing credential provider that assumes a role via
5
+ # {Aws::SSO::Client#get_role_credentials} using a cached access
6
+ # token. When `sso_session` is specified, token refresh logic from
7
+ # {Aws::SSOTokenProvider} will be used to refresh the token if possible.
8
+ # This class does NOT implement the SSO login token flow - tokens
9
+ # must generated separately by running `aws login` from the
10
+ # AWS CLI with the correct profile. The `SSOCredentials` will
11
+ # auto-refresh the AWS credentials from SSO.
12
+ #
13
+ # # You must first run aws sso login --profile your-sso-profile
14
+ # sso_credentials = Aws::SSOCredentials.new(
15
+ # sso_account_id: '123456789',
16
+ # sso_role_name: "role_name",
17
+ # sso_region: "us-east-1",
18
+ # sso_session: 'my_sso_session'
19
+ # )
20
+ # ec2 = Aws::EC2::Client.new(credentials: sso_credentials)
21
+ #
22
+ # If you omit `:client` option, a new {Aws::SSO::Client} object will be
23
+ # constructed with additional options that were provided.
24
+ #
25
+ # @see Aws::SSO::Client#get_role_credentials
26
+ # @see https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html
27
+ class SSOCredentials
28
+
29
+ include CredentialProvider
30
+ include RefreshingCredentials
31
+
32
+ # @api private
33
+ LEGACY_REQUIRED_OPTS = [:sso_start_url, :sso_account_id, :sso_region, :sso_role_name].freeze
34
+ TOKEN_PROVIDER_REQUIRED_OPTS = [:sso_session, :sso_account_id, :sso_region, :sso_role_name].freeze
35
+
36
+ # @api private
37
+ SSO_LOGIN_GUIDANCE = 'The SSO session associated with this profile has '\
38
+ 'expired or is otherwise invalid. To refresh this SSO session run '\
39
+ 'aws sso login with the corresponding profile.'.freeze
40
+
41
+ # @option options [required, String] :sso_account_id The AWS account ID
42
+ # that temporary AWS credentials will be resolved for
43
+ #
44
+ # @option options [required, String] :sso_role_name The corresponding
45
+ # IAM role in the AWS account that temporary AWS credentials
46
+ # will be resolved for.
47
+ #
48
+ # @option options [required, String] :sso_region The AWS region where the
49
+ # SSO directory for the given sso_start_url is hosted.
50
+ #
51
+ # @option options [String] :sso_session The SSO Token used for fetching
52
+ # the token. If provided, refresh logic from the {Aws::SSOTokenProvider}
53
+ # will be used.
54
+ #
55
+ # @option options [String] :sso_start_url (legacy profiles) If provided,
56
+ # legacy token fetch behavior will be used, which does not support
57
+ # token refreshing. The start URL is provided by the SSO
58
+ # service via the console and is the URL used to
59
+ # login to the SSO directory. This is also sometimes referred to as
60
+ # the "User Portal URL".
61
+ #
62
+ # @option options [SSO::Client] :client Optional `SSO::Client`. If not
63
+ # provided, a client will be constructed.
64
+ #
65
+ # @option options [Callable] before_refresh Proc called before
66
+ # credentials are refreshed. `before_refresh` is called
67
+ # with an instance of this object when
68
+ # AWS credentials are required and need to be refreshed.
69
+ def initialize(options = {})
70
+ options = options.select {|k, v| !v.nil? }
71
+ if (options[:sso_session])
72
+ missing_keys = TOKEN_PROVIDER_REQUIRED_OPTS.select { |k| options[k].nil? }
73
+ unless missing_keys.empty?
74
+ raise ArgumentError, "Missing required keys: #{missing_keys}"
75
+ end
76
+ @legacy = false
77
+ @sso_role_name = options.delete(:sso_role_name)
78
+ @sso_account_id = options.delete(:sso_account_id)
79
+
80
+ # if client has been passed, don't pass through to SSOTokenProvider
81
+ @client = options.delete(:client)
82
+ options.delete(:sso_start_url)
83
+ @token_provider = Aws::SSOTokenProvider.new(options.dup)
84
+ @sso_session = options.delete(:sso_session)
85
+ @sso_region = options.delete(:sso_region)
86
+
87
+ unless @client
88
+ client_opts = {}
89
+ options.each_pair { |k,v| client_opts[k] = v unless CLIENT_EXCLUDE_OPTIONS.include?(k) }
90
+ client_opts[:region] = @sso_region
91
+ client_opts[:credentials] = nil
92
+ @client = Aws::SSO::Client.new(client_opts)
93
+ end
94
+ else # legacy behavior
95
+ missing_keys = LEGACY_REQUIRED_OPTS.select { |k| options[k].nil? }
96
+ unless missing_keys.empty?
97
+ raise ArgumentError, "Missing required keys: #{missing_keys}"
98
+ end
99
+ @legacy = true
100
+ @sso_start_url = options.delete(:sso_start_url)
101
+ @sso_region = options.delete(:sso_region)
102
+ @sso_role_name = options.delete(:sso_role_name)
103
+ @sso_account_id = options.delete(:sso_account_id)
104
+
105
+ # validate we can read the token file
106
+ read_cached_token
107
+
108
+ client_opts = {}
109
+ options.each_pair { |k,v| client_opts[k] = v unless CLIENT_EXCLUDE_OPTIONS.include?(k) }
110
+ client_opts[:region] = @sso_region
111
+ client_opts[:credentials] = nil
112
+
113
+ @client = options[:client] || Aws::SSO::Client.new(client_opts)
114
+ end
115
+
116
+ @async_refresh = true
117
+ super
118
+ end
119
+
120
+ # @return [SSO::Client]
121
+ attr_reader :client
122
+
123
+ private
124
+
125
+ def read_cached_token
126
+ cached_token = Json.load(File.read(sso_cache_file))
127
+ # validation
128
+ unless cached_token['accessToken'] && cached_token['expiresAt']
129
+ raise ArgumentError, 'Missing required field(s)'
130
+ end
131
+ expires_at = DateTime.parse(cached_token['expiresAt'])
132
+ if expires_at < DateTime.now
133
+ raise ArgumentError, 'Cached SSO Token is expired.'
134
+ end
135
+ cached_token
136
+ rescue Errno::ENOENT, Aws::Json::ParseError, ArgumentError
137
+ raise Errors::InvalidSSOCredentials, SSO_LOGIN_GUIDANCE
138
+ end
139
+
140
+ def refresh
141
+ c = if @legacy
142
+ cached_token = read_cached_token
143
+ @client.get_role_credentials(
144
+ account_id: @sso_account_id,
145
+ role_name: @sso_role_name,
146
+ access_token: cached_token['accessToken']
147
+ ).role_credentials
148
+ else
149
+ @client.get_role_credentials(
150
+ account_id: @sso_account_id,
151
+ role_name: @sso_role_name,
152
+ access_token: @token_provider.token.token
153
+ ).role_credentials
154
+ end
155
+
156
+ @credentials = Credentials.new(
157
+ c.access_key_id,
158
+ c.secret_access_key,
159
+ c.session_token
160
+ )
161
+ @expiration = Time.at(c.expiration / 1000.0)
162
+ end
163
+
164
+ def sso_cache_file
165
+ start_url_sha1 = OpenSSL::Digest::SHA1.hexdigest(@sso_start_url.encode('utf-8'))
166
+ File.join(Dir.home, '.aws', 'sso', 'cache', "#{start_url_sha1}.json")
167
+ rescue ArgumentError
168
+ # Dir.home raises ArgumentError when ENV['home'] is not set
169
+ raise ArgumentError, "Unable to load sso_cache_file: ENV['HOME'] is not set."
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ class SSOTokenProvider
5
+
6
+ include TokenProvider
7
+ include RefreshingToken
8
+
9
+ # @api private
10
+ SSO_REQUIRED_OPTS = [:sso_region, :sso_session].freeze
11
+
12
+ # @api private
13
+ SSO_LOGIN_GUIDANCE = 'The SSO session associated with this profile has '\
14
+ 'expired or is otherwise invalid. To refresh this SSO session run '\
15
+ 'aws sso login with the corresponding profile.'.freeze
16
+
17
+ # @option options [required, String] :sso_region The AWS region where the
18
+ # SSO directory for the given sso_start_url is hosted.
19
+ #
20
+ # @option options [required, String] :sso_session The SSO Session used to
21
+ # for fetching this token.
22
+ #
23
+ # @option options [SSOOIDC::Client] :client Optional `SSOOIDC::Client`. If not
24
+ # provided, a client will be constructed.
25
+ #
26
+ # @option options [Callable] before_refresh Proc called before
27
+ # credentials are refreshed. `before_refresh` is called
28
+ # with an instance of this object when
29
+ # AWS credentials are required and need to be refreshed.
30
+ def initialize(options = {})
31
+
32
+ missing_keys = SSO_REQUIRED_OPTS.select { |k| options[k].nil? }
33
+ unless missing_keys.empty?
34
+ raise ArgumentError, "Missing required keys: #{missing_keys}"
35
+ end
36
+
37
+ @sso_session = options.delete(:sso_session)
38
+ @sso_region = options.delete(:sso_region)
39
+
40
+ options[:region] = @sso_region
41
+ options[:credentials] = nil
42
+ options[:token_provider] = nil
43
+ @client = options[:client] || Aws::SSOOIDC::Client.new(options)
44
+
45
+ super
46
+ end
47
+
48
+ # @return [SSOOIDC::Client]
49
+ attr_reader :client
50
+
51
+ private
52
+
53
+ def refresh
54
+ # token is valid and not in refresh window - do not refresh it.
55
+ return if @token && @token.expiration && !near_expiration?
56
+
57
+ # token may not exist or is out of the expiration window
58
+ # attempt to refresh from disk first (another process/application may have refreshed already)
59
+ token_json = read_cached_token
60
+ @token = Token.new(token_json['accessToken'], token_json['expiresAt'])
61
+ return if @token && @token.expiration && !near_expiration?
62
+
63
+ # The token is expired and needs to be refreshed
64
+ if can_refresh_token?(token_json)
65
+ begin
66
+ current_time = Time.now
67
+ resp = @client.create_token(
68
+ grant_type: 'refresh_token',
69
+ client_id: token_json['clientId'],
70
+ client_secret: token_json['clientSecret'],
71
+ refresh_token: token_json['refreshToken']
72
+ )
73
+ token_json['accessToken'] = resp.access_token
74
+ token_json['expiresAt'] = current_time + resp.expires_in
75
+ @token = Token.new(token_json['accessToken'], token_json['expiresAt'])
76
+
77
+ if resp.refresh_token
78
+ token_json['refreshToken'] = resp.refresh_token
79
+ else
80
+ token_json.delete('refreshToken')
81
+ end
82
+
83
+ update_token_cache(token_json)
84
+ rescue
85
+ # refresh has failed, continue attempting to use the token if its not hard expired
86
+ end
87
+ end
88
+
89
+ if !@token.expiration || @token.expiration < Time.now
90
+ # Token is hard expired, raise an exception
91
+ raise Errors::InvalidSSOToken, 'Token is invalid and failed to refresh.'
92
+ end
93
+ end
94
+
95
+ def read_cached_token
96
+ cached_token = Json.load(File.read(sso_cache_file))
97
+ # validation
98
+ unless cached_token['accessToken'] && cached_token['expiresAt']
99
+ raise ArgumentError, 'Missing required field(s)'
100
+ end
101
+ cached_token['expiresAt'] = Time.parse(cached_token['expiresAt'])
102
+ cached_token
103
+ rescue Errno::ENOENT, Aws::Json::ParseError, ArgumentError
104
+ raise Errors::InvalidSSOToken, SSO_LOGIN_GUIDANCE
105
+ end
106
+
107
+ def update_token_cache(token_json)
108
+ cached_token = token_json.dup
109
+ cached_token['expiresAt'] = cached_token['expiresAt'].iso8601
110
+ File.write(sso_cache_file, Json.dump(cached_token))
111
+ end
112
+
113
+ def sso_cache_file
114
+ sso_session_sha1 = OpenSSL::Digest::SHA1.hexdigest(@sso_session.encode('utf-8'))
115
+ File.join(Dir.home, '.aws', 'sso', 'cache', "#{sso_session_sha1}.json")
116
+ rescue ArgumentError
117
+ # Dir.home raises ArgumentError when ENV['home'] is not set
118
+ raise ArgumentError, "Unable to load sso_cache_file: ENV['HOME'] is not set."
119
+ end
120
+
121
+ # return true if all required fields are present
122
+ # return false if registrationExpiresAt exists and is later than now
123
+ def can_refresh_token?(token_json)
124
+ if token_json['clientId'] &&
125
+ token_json['clientSecret'] &&
126
+ token_json['refreshToken']
127
+
128
+ return !token_json['registrationExpiresAt'] ||
129
+ Time.parse(token_json['registrationExpiresAt']) > Time.now
130
+ else
131
+ false
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ class StaticTokenProvider
5
+
6
+ include TokenProvider
7
+
8
+ # @param [String] token
9
+ # @param [Time] expiration
10
+ def initialize(token, expiration=nil)
11
+ @token = Token.new(token, expiration)
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  module Structure
@@ -26,18 +28,20 @@ module Aws
26
28
  # in stdlib Struct.
27
29
  #
28
30
  # @return [Hash]
29
- def to_h(obj = self)
31
+ def to_h(obj = self, options = {})
30
32
  case obj
31
33
  when Struct
32
34
  obj.each_pair.with_object({}) do |(member, value), hash|
33
- hash[member] = to_hash(value) unless value.nil?
35
+ member = member.to_s if options[:as_json]
36
+ hash[member] = to_hash(value, options) unless value.nil?
34
37
  end
35
38
  when Hash
36
39
  obj.each.with_object({}) do |(key, value), hash|
37
- hash[key] = to_hash(value)
40
+ key = key.to_s if options[:as_json]
41
+ hash[key] = to_hash(value, options)
38
42
  end
39
43
  when Array
40
- obj.collect { |value| to_hash(value) }
44
+ obj.collect { |value| to_hash(value, options) }
41
45
  else
42
46
  obj
43
47
  end
@@ -46,7 +50,7 @@ module Aws
46
50
 
47
51
  # Wraps the default #to_s logic with filtering of sensitive parameters.
48
52
  def to_s(obj = self)
49
- Aws::Log::ParamFilter.new.filter(obj).to_s
53
+ Aws::Log::ParamFilter.new.filter(obj, obj.class).to_s
50
54
  end
51
55
 
52
56
  class << self
@@ -68,11 +72,20 @@ module Aws
68
72
  end
69
73
 
70
74
  end
75
+
76
+ module Union
77
+ def member
78
+ self.members.select { |k| self[k] != nil }.first
79
+ end
80
+
81
+ def value
82
+ self[member] if member
83
+ end
84
+ end
71
85
  end
72
86
 
73
87
  # @api private
74
88
  class EmptyStructure < Struct.new('AwsEmptyStructure')
75
89
  include(Aws::Structure)
76
90
  end
77
-
78
91
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  class DataApplicator
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  class EmptyStub
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  module Protocols