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
@@ -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'
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  class SharedConfig
6
+ SSO_PROFILE_KEYS = %w[sso_start_url sso_region sso_account_id sso_role_name].freeze
7
+
4
8
  # @return [String]
5
9
  attr_reader :credentials_path
6
10
 
@@ -96,7 +100,7 @@ module Aws
96
100
  # or `nil` if no valid credentials were found.
97
101
  def credentials(opts = {})
98
102
  p = opts[:profile] || @profile_name
99
- validate_profile_exists(p) if credentials_present?
103
+ validate_profile_exists(p)
100
104
  if (credentials = credentials_from_shared(p, opts))
101
105
  credentials
102
106
  elsif (credentials = credentials_from_config(p, opts))
@@ -133,6 +137,18 @@ module Aws
133
137
  end
134
138
  end
135
139
 
140
+ # Attempts to load from shared config or shared credentials file.
141
+ # Will always attempt first to load from the shared credentials
142
+ # file, if present.
143
+ def sso_credentials_from_config(opts = {})
144
+ p = opts[:profile] || @profile_name
145
+ credentials = sso_credentials_from_profile(@parsed_credentials, p)
146
+ if @parsed_config
147
+ credentials ||= sso_credentials_from_profile(@parsed_config, p)
148
+ end
149
+ credentials
150
+ end
151
+
136
152
  # Add an accessor method (similar to attr_reader) to return a configuration value
137
153
  # Uses the get_config_value below to control where
138
154
  # values are loaded from
@@ -144,8 +160,13 @@ module Aws
144
160
 
145
161
  config_reader(
146
162
  :region,
163
+ :ca_bundle,
147
164
  :credential_process,
148
165
  :endpoint_discovery_enabled,
166
+ :use_dualstack_endpoint,
167
+ :use_fips_endpoint,
168
+ :ec2_metadata_service_endpoint,
169
+ :ec2_metadata_service_endpoint_mode,
149
170
  :max_attempts,
150
171
  :retry_mode,
151
172
  :adaptive_retry_wait_to_fill,
@@ -156,7 +177,9 @@ module Aws
156
177
  :csm_port,
157
178
  :sts_regional_endpoints,
158
179
  :s3_use_arn_region,
159
- :s3_us_east_1_regional_endpoint
180
+ :s3_us_east_1_regional_endpoint,
181
+ :s3_disable_multiregion_access_points,
182
+ :defaults_mode
160
183
  )
161
184
 
162
185
  private
@@ -172,11 +195,6 @@ module Aws
172
195
  value
173
196
  end
174
197
 
175
- def credentials_present?
176
- (@parsed_credentials && !@parsed_credentials.empty?) ||
177
- (@parsed_config && !@parsed_config.empty?)
178
- end
179
-
180
198
  def assume_role_from_profile(cfg, profile, opts, chain_config)
181
199
  if cfg && prof_cfg = cfg[profile]
182
200
  opts[:source_profile] ||= prof_cfg['source_profile']
@@ -188,6 +206,7 @@ module Aws
188
206
  'a credential_source. For assume role credentials, must '\
189
207
  'provide only source_profile or credential_source, not both.'
190
208
  elsif opts[:source_profile]
209
+ opts[:visited_profiles] ||= Set.new
191
210
  opts[:credentials] = resolve_source_profile(opts[:source_profile], opts)
192
211
  if opts[:credentials]
193
212
  opts[:role_session_name] ||= prof_cfg['role_session_name']
@@ -197,6 +216,7 @@ module Aws
197
216
  opts[:external_id] ||= prof_cfg['external_id']
198
217
  opts[:serial_number] ||= prof_cfg['mfa_serial']
199
218
  opts[:profile] = opts.delete(:source_profile)
219
+ opts.delete(:visited_profiles)
200
220
  AssumeRoleCredentials.new(opts)
201
221
  else
202
222
  raise Errors::NoSourceProfileError,
@@ -229,12 +249,27 @@ module Aws
229
249
  end
230
250
 
231
251
  def resolve_source_profile(profile, opts = {})
252
+ if opts[:visited_profiles] && opts[:visited_profiles].include?(profile)
253
+ raise Errors::SourceProfileCircularReferenceError
254
+ end
255
+ opts[:visited_profiles].add(profile) if opts[:visited_profiles]
256
+
257
+ profile_config = @parsed_credentials[profile]
258
+ if @config_enabled
259
+ profile_config ||= @parsed_config[profile]
260
+ end
261
+
232
262
  if (creds = credentials(profile: profile))
233
263
  creds # static credentials
264
+ elsif profile_config && profile_config['source_profile']
265
+ opts.delete(:source_profile)
266
+ assume_role_credentials_from_config(opts.merge(profile: profile))
234
267
  elsif (provider = assume_role_web_identity_credentials_from_config(opts.merge(profile: profile)))
235
268
  provider.credentials if provider.credentials.set?
236
269
  elsif (provider = assume_role_process_credentials_from_config(profile))
237
270
  provider.credentials if provider.credentials.set?
271
+ elsif (provider = sso_credentials_from_config(profile: profile))
272
+ provider.credentials if provider.credentials.set?
238
273
  end
239
274
  end
240
275
 
@@ -255,7 +290,10 @@ module Aws
255
290
 
256
291
  def assume_role_process_credentials_from_config(profile)
257
292
  validate_profile_exists(profile)
258
- credential_process = @parsed_config[profile]['credential_process']
293
+ credential_process = @parsed_credentials.fetch(profile, {})['credential_process']
294
+ if @parsed_config
295
+ credential_process ||= @parsed_config.fetch(profile, {})['credential_process']
296
+ end
259
297
  ProcessCredentials.new(credential_process) if credential_process
260
298
  end
261
299
 
@@ -271,6 +309,22 @@ module Aws
271
309
  end
272
310
  end
273
311
 
312
+ # If any of the sso_ profile values are present, attempt to construct
313
+ # SSOCredentials
314
+ def sso_credentials_from_profile(cfg, profile)
315
+ if @parsed_config &&
316
+ (prof_config = cfg[profile]) &&
317
+ !(prof_config.keys & SSO_PROFILE_KEYS).empty?
318
+
319
+ SSOCredentials.new(
320
+ sso_start_url: prof_config['sso_start_url'],
321
+ sso_region: prof_config['sso_region'],
322
+ sso_account_id: prof_config['sso_account_id'],
323
+ sso_role_name: prof_config['sso_role_name']
324
+ )
325
+ end
326
+ end
327
+
274
328
  def credentials_from_profile(prof_config)
275
329
  creds = Credentials.new(
276
330
  prof_config['aws_access_key_id'],
@@ -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,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ # An auto-refreshing credential provider that works by assuming a
5
+ # role via {Aws::SSO::Client#get_role_credentials} using a cached access
6
+ # token. This class does NOT implement the SSO login token flow - tokens
7
+ # must generated and refreshed separately by running `aws login` from the
8
+ # AWS CLI with the correct profile.
9
+ #
10
+ # For more background on AWS SSO see the official
11
+ # {https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html what is SSO Userguide}
12
+ #
13
+ # ## Refreshing Credentials from SSO
14
+ #
15
+ # The `SSOCredentials` will auto-refresh the AWS credentials from SSO. In
16
+ # addition to AWS credentials expiring after a given amount of time, the
17
+ # access token generated and cached from `aws login` will also expire.
18
+ # Once this token expires, it will not be usable to refresh AWS credentials,
19
+ # and another token will be needed. The SDK does not manage refreshing of
20
+ # the token value, but this can be done by running `aws login` with the
21
+ # correct profile.
22
+ #
23
+ #
24
+ # # You must first run aws sso login --profile your-sso-profile
25
+ # sso_credentials = Aws::SSOCredentials.new(
26
+ # sso_account_id: '123456789',
27
+ # sso_role_name: "role_name",
28
+ # sso_region: "us-east-1",
29
+ # sso_start_url: 'https://your-start-url.awsapps.com/start'
30
+ # )
31
+ #
32
+ # ec2 = Aws::EC2::Client.new(credentials: sso_credentials)
33
+ #
34
+ # If you omit `:client` option, a new {SSO::Client} object will be
35
+ # constructed.
36
+ class SSOCredentials
37
+
38
+ include CredentialProvider
39
+ include RefreshingCredentials
40
+
41
+ # @api private
42
+ SSO_REQUIRED_OPTS = [:sso_account_id, :sso_region, :sso_role_name, :sso_start_url].freeze
43
+
44
+ # @api private
45
+ SSO_LOGIN_GUIDANCE = 'The SSO session associated with this profile has '\
46
+ 'expired or is otherwise invalid. To refresh this SSO session run '\
47
+ 'aws sso login with the corresponding profile.'.freeze
48
+
49
+ # @option options [required, String] :sso_account_id The AWS account ID
50
+ # that temporary AWS credentials will be resolved for
51
+ #
52
+ # @option options [required, String] :sso_region The AWS region where the
53
+ # SSO directory for the given sso_start_url is hosted.
54
+ #
55
+ # @option options [required, String] :sso_role_name The corresponding
56
+ # IAM role in the AWS account that temporary AWS credentials
57
+ # will be resolved for.
58
+ #
59
+ # @option options [required, String] :sso_start_url The start URL is
60
+ # provided by the SSO service via the console and is the URL used to
61
+ # login to the SSO directory. This is also sometimes referred to as
62
+ # the "User Portal URL"
63
+ #
64
+ # @option options [SSO::Client] :client Optional `SSO::Client`. If not
65
+ # provided, a client will be constructed.
66
+ #
67
+ # @option options [Callable] before_refresh Proc called before
68
+ # credentials are refreshed. `before_refresh` is called
69
+ # with an instance of this object when
70
+ # AWS credentials are required and need to be refreshed.
71
+ def initialize(options = {})
72
+
73
+ missing_keys = SSO_REQUIRED_OPTS.select { |k| options[k].nil? }
74
+ unless missing_keys.empty?
75
+ raise ArgumentError, "Missing required keys: #{missing_keys}"
76
+ end
77
+
78
+ @sso_start_url = options.delete(:sso_start_url)
79
+ @sso_region = options.delete(:sso_region)
80
+ @sso_role_name = options.delete(:sso_role_name)
81
+ @sso_account_id = options.delete(:sso_account_id)
82
+
83
+ # validate we can read the token file
84
+ read_cached_token
85
+
86
+ options[:region] = @sso_region
87
+ options[:credentials] = nil
88
+ @client = options[:client] || Aws::SSO::Client.new(options)
89
+ @async_refresh = true
90
+ super
91
+ end
92
+
93
+ # @return [SSO::Client]
94
+ attr_reader :client
95
+
96
+ private
97
+
98
+ def read_cached_token
99
+ cached_token = Json.load(File.read(sso_cache_file))
100
+ # validation
101
+ unless cached_token['accessToken'] && cached_token['expiresAt']
102
+ raise ArgumentError, 'Missing required field(s)'
103
+ end
104
+ expires_at = DateTime.parse(cached_token['expiresAt'])
105
+ if expires_at < DateTime.now
106
+ raise ArgumentError, 'Cached SSO Token is expired.'
107
+ end
108
+ cached_token
109
+ rescue Errno::ENOENT, Aws::Json::ParseError, ArgumentError
110
+ raise Errors::InvalidSSOCredentials, SSO_LOGIN_GUIDANCE
111
+ end
112
+
113
+ def refresh
114
+ cached_token = read_cached_token
115
+ c = @client.get_role_credentials(
116
+ account_id: @sso_account_id,
117
+ role_name: @sso_role_name,
118
+ access_token: cached_token['accessToken']
119
+ ).role_credentials
120
+
121
+ @credentials = Credentials.new(
122
+ c.access_key_id,
123
+ c.secret_access_key,
124
+ c.session_token
125
+ )
126
+ @expiration = c.expiration
127
+ end
128
+
129
+ def sso_cache_file
130
+ start_url_sha1 = OpenSSL::Digest::SHA1.hexdigest(@sso_start_url.encode('utf-8'))
131
+ File.join(Dir.home, '.aws', 'sso', 'cache', "#{start_url_sha1}.json")
132
+ rescue ArgumentError
133
+ # Dir.home raises ArgumentError when ENV['home'] is not set
134
+ raise ArgumentError, "Unable to load sso_cache_file: ENV['HOME'] is not set."
135
+ end
136
+ end
137
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  module Structure
@@ -46,7 +48,7 @@ module Aws
46
48
 
47
49
  # Wraps the default #to_s logic with filtering of sensitive parameters.
48
50
  def to_s(obj = self)
49
- Aws::Log::ParamFilter.new.filter(obj).to_s
51
+ Aws::Log::ParamFilter.new.filter(obj, obj.class).to_s
50
52
  end
51
53
 
52
54
  class << self
@@ -68,11 +70,20 @@ module Aws
68
70
  end
69
71
 
70
72
  end
73
+
74
+ module Union
75
+ def member
76
+ self.members.select { |k| self[k] != nil }.first
77
+ end
78
+
79
+ def value
80
+ self[member] if member
81
+ end
82
+ end
71
83
  end
72
84
 
73
85
  # @api private
74
86
  class EmptyStructure < Struct.new('AwsEmptyStructure')
75
87
  include(Aws::Structure)
76
88
  end
77
-
78
89
  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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  module Protocols
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  module Protocols
@@ -27,7 +29,7 @@ module Aws
27
29
  private
28
30
 
29
31
  def content_type(api)
30
- "application/x-amz-json-#{api.metadata['jsonVerison']}"
32
+ "application/x-amz-json-#{api.metadata['jsonVersion']}"
31
33
  end
32
34
 
33
35
  def build_body(operation, data)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  module Protocols
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'aws-eventstream'
2
4
 
3
5
  module Aws
@@ -118,7 +120,7 @@ module Aws
118
120
 
119
121
  def encode_unknown_event(opts, event_type, event_data)
120
122
  # right now h2 events are only rest_json
121
- opts[:payload] = StringIO.new(JSON.dump(event_data))
123
+ opts[:payload] = StringIO.new(Aws::Json.dump(event_data))
122
124
  opts[:headers][':event-type'] = Aws::EventStream::HeaderValue.new(
123
125
  value: event_type.to_s,
124
126
  type: 'string'
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  module Protocols
4
6
  class RestJson < Rest
5
7
 
6
- def body_for(_, _, rules, data)
8
+ def body_for(_a, _b, rules, data)
7
9
  if eventstream?(rules)
8
10
  encode_eventstream_response(rules, data, Aws::Json::Builder)
9
11
  else
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  module Protocols
4
6
  class RestXml < Rest
5
7
 
6
- include Seahorse::Model::Shapes
7
-
8
8
  def body_for(api, operation, rules, data)
9
9
  if eventstream?(rules)
10
10
  encode_eventstream_response(rules, data, Xml::Builder)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  module Stubbing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Stubbing
3
5
  class XmlError
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  class TypeBuilder
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cgi'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Waiters
3
5
  module Errors
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Waiters
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Waiters
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'waiters/errors'
2
4
  require_relative 'waiters/poller'
3
5
  require_relative 'waiters/waiter'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'base64'
2
4
 
3
5
  module Aws
@@ -9,7 +11,7 @@ module Aws
9
11
  def initialize(rules, options = {})
10
12
  @rules = rules
11
13
  @xml = options[:target] || []
12
- indent = options[:indent] || ' '
14
+ indent = options[:indent] || ''
13
15
  pad = options[:pad] || ''
14
16
  @builder = DocBuilder.new(target: @xml, indent: indent, pad: pad)
15
17
  end
@@ -46,7 +48,7 @@ module Aws
46
48
  end
47
49
 
48
50
  def list(name, ref, values)
49
- if ref.shape.flattened
51
+ if ref[:flattened] || ref.shape.flattened
50
52
  values.each do |value|
51
53
  member(ref.shape.member.location_name || name, ref.shape.member, value)
52
54
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Xml
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Xml
3
5
  # @api private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  module Xml
3
5
  class DocBuilder
@@ -65,7 +67,12 @@ module Aws
65
67
  end
66
68
 
67
69
  def escape(string, text_or_attr)
68
- string.to_s.encode(:xml => text_or_attr)
70
+ string.to_s
71
+ .encode(:xml => text_or_attr)
72
+ .gsub("\u{000D}", '&#xD;') # Carriage Return
73
+ .gsub("\u{000A}", '&#xA;') # Line Feed
74
+ .gsub("\u{0085}", '&#x85;') # Next Line
75
+ .gsub("\u{2028}", '&#x2028;') # Line Separator
69
76
  end
70
77
 
71
78
  def attributes(attr)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cgi'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'libxml'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'nokogiri'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'oga'
2
4
 
3
5
  module Aws
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ox'
2
4
  require 'stringio'
3
5
 
@@ -14,7 +16,7 @@ module Aws
14
16
  Ox.sax_parse(
15
17
  @stack, StringIO.new(xml),
16
18
  :convert_special => true,
17
- :skip => :skip_white
19
+ :skip => :skip_return
18
20
  )
19
21
  end
20
22
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rexml/document'
2
4
  require 'rexml/streamlistener'
3
5