aws-sdk-core 3.0.0 → 3.129.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1287 -0
  3. data/LICENSE.txt +202 -0
  4. data/VERSION +1 -1
  5. data/ca-bundle.crt +3615 -3541
  6. data/lib/aws-defaults/default_configuration.rb +153 -0
  7. data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
  8. data/lib/aws-defaults.rb +3 -0
  9. data/lib/aws-sdk-core/arn.rb +92 -0
  10. data/lib/aws-sdk-core/arn_parser.rb +40 -0
  11. data/lib/aws-sdk-core/assume_role_credentials.rb +20 -0
  12. data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +109 -0
  13. data/lib/aws-sdk-core/async_client_stubs.rb +82 -0
  14. data/lib/aws-sdk-core/binary/decode_handler.rb +58 -0
  15. data/lib/aws-sdk-core/binary/encode_handler.rb +34 -0
  16. data/lib/aws-sdk-core/binary/event_builder.rb +124 -0
  17. data/lib/aws-sdk-core/binary/event_parser.rb +136 -0
  18. data/lib/aws-sdk-core/binary/event_stream_decoder.rb +64 -0
  19. data/lib/aws-sdk-core/binary/event_stream_encoder.rb +55 -0
  20. data/lib/aws-sdk-core/binary.rb +8 -0
  21. data/lib/aws-sdk-core/client_side_monitoring/publisher.rb +51 -0
  22. data/lib/aws-sdk-core/client_side_monitoring/request_metrics.rb +199 -0
  23. data/lib/aws-sdk-core/client_stubs.rb +55 -10
  24. data/lib/aws-sdk-core/credential_provider.rb +1 -30
  25. data/lib/aws-sdk-core/credential_provider_chain.rb +111 -33
  26. data/lib/aws-sdk-core/credentials.rb +2 -0
  27. data/lib/aws-sdk-core/deprecations.rb +17 -11
  28. data/lib/aws-sdk-core/eager_loader.rb +2 -0
  29. data/lib/aws-sdk-core/ec2_metadata.rb +238 -0
  30. data/lib/aws-sdk-core/ecs_credentials.rb +20 -11
  31. data/lib/aws-sdk-core/endpoint_cache.rb +193 -0
  32. data/lib/aws-sdk-core/errors.rb +210 -12
  33. data/lib/aws-sdk-core/event_emitter.rb +64 -0
  34. data/lib/aws-sdk-core/ini_parser.rb +2 -0
  35. data/lib/aws-sdk-core/instance_profile_credentials.rb +237 -45
  36. data/lib/aws-sdk-core/json/builder.rb +6 -2
  37. data/lib/aws-sdk-core/json/error_handler.rb +21 -2
  38. data/lib/aws-sdk-core/json/handler.rb +21 -1
  39. data/lib/aws-sdk-core/json/json_engine.rb +12 -8
  40. data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
  41. data/lib/aws-sdk-core/json/parser.rb +10 -0
  42. data/lib/aws-sdk-core/json.rb +11 -28
  43. data/lib/aws-sdk-core/log/formatter.rb +16 -4
  44. data/lib/aws-sdk-core/log/handler.rb +2 -0
  45. data/lib/aws-sdk-core/log/param_filter.rb +38 -13
  46. data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
  47. data/lib/aws-sdk-core/pageable_response.rb +111 -47
  48. data/lib/aws-sdk-core/pager.rb +5 -0
  49. data/lib/aws-sdk-core/param_converter.rb +2 -0
  50. data/lib/aws-sdk-core/param_validator.rb +99 -22
  51. data/lib/aws-sdk-core/plugins/api_key.rb +56 -0
  52. data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +32 -0
  53. data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +36 -0
  54. data/lib/aws-sdk-core/plugins/apig_user_agent.rb +39 -0
  55. data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +340 -0
  56. data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +283 -0
  57. data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +86 -0
  58. data/lib/aws-sdk-core/plugins/credentials_configuration.rb +26 -7
  59. data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
  60. data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +168 -0
  61. data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +65 -0
  62. data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +32 -0
  63. data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
  64. data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
  65. data/lib/aws-sdk-core/plugins/http_checksum.rb +64 -0
  66. data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
  67. data/lib/aws-sdk-core/plugins/invocation_id.rb +35 -0
  68. data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +2 -0
  69. data/lib/aws-sdk-core/plugins/logging.rb +2 -0
  70. data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
  71. data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
  72. data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +29 -0
  73. data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
  74. data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
  75. data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
  76. data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
  77. data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
  78. data/lib/aws-sdk-core/plugins/recursion_detection.rb +27 -0
  79. data/lib/aws-sdk-core/plugins/regional_endpoint.rb +76 -16
  80. data/lib/aws-sdk-core/plugins/response_paging.rb +3 -1
  81. data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +139 -0
  82. data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +100 -0
  83. data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +146 -0
  84. data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +59 -0
  85. data/lib/aws-sdk-core/plugins/retry_errors.rb +334 -78
  86. data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -0
  87. data/lib/aws-sdk-core/plugins/signature_v4.rb +33 -28
  88. data/lib/aws-sdk-core/plugins/stub_responses.rb +31 -7
  89. data/lib/aws-sdk-core/plugins/transfer_encoding.rb +53 -0
  90. data/lib/aws-sdk-core/plugins/user_agent.rb +9 -5
  91. data/lib/aws-sdk-core/process_credentials.rb +81 -0
  92. data/lib/aws-sdk-core/query/ec2_param_builder.rb +11 -3
  93. data/lib/aws-sdk-core/query/handler.rb +8 -1
  94. data/lib/aws-sdk-core/query/param.rb +2 -0
  95. data/lib/aws-sdk-core/query/param_builder.rb +11 -3
  96. data/lib/aws-sdk-core/query/param_list.rb +2 -0
  97. data/lib/aws-sdk-core/query.rb +2 -0
  98. data/lib/aws-sdk-core/refreshing_credentials.rb +16 -3
  99. data/lib/aws-sdk-core/resources/collection.rb +7 -5
  100. data/lib/aws-sdk-core/rest/handler.rb +2 -0
  101. data/lib/aws-sdk-core/rest/request/body.rb +21 -1
  102. data/lib/aws-sdk-core/rest/request/builder.rb +4 -1
  103. data/lib/aws-sdk-core/rest/request/endpoint.rb +13 -6
  104. data/lib/aws-sdk-core/rest/request/headers.rb +30 -6
  105. data/lib/aws-sdk-core/rest/request/querystring_builder.rb +17 -2
  106. data/lib/aws-sdk-core/rest/response/body.rb +16 -1
  107. data/lib/aws-sdk-core/rest/response/headers.rb +8 -3
  108. data/lib/aws-sdk-core/rest/response/parser.rb +7 -1
  109. data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
  110. data/lib/aws-sdk-core/rest.rb +2 -0
  111. data/lib/aws-sdk-core/shared_config.rb +204 -68
  112. data/lib/aws-sdk-core/shared_credentials.rb +9 -1
  113. data/lib/aws-sdk-core/sso_credentials.rb +136 -0
  114. data/lib/aws-sdk-core/structure.rb +18 -3
  115. data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
  116. data/lib/aws-sdk-core/stubbing/empty_stub.rb +6 -1
  117. data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +10 -0
  118. data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
  119. data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
  120. data/lib/aws-sdk-core/stubbing/protocols/query.rb +4 -2
  121. data/lib/aws-sdk-core/stubbing/protocols/rest.rb +120 -2
  122. data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +8 -2
  123. data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +11 -7
  124. data/lib/aws-sdk-core/stubbing/stub_data.rb +15 -4
  125. data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
  126. data/lib/aws-sdk-core/type_builder.rb +2 -0
  127. data/lib/aws-sdk-core/util.rb +34 -1
  128. data/lib/aws-sdk-core/waiters/errors.rb +2 -0
  129. data/lib/aws-sdk-core/waiters/poller.rb +2 -0
  130. data/lib/aws-sdk-core/waiters/waiter.rb +4 -2
  131. data/lib/aws-sdk-core/waiters.rb +2 -0
  132. data/lib/aws-sdk-core/xml/builder.rb +14 -6
  133. data/lib/aws-sdk-core/xml/default_list.rb +2 -0
  134. data/lib/aws-sdk-core/xml/default_map.rb +2 -0
  135. data/lib/aws-sdk-core/xml/doc_builder.rb +15 -4
  136. data/lib/aws-sdk-core/xml/error_handler.rb +29 -4
  137. data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
  138. data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
  139. data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
  140. data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
  141. data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +4 -1
  142. data/lib/aws-sdk-core/xml/parser/frame.rb +30 -5
  143. data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
  144. data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
  145. data/lib/aws-sdk-core/xml/parser.rb +7 -0
  146. data/lib/aws-sdk-core/xml.rb +2 -0
  147. data/lib/aws-sdk-core.rb +39 -5
  148. data/lib/aws-sdk-sso/client.rb +570 -0
  149. data/lib/aws-sdk-sso/client_api.rb +190 -0
  150. data/lib/aws-sdk-sso/customizations.rb +1 -0
  151. data/lib/aws-sdk-sso/errors.rb +102 -0
  152. data/lib/aws-sdk-sso/resource.rb +26 -0
  153. data/lib/aws-sdk-sso/types.rb +352 -0
  154. data/lib/aws-sdk-sso.rb +55 -0
  155. data/lib/aws-sdk-sts/client.rb +1474 -598
  156. data/lib/aws-sdk-sts/client_api.rb +81 -1
  157. data/lib/aws-sdk-sts/customizations.rb +4 -0
  158. data/lib/aws-sdk-sts/errors.rb +153 -1
  159. data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +38 -0
  160. data/lib/aws-sdk-sts/presigner.rb +75 -0
  161. data/lib/aws-sdk-sts/resource.rb +4 -1
  162. data/lib/aws-sdk-sts/types.rb +1005 -251
  163. data/lib/aws-sdk-sts.rb +16 -6
  164. data/lib/seahorse/client/async_base.rb +52 -0
  165. data/lib/seahorse/client/async_response.rb +64 -0
  166. data/lib/seahorse/client/base.rb +7 -2
  167. data/lib/seahorse/client/block_io.rb +6 -2
  168. data/lib/seahorse/client/configuration.rb +16 -2
  169. data/lib/seahorse/client/events.rb +3 -1
  170. data/lib/seahorse/client/h2/connection.rb +250 -0
  171. data/lib/seahorse/client/h2/handler.rb +152 -0
  172. data/lib/seahorse/client/handler.rb +2 -0
  173. data/lib/seahorse/client/handler_builder.rb +2 -0
  174. data/lib/seahorse/client/handler_list.rb +2 -0
  175. data/lib/seahorse/client/handler_list_entry.rb +6 -4
  176. data/lib/seahorse/client/http/async_response.rb +44 -0
  177. data/lib/seahorse/client/http/headers.rb +2 -0
  178. data/lib/seahorse/client/http/request.rb +5 -3
  179. data/lib/seahorse/client/http/response.rb +18 -11
  180. data/lib/seahorse/client/logging/formatter.rb +6 -2
  181. data/lib/seahorse/client/logging/handler.rb +2 -0
  182. data/lib/seahorse/client/managed_file.rb +2 -0
  183. data/lib/seahorse/client/net_http/connection_pool.rb +43 -27
  184. data/lib/seahorse/client/net_http/handler.rb +27 -7
  185. data/lib/seahorse/client/net_http/patches.rb +17 -79
  186. data/lib/seahorse/client/networking_error.rb +30 -0
  187. data/lib/seahorse/client/plugin.rb +10 -7
  188. data/lib/seahorse/client/plugin_list.rb +2 -0
  189. data/lib/seahorse/client/plugins/content_length.rb +14 -3
  190. data/lib/seahorse/client/plugins/endpoint.rb +4 -2
  191. data/lib/seahorse/client/plugins/h2.rb +69 -0
  192. data/lib/seahorse/client/plugins/logging.rb +2 -0
  193. data/lib/seahorse/client/plugins/net_http.rb +39 -3
  194. data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
  195. data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
  196. data/lib/seahorse/client/plugins/request_callback.rb +110 -0
  197. data/lib/seahorse/client/plugins/response_target.rb +26 -10
  198. data/lib/seahorse/client/request.rb +2 -0
  199. data/lib/seahorse/client/request_context.rb +7 -0
  200. data/lib/seahorse/client/response.rb +5 -5
  201. data/lib/seahorse/model/api.rb +39 -0
  202. data/lib/seahorse/model/authorizer.rb +23 -0
  203. data/lib/seahorse/model/operation.rb +28 -0
  204. data/lib/seahorse/model/shapes.rb +53 -0
  205. data/lib/seahorse/util.rb +9 -2
  206. data/lib/seahorse/version.rb +2 -0
  207. data/lib/seahorse.rb +13 -0
  208. metadata +99 -12
  209. data/lib/aws-sdk-core/version.rb +0 -3
@@ -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,7 +1,9 @@
1
- module Aws
1
+ # frozen_string_literal: true
2
2
 
3
+ module Aws
3
4
  # @api private
4
5
  class SharedConfig
6
+ SSO_PROFILE_KEYS = %w[sso_start_url sso_region sso_account_id sso_role_name].freeze
5
7
 
6
8
  # @return [String]
7
9
  attr_reader :credentials_path
@@ -20,7 +22,11 @@ module Aws
20
22
  # `~/.aws/credentials`) and the shared config file (the default path for
21
23
  # which is `~/.aws/config`) are loaded. However, if you set the
22
24
  # `ENV['AWS_SDK_CONFIG_OPT_OUT']` environment variable, only the shared
23
- # credential file will be loaded.
25
+ # credential file will be loaded. You can specify the shared credential
26
+ # file path with the `ENV['AWS_SHARED_CREDENTIALS_FILE']` environment
27
+ # variable or with the `:credentials_path` option. Similarly, you can
28
+ # specify the shared config file path with the `ENV['AWS_CONFIG_FILE']`
29
+ # environment variable or with the `:config_path` option.
24
30
  #
25
31
  # The default profile name is 'default'. You can specify the profile name
26
32
  # with the `ENV['AWS_PROFILE']` environment variable or with the
@@ -28,9 +34,11 @@ module Aws
28
34
  #
29
35
  # @param [Hash] options
30
36
  # @option options [String] :credentials_path Path to the shared credentials
31
- # file. Defaults to "#{Dir.home}/.aws/credentials".
37
+ # file. If not specified, will check `ENV['AWS_SHARED_CREDENTIALS_FILE']`
38
+ # before using the default value of "#{Dir.home}/.aws/credentials".
32
39
  # @option options [String] :config_path Path to the shared config file.
33
- # Defaults to "#{Dir.home}/.aws/config".
40
+ # If not specified, will check `ENV['AWS_CONFIG_FILE']` before using the
41
+ # default value of "#{Dir.home}/.aws/config".
34
42
  # @option options [String] :profile_name The credential/config profile name
35
43
  # to use. If not specified, will check `ENV['AWS_PROFILE']` before using
36
44
  # the fixed default value of 'default'.
@@ -38,10 +46,11 @@ module Aws
38
46
  # file and enables new config values outside of the old shared credential
39
47
  # spec.
40
48
  def initialize(options = {})
49
+ @parsed_config = nil
41
50
  @profile_name = determine_profile(options)
42
51
  @config_enabled = options[:config_enabled]
43
52
  @credentials_path = options[:credentials_path] ||
44
- determine_credentials_path
53
+ determine_credentials_path
45
54
  @parsed_credentials = {}
46
55
  load_credentials_file if loadable?(@credentials_path)
47
56
  if @config_enabled
@@ -60,7 +69,7 @@ module Aws
60
69
  @config_enabled = options[:config_enabled] ? true : false
61
70
  @profile_name = determine_profile(options)
62
71
  @credentials_path = options[:credentials_path] ||
63
- determine_credentials_path
72
+ determine_credentials_path
64
73
  load_credentials_file if loadable?(@credentials_path)
65
74
  if @config_enabled
66
75
  @config_path = options[:config_path] || determine_config_path
@@ -91,13 +100,11 @@ module Aws
91
100
  # or `nil` if no valid credentials were found.
92
101
  def credentials(opts = {})
93
102
  p = opts[:profile] || @profile_name
94
- validate_profile_exists(p) if credentials_present?
95
- if credentials = credentials_from_shared(p, opts)
103
+ validate_profile_exists(p)
104
+ if (credentials = credentials_from_shared(p, opts))
96
105
  credentials
97
- elsif credentials = credentials_from_config(p, opts)
106
+ elsif (credentials = credentials_from_config(p, opts))
98
107
  credentials
99
- else
100
- nil
101
108
  end
102
109
  end
103
110
 
@@ -106,77 +113,215 @@ module Aws
106
113
  # file, if present.
107
114
  def assume_role_credentials_from_config(opts = {})
108
115
  p = opts.delete(:profile) || @profile_name
109
- credentials = assume_role_from_profile(@parsed_credentials, p, opts)
116
+ chain_config = opts.delete(:chain_config)
117
+ credentials = assume_role_from_profile(@parsed_credentials, p, opts, chain_config)
110
118
  if @parsed_config
111
- credentials ||= assume_role_from_profile(@parsed_config, p, opts)
119
+ credentials ||= assume_role_from_profile(@parsed_config, p, opts, chain_config)
112
120
  end
113
121
  credentials
114
122
  end
115
123
 
116
- def region(opts = {})
124
+ def assume_role_web_identity_credentials_from_config(opts = {})
117
125
  p = opts[:profile] || @profile_name
118
- if @config_enabled
119
- if @parsed_credentials
120
- region = @parsed_credentials.fetch(p, {})["region"]
121
- end
122
- if @parsed_config
123
- region ||= @parsed_config.fetch(p, {})["region"]
126
+ if @config_enabled && @parsed_config
127
+ entry = @parsed_config.fetch(p, {})
128
+ if entry['web_identity_token_file'] && entry['role_arn']
129
+ cfg = {
130
+ role_arn: entry['role_arn'],
131
+ web_identity_token_file: entry['web_identity_token_file'],
132
+ role_session_name: entry['role_session_name']
133
+ }
134
+ cfg[:region] = opts[:region] if opts[:region]
135
+ AssumeRoleWebIdentityCredentials.new(cfg)
124
136
  end
125
- region
126
- else
127
- nil
128
137
  end
129
138
  end
130
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
+
152
+ # Add an accessor method (similar to attr_reader) to return a configuration value
153
+ # Uses the get_config_value below to control where
154
+ # values are loaded from
155
+ def self.config_reader(*attrs)
156
+ attrs.each do |attr|
157
+ define_method(attr) { |opts = {}| get_config_value(attr.to_s, opts) }
158
+ end
159
+ end
160
+
161
+ config_reader(
162
+ :region,
163
+ :ca_bundle,
164
+ :credential_process,
165
+ :endpoint_discovery_enabled,
166
+ :use_dualstack_endpoint,
167
+ :use_fips_endpoint,
168
+ :ec2_metadata_service_endpoint,
169
+ :ec2_metadata_service_endpoint_mode,
170
+ :max_attempts,
171
+ :retry_mode,
172
+ :adaptive_retry_wait_to_fill,
173
+ :correct_clock_skew,
174
+ :csm_client_id,
175
+ :csm_enabled,
176
+ :csm_host,
177
+ :csm_port,
178
+ :sts_regional_endpoints,
179
+ :s3_use_arn_region,
180
+ :s3_us_east_1_regional_endpoint,
181
+ :s3_disable_multiregion_access_points,
182
+ :defaults_mode
183
+ )
184
+
131
185
  private
132
- def credentials_present?
133
- (@parsed_credentials && !@parsed_credentials.empty?) ||
134
- (@parsed_config && !@parsed_config.empty?)
186
+
187
+ # Get a config value from from shared credential/config files.
188
+ # Only loads a value when config_enabled is true
189
+ # Return a value from credentials preferentially over config
190
+ def get_config_value(key, opts)
191
+ p = opts[:profile] || @profile_name
192
+
193
+ value = @parsed_credentials.fetch(p, {})[key] if @parsed_credentials
194
+ value ||= @parsed_config.fetch(p, {})[key] if @config_enabled && @parsed_config
195
+ value
135
196
  end
136
- def assume_role_from_profile(cfg, profile, opts)
197
+
198
+ def assume_role_from_profile(cfg, profile, opts, chain_config)
137
199
  if cfg && prof_cfg = cfg[profile]
138
- opts[:source_profile] ||= prof_cfg["source_profile"]
139
- if opts[:source_profile]
140
- opts[:credentials] = credentials(profile: opts[:source_profile])
200
+ opts[:source_profile] ||= prof_cfg['source_profile']
201
+ credential_source = opts.delete(:credential_source)
202
+ credential_source ||= prof_cfg['credential_source']
203
+ if opts[:source_profile] && credential_source
204
+ raise Errors::CredentialSourceConflictError,
205
+ "Profile #{profile} has a source_profile, and "\
206
+ 'a credential_source. For assume role credentials, must '\
207
+ 'provide only source_profile or credential_source, not both.'
208
+ elsif opts[:source_profile]
209
+ opts[:visited_profiles] ||= Set.new
210
+ opts[:credentials] = resolve_source_profile(opts[:source_profile], opts)
141
211
  if opts[:credentials]
142
- opts[:role_session_name] ||= prof_cfg["role_session_name"]
143
- opts[:role_session_name] ||= "default_session"
144
- opts[:role_arn] ||= prof_cfg["role_arn"]
145
- opts[:external_id] ||= prof_cfg["external_id"]
146
- opts[:serial_number] ||= prof_cfg["mfa_serial"]
212
+ opts[:role_session_name] ||= prof_cfg['role_session_name']
213
+ opts[:role_session_name] ||= 'default_session'
214
+ opts[:role_arn] ||= prof_cfg['role_arn']
215
+ opts[:duration_seconds] ||= prof_cfg['duration_seconds']
216
+ opts[:external_id] ||= prof_cfg['external_id']
217
+ opts[:serial_number] ||= prof_cfg['mfa_serial']
147
218
  opts[:profile] = opts.delete(:source_profile)
219
+ opts.delete(:visited_profiles)
148
220
  AssumeRoleCredentials.new(opts)
149
221
  else
150
- raise Errors::NoSourceProfileError.new(
222
+ raise Errors::NoSourceProfileError,
151
223
  "Profile #{profile} has a role_arn, and source_profile, but the"\
152
- " source_profile does not have credentials."
153
- )
224
+ ' source_profile does not have credentials.'
154
225
  end
155
- elsif prof_cfg["role_arn"]
156
- raise Errors::NoSourceProfileError.new(
157
- "Profile #{profile} has a role_arn, but no source_profile."
226
+ elsif credential_source
227
+ opts[:credentials] = credentials_from_source(
228
+ credential_source,
229
+ chain_config
158
230
  )
159
- else
160
- nil
231
+ if opts[:credentials]
232
+ opts[:role_session_name] ||= prof_cfg['role_session_name']
233
+ opts[:role_session_name] ||= 'default_session'
234
+ opts[:role_arn] ||= prof_cfg['role_arn']
235
+ opts[:duration_seconds] ||= prof_cfg['duration_seconds']
236
+ opts[:external_id] ||= prof_cfg['external_id']
237
+ opts[:serial_number] ||= prof_cfg['mfa_serial']
238
+ opts.delete(:source_profile) # Cleanup
239
+ AssumeRoleCredentials.new(opts)
240
+ else
241
+ raise Errors::NoSourceCredentials,
242
+ "Profile #{profile} could not get source credentials from"\
243
+ " provider #{credential_source}"
244
+ end
245
+ elsif prof_cfg['role_arn']
246
+ raise Errors::NoSourceProfileError, "Profile #{profile} has a role_arn, but no source_profile."
161
247
  end
248
+ end
249
+ end
250
+
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
+
262
+ if (creds = credentials(profile: profile))
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))
267
+ elsif (provider = assume_role_web_identity_credentials_from_config(opts.merge(profile: profile)))
268
+ provider.credentials if provider.credentials.set?
269
+ elsif (provider = assume_role_process_credentials_from_config(profile))
270
+ provider.credentials if provider.credentials.set?
271
+ elsif (provider = sso_credentials_from_config(profile: profile))
272
+ provider.credentials if provider.credentials.set?
273
+ end
274
+ end
275
+
276
+ def credentials_from_source(credential_source, config)
277
+ case credential_source
278
+ when 'Ec2InstanceMetadata'
279
+ InstanceProfileCredentials.new(
280
+ retries: config ? config.instance_profile_credentials_retries : 0,
281
+ http_open_timeout: config ? config.instance_profile_credentials_timeout : 1,
282
+ http_read_timeout: config ? config.instance_profile_credentials_timeout : 1
283
+ )
284
+ when 'EcsContainer'
285
+ ECSCredentials.new
162
286
  else
163
- nil
287
+ raise Errors::InvalidCredentialSourceError, "Unsupported credential_source: #{credential_source}"
288
+ end
289
+ end
290
+
291
+ def assume_role_process_credentials_from_config(profile)
292
+ validate_profile_exists(profile)
293
+ credential_process = @parsed_credentials.fetch(profile, {})['credential_process']
294
+ if @parsed_config
295
+ credential_process ||= @parsed_config.fetch(profile, {})['credential_process']
164
296
  end
297
+ ProcessCredentials.new(credential_process) if credential_process
165
298
  end
166
299
 
167
- def credentials_from_shared(profile, opts)
300
+ def credentials_from_shared(profile, _opts)
168
301
  if @parsed_credentials && prof_config = @parsed_credentials[profile]
169
302
  credentials_from_profile(prof_config)
170
- else
171
- nil
172
303
  end
173
304
  end
174
305
 
175
- def credentials_from_config(profile, opts)
306
+ def credentials_from_config(profile, _opts)
176
307
  if @parsed_config && prof_config = @parsed_config[profile]
177
308
  credentials_from_profile(prof_config)
178
- else
179
- nil
309
+ end
310
+ end
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
+ )
180
325
  end
181
326
  end
182
327
 
@@ -186,15 +331,7 @@ module Aws
186
331
  prof_config['aws_secret_access_key'],
187
332
  prof_config['aws_session_token']
188
333
  )
189
- if credentials_complete(creds)
190
- creds
191
- else
192
- nil
193
- end
194
- end
195
-
196
- def credentials_complete(creds)
197
- creds.set?
334
+ creds if creds.set?
198
335
  end
199
336
 
200
337
  def load_credentials_file
@@ -208,11 +345,11 @@ module Aws
208
345
  end
209
346
 
210
347
  def determine_credentials_path
211
- default = default_shared_config_path('credentials')
348
+ ENV['AWS_SHARED_CREDENTIALS_FILE'] || default_shared_config_path('credentials')
212
349
  end
213
350
 
214
351
  def determine_config_path
215
- default = default_shared_config_path('config')
352
+ ENV['AWS_CONFIG_FILE'] || default_shared_config_path('config')
216
353
  end
217
354
 
218
355
  def default_shared_config_path(file)
@@ -224,19 +361,18 @@ module Aws
224
361
 
225
362
  def validate_profile_exists(profile)
226
363
  unless (@parsed_credentials && @parsed_credentials[profile]) ||
227
- (@parsed_config && @parsed_config[profile])
228
- msg = "Profile `#{profile}' not found in #{@credentials_path}"
229
- msg << " or #{@config_path}" if @config_path
230
- raise Errors::NoSuchProfileError.new(msg)
364
+ (@parsed_config && @parsed_config[profile])
365
+ msg = "Profile `#{profile}' not found in #{@credentials_path}"\
366
+ "#{" or #{@config_path}" if @config_path}"
367
+ raise Errors::NoSuchProfileError, msg
231
368
  end
232
369
  end
233
370
 
234
371
  def determine_profile(options)
235
372
  ret = options[:profile_name]
236
- ret ||= ENV["AWS_PROFILE"]
237
- ret ||= "default"
373
+ ret ||= ENV['AWS_PROFILE']
374
+ ret ||= 'default'
238
375
  ret
239
376
  end
240
-
241
377
  end
242
378
  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,136 @@
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
+ super
90
+ end
91
+
92
+ # @return [SSO::Client]
93
+ attr_reader :client
94
+
95
+ private
96
+
97
+ def read_cached_token
98
+ cached_token = Json.load(File.read(sso_cache_file))
99
+ # validation
100
+ unless cached_token['accessToken'] && cached_token['expiresAt']
101
+ raise ArgumentError, 'Missing required field(s)'
102
+ end
103
+ expires_at = DateTime.parse(cached_token['expiresAt'])
104
+ if expires_at < DateTime.now
105
+ raise ArgumentError, 'Cached SSO Token is expired.'
106
+ end
107
+ cached_token
108
+ rescue Errno::ENOENT, Aws::Json::ParseError, ArgumentError
109
+ raise Errors::InvalidSSOCredentials, SSO_LOGIN_GUIDANCE
110
+ end
111
+
112
+ def refresh
113
+ cached_token = read_cached_token
114
+ c = @client.get_role_credentials(
115
+ account_id: @sso_account_id,
116
+ role_name: @sso_role_name,
117
+ access_token: cached_token['accessToken']
118
+ ).role_credentials
119
+
120
+ @credentials = Credentials.new(
121
+ c.access_key_id,
122
+ c.secret_access_key,
123
+ c.session_token
124
+ )
125
+ @expiration = c.expiration
126
+ end
127
+
128
+ def sso_cache_file
129
+ start_url_sha1 = OpenSSL::Digest::SHA1.hexdigest(@sso_start_url.encode('utf-8'))
130
+ File.join(Dir.home, '.aws', 'sso', 'cache', "#{start_url_sha1}.json")
131
+ rescue ArgumentError
132
+ # Dir.home raises ArgumentError when ENV['home'] is not set
133
+ raise ArgumentError, "Unable to load sso_cache_file: ENV['HOME'] is not set."
134
+ end
135
+ end
136
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Aws
2
4
  # @api private
3
5
  module Structure
@@ -29,8 +31,7 @@ module Aws
29
31
  def to_h(obj = self)
30
32
  case obj
31
33
  when Struct
32
- obj.members.each.with_object({}) do |member, hash|
33
- value = obj[member]
34
+ obj.each_pair.with_object({}) do |(member, value), hash|
34
35
  hash[member] = to_hash(value) unless value.nil?
35
36
  end
36
37
  when Hash
@@ -45,6 +46,11 @@ module Aws
45
46
  end
46
47
  alias to_hash to_h
47
48
 
49
+ # Wraps the default #to_s logic with filtering of sensitive parameters.
50
+ def to_s(obj = self)
51
+ Aws::Log::ParamFilter.new.filter(obj, obj.class).to_s
52
+ end
53
+
48
54
  class << self
49
55
 
50
56
  # @api private
@@ -64,11 +70,20 @@ module Aws
64
70
  end
65
71
 
66
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
67
83
  end
68
84
 
69
85
  # @api private
70
86
  class EmptyStructure < Struct.new('AwsEmptyStructure')
71
87
  include(Aws::Structure)
72
88
  end
73
-
74
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
@@ -36,7 +38,10 @@ module Aws
36
38
 
37
39
  def stub_structure(ref, visited)
38
40
  ref.shape.members.inject(ref.shape.struct_class.new) do |struct, (mname, mref)|
39
- struct[mname] = stub_ref(mref, visited)
41
+ # For eventstream shape, it returns an Enumerator
42
+ unless mref.eventstream
43
+ struct[mname] = stub_ref(mref, visited)
44
+ end
40
45
  struct
41
46
  end
42
47
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws
4
+ module Stubbing
5
+ module Protocols
6
+ class ApiGateway < RestJson
7
+ end
8
+ end
9
+ end
10
+ end
@@ -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
@@ -23,9 +25,9 @@ module Aws
23
25
  xml = []
24
26
  builder = Aws::Xml::DocBuilder.new(target: xml, indent: ' ')
25
27
  builder.node(operation.name + 'Response', xmlns: xmlns(api)) do
26
- if rules = operation.output
28
+ if (rules = operation.output)
27
29
  rules.location_name = operation.name + 'Result'
28
- Xml::Builder.new(rules, target:xml, pad:' ').to_xml(data)
30
+ Xml::Builder.new(rules, target: xml, pad:' ').to_xml(data)
29
31
  end
30
32
  builder.node('ResponseMetadata') do
31
33
  builder.node('RequestId', 'stubbed-request-id')