aws-sdk-core 3.117.0 → 3.197.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +836 -0
- data/VERSION +1 -1
- data/lib/aws-defaults/default_configuration.rb +153 -0
- data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
- data/lib/aws-defaults.rb +3 -0
- data/lib/aws-sdk-core/arn.rb +13 -0
- data/lib/aws-sdk-core/assume_role_credentials.rb +21 -7
- data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +14 -10
- data/lib/aws-sdk-core/binary/decode_handler.rb +0 -5
- data/lib/aws-sdk-core/binary/encode_handler.rb +12 -1
- data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
- data/lib/aws-sdk-core/client_stubs.rb +20 -13
- data/lib/aws-sdk-core/credential_provider.rb +4 -1
- data/lib/aws-sdk-core/credential_provider_chain.rb +8 -5
- data/lib/aws-sdk-core/ec2_metadata.rb +4 -3
- data/lib/aws-sdk-core/ecs_credentials.rb +187 -52
- data/lib/aws-sdk-core/endpoints/condition.rb +41 -0
- data/lib/aws-sdk-core/endpoints/endpoint.rb +17 -0
- data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +75 -0
- data/lib/aws-sdk-core/endpoints/error_rule.rb +42 -0
- data/lib/aws-sdk-core/endpoints/function.rb +80 -0
- data/lib/aws-sdk-core/endpoints/matchers.rb +135 -0
- data/lib/aws-sdk-core/endpoints/reference.rb +31 -0
- data/lib/aws-sdk-core/endpoints/rule.rb +25 -0
- data/lib/aws-sdk-core/endpoints/rule_set.rb +52 -0
- data/lib/aws-sdk-core/endpoints/rules_provider.rb +37 -0
- data/lib/aws-sdk-core/endpoints/templater.rb +58 -0
- data/lib/aws-sdk-core/endpoints/tree_rule.rb +45 -0
- data/lib/aws-sdk-core/endpoints/url.rb +60 -0
- data/lib/aws-sdk-core/endpoints.rb +78 -0
- data/lib/aws-sdk-core/errors.rb +17 -4
- data/lib/aws-sdk-core/event_emitter.rb +0 -16
- data/lib/aws-sdk-core/ini_parser.rb +7 -0
- data/lib/aws-sdk-core/instance_profile_credentials.rb +127 -33
- data/lib/aws-sdk-core/json/builder.rb +8 -1
- data/lib/aws-sdk-core/json/error_handler.rb +30 -4
- data/lib/aws-sdk-core/json/handler.rb +8 -1
- data/lib/aws-sdk-core/json/json_engine.rb +10 -8
- data/lib/aws-sdk-core/json/oj_engine.rb +33 -6
- data/lib/aws-sdk-core/json/parser.rb +38 -2
- data/lib/aws-sdk-core/json.rb +8 -26
- data/lib/aws-sdk-core/log/formatter.rb +6 -0
- data/lib/aws-sdk-core/log/param_filter.rb +9 -1
- data/lib/aws-sdk-core/lru_cache.rb +75 -0
- data/lib/aws-sdk-core/pageable_response.rb +81 -32
- data/lib/aws-sdk-core/param_validator.rb +36 -2
- data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
- data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +342 -0
- data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +1 -0
- data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
- data/lib/aws-sdk-core/plugins/credentials_configuration.rb +29 -1
- data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
- data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +6 -2
- data/lib/aws-sdk-core/plugins/http_checksum.rb +9 -1
- data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
- data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +34 -6
- data/lib/aws-sdk-core/plugins/logging.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +17 -0
- data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +4 -2
- data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +1 -2
- data/lib/aws-sdk-core/plugins/recursion_detection.rb +38 -0
- data/lib/aws-sdk-core/plugins/regional_endpoint.rb +144 -17
- data/lib/aws-sdk-core/plugins/request_compression.rb +226 -0
- data/lib/aws-sdk-core/plugins/response_paging.rb +1 -1
- data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +7 -4
- data/lib/aws-sdk-core/plugins/retry_errors.rb +33 -7
- data/lib/aws-sdk-core/plugins/sign.rb +211 -0
- data/lib/aws-sdk-core/plugins/signature_v2.rb +1 -0
- data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -31
- data/lib/aws-sdk-core/plugins/stub_responses.rb +6 -1
- data/lib/aws-sdk-core/plugins/user_agent.rb +152 -14
- data/lib/aws-sdk-core/process_credentials.rb +50 -34
- data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
- data/lib/aws-sdk-core/query/param_builder.rb +2 -2
- data/lib/aws-sdk-core/refreshing_credentials.rb +49 -18
- data/lib/aws-sdk-core/refreshing_token.rb +71 -0
- data/lib/aws-sdk-core/rest/handler.rb +1 -1
- data/lib/aws-sdk-core/rest/request/body.rb +49 -4
- data/lib/aws-sdk-core/rest/request/content_type.rb +60 -0
- data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
- data/lib/aws-sdk-core/rest/request/headers.rb +23 -7
- data/lib/aws-sdk-core/rest/request/querystring_builder.rb +62 -36
- data/lib/aws-sdk-core/rest/response/body.rb +15 -1
- data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
- data/lib/aws-sdk-core/rest/response/headers.rb +10 -3
- data/lib/aws-sdk-core/rest.rb +1 -0
- data/lib/aws-sdk-core/shared_config.rb +112 -12
- data/lib/aws-sdk-core/sso_credentials.rb +92 -51
- data/lib/aws-sdk-core/sso_token_provider.rb +135 -0
- data/lib/aws-sdk-core/static_token_provider.rb +14 -0
- data/lib/aws-sdk-core/structure.rb +16 -5
- data/lib/aws-sdk-core/stubbing/stub_data.rb +11 -0
- data/lib/aws-sdk-core/token.rb +31 -0
- data/lib/aws-sdk-core/token_provider.rb +15 -0
- data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
- data/lib/aws-sdk-core/util.rb +39 -0
- data/lib/aws-sdk-core/waiters/poller.rb +4 -2
- data/lib/aws-sdk-core/xml/builder.rb +17 -9
- data/lib/aws-sdk-core/xml/error_handler.rb +31 -8
- data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/engines/ox.rb +1 -1
- data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +0 -8
- data/lib/aws-sdk-core/xml/parser/frame.rb +27 -20
- data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
- data/lib/aws-sdk-core.rb +21 -0
- data/lib/aws-sdk-sso/client.rb +157 -50
- data/lib/aws-sdk-sso/endpoint_parameters.rb +66 -0
- data/lib/aws-sdk-sso/endpoint_provider.rb +57 -0
- data/lib/aws-sdk-sso/endpoints.rb +72 -0
- data/lib/aws-sdk-sso/plugins/endpoints.rb +78 -0
- data/lib/aws-sdk-sso/types.rb +8 -43
- data/lib/aws-sdk-sso.rb +5 -1
- data/lib/aws-sdk-ssooidc/client.rb +1008 -0
- data/lib/aws-sdk-ssooidc/client_api.rb +293 -0
- data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
- data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +66 -0
- data/lib/aws-sdk-ssooidc/endpoint_provider.rb +57 -0
- data/lib/aws-sdk-ssooidc/endpoints.rb +72 -0
- data/lib/aws-sdk-ssooidc/errors.rb +342 -0
- data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +78 -0
- data/lib/aws-sdk-ssooidc/resource.rb +26 -0
- data/lib/aws-sdk-ssooidc/types.rb +823 -0
- data/lib/aws-sdk-ssooidc.rb +59 -0
- data/lib/aws-sdk-sts/client.rb +472 -398
- data/lib/aws-sdk-sts/client_api.rb +20 -9
- data/lib/aws-sdk-sts/endpoint_parameters.rb +78 -0
- data/lib/aws-sdk-sts/endpoint_provider.rb +112 -0
- data/lib/aws-sdk-sts/endpoints.rb +136 -0
- data/lib/aws-sdk-sts/plugins/endpoints.rb +86 -0
- data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +5 -1
- data/lib/aws-sdk-sts/presigner.rb +14 -10
- data/lib/aws-sdk-sts/types.rb +168 -227
- data/lib/aws-sdk-sts.rb +5 -1
- data/lib/seahorse/client/async_base.rb +1 -2
- data/lib/seahorse/client/async_response.rb +19 -0
- data/lib/seahorse/client/base.rb +1 -0
- data/lib/seahorse/client/configuration.rb +5 -5
- data/lib/seahorse/client/h2/connection.rb +15 -16
- data/lib/seahorse/client/h2/handler.rb +5 -5
- data/lib/seahorse/client/net_http/connection_pool.rb +10 -9
- data/lib/seahorse/client/net_http/handler.rb +15 -7
- data/lib/seahorse/client/net_http/patches.rb +12 -86
- data/lib/seahorse/client/plugin.rb +9 -0
- data/lib/seahorse/client/plugins/content_length.rb +11 -5
- data/lib/seahorse/client/plugins/h2.rb +3 -3
- data/lib/seahorse/client/plugins/net_http.rb +73 -10
- data/lib/seahorse/client/plugins/request_callback.rb +40 -9
- data/lib/seahorse/client/response.rb +6 -0
- data/lib/seahorse/model/operation.rb +6 -0
- data/lib/seahorse/model/shapes.rb +27 -2
- data/lib/seahorse/util.rb +4 -0
- data/sig/aws-sdk-core/client_stubs.rbs +10 -0
- data/sig/aws-sdk-core/errors.rbs +22 -0
- data/sig/aws-sdk-core/resources/collection.rbs +21 -0
- data/sig/aws-sdk-core/structure.rbs +4 -0
- data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
- data/sig/aws-sdk-core.rbs +7 -0
- data/sig/seahorse/client/base.rbs +25 -0
- data/sig/seahorse/client/handler_builder.rbs +16 -0
- data/sig/seahorse/client/response.rbs +61 -0
- metadata +82 -17
- data/lib/aws-sdk-sso/plugins/content_type.rb +0 -25
@@ -4,6 +4,11 @@ require 'time'
|
|
4
4
|
require 'net/http'
|
5
5
|
|
6
6
|
module Aws
|
7
|
+
# An auto-refreshing credential provider that loads credentials from
|
8
|
+
# EC2 instances.
|
9
|
+
#
|
10
|
+
# instance_credentials = Aws::InstanceProfileCredentials.new
|
11
|
+
# ec2 = Aws::EC2::Client.new(credentials: instance_credentials)
|
7
12
|
class InstanceProfileCredentials
|
8
13
|
include CredentialProvider
|
9
14
|
include RefreshingCredentials
|
@@ -48,6 +53,8 @@ module Aws
|
|
48
53
|
# @option options [String] :endpoint_mode ('IPv4') The endpoint mode for
|
49
54
|
# the instance metadata service. This is either 'IPv4' ('169.254.169.254')
|
50
55
|
# or 'IPv6' ('[fd00:ec2::254]').
|
56
|
+
# @option options [Boolean] :disable_imds_v1 (false) Disable the use of the
|
57
|
+
# legacy EC2 Metadata Service v1.
|
51
58
|
# @option options [String] :ip_address ('169.254.169.254') Deprecated. Use
|
52
59
|
# :endpoint instead. The IP address for the endpoint.
|
53
60
|
# @option options [Integer] :port (80)
|
@@ -63,17 +70,26 @@ module Aws
|
|
63
70
|
# @option options [Integer] :token_ttl Time-to-Live in seconds for EC2
|
64
71
|
# Metadata Token used for fetching Metadata Profile Credentials, defaults
|
65
72
|
# to 21600 seconds
|
73
|
+
# @option options [Callable] before_refresh Proc called before
|
74
|
+
# credentials are refreshed. `before_refresh` is called
|
75
|
+
# with an instance of this object when
|
76
|
+
# AWS credentials are required and need to be refreshed.
|
66
77
|
def initialize(options = {})
|
67
78
|
@retries = options[:retries] || 1
|
68
79
|
endpoint_mode = resolve_endpoint_mode(options)
|
69
80
|
@endpoint = resolve_endpoint(options, endpoint_mode)
|
70
81
|
@port = options[:port] || 80
|
82
|
+
@disable_imds_v1 = resolve_disable_v1(options)
|
83
|
+
# Flag for if v2 flow fails, skip future attempts
|
84
|
+
@imds_v1_fallback = false
|
71
85
|
@http_open_timeout = options[:http_open_timeout] || 1
|
72
86
|
@http_read_timeout = options[:http_read_timeout] || 1
|
73
87
|
@http_debug_output = options[:http_debug_output]
|
74
88
|
@backoff = backoff(options[:backoff])
|
75
89
|
@token_ttl = options[:token_ttl] || 21_600
|
76
90
|
@token = nil
|
91
|
+
@no_refresh_until = nil
|
92
|
+
@async_refresh = false
|
77
93
|
super
|
78
94
|
end
|
79
95
|
|
@@ -112,6 +128,16 @@ module Aws
|
|
112
128
|
end
|
113
129
|
end
|
114
130
|
|
131
|
+
def resolve_disable_v1(options)
|
132
|
+
value = options[:disable_imds_v1]
|
133
|
+
value ||= ENV['AWS_EC2_METADATA_V1_DISABLED']
|
134
|
+
value ||= Aws.shared_config.ec2_metadata_v1_disabled(
|
135
|
+
profile: options[:profile]
|
136
|
+
)
|
137
|
+
value = value.to_s.downcase if value
|
138
|
+
Aws::Util.str_2_bool(value) || false
|
139
|
+
end
|
140
|
+
|
115
141
|
def backoff(backoff)
|
116
142
|
case backoff
|
117
143
|
when Proc then backoff
|
@@ -121,18 +147,47 @@ module Aws
|
|
121
147
|
end
|
122
148
|
|
123
149
|
def refresh
|
150
|
+
if @no_refresh_until && @no_refresh_until > Time.now
|
151
|
+
warn_expired_credentials
|
152
|
+
return
|
153
|
+
end
|
154
|
+
|
124
155
|
# Retry loading credentials up to 3 times is the instance metadata
|
125
156
|
# service is responding but is returning invalid JSON documents
|
126
157
|
# in response to the GET profile credentials call.
|
127
158
|
begin
|
128
|
-
retry_errors([Aws::Json::ParseError
|
159
|
+
retry_errors([Aws::Json::ParseError], max_retries: 3) do
|
129
160
|
c = Aws::Json.load(get_credentials.to_s)
|
130
|
-
@credentials
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
161
|
+
if empty_credentials?(@credentials)
|
162
|
+
@credentials = Credentials.new(
|
163
|
+
c['AccessKeyId'],
|
164
|
+
c['SecretAccessKey'],
|
165
|
+
c['Token']
|
166
|
+
)
|
167
|
+
@expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
|
168
|
+
if @expiration && @expiration < Time.now
|
169
|
+
@no_refresh_until = Time.now + refresh_offset
|
170
|
+
warn_expired_credentials
|
171
|
+
end
|
172
|
+
else
|
173
|
+
# credentials are already set, update them only if the new ones are not empty
|
174
|
+
if !c['AccessKeyId'] || c['AccessKeyId'].empty?
|
175
|
+
# error getting new credentials
|
176
|
+
@no_refresh_until = Time.now + refresh_offset
|
177
|
+
warn_expired_credentials
|
178
|
+
else
|
179
|
+
@credentials = Credentials.new(
|
180
|
+
c['AccessKeyId'],
|
181
|
+
c['SecretAccessKey'],
|
182
|
+
c['Token']
|
183
|
+
)
|
184
|
+
@expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
|
185
|
+
if @expiration && @expiration < Time.now
|
186
|
+
@no_refresh_until = Time.now + refresh_offset
|
187
|
+
warn_expired_credentials
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
136
191
|
end
|
137
192
|
rescue Aws::Json::ParseError
|
138
193
|
raise Aws::Errors::MetadataParserError
|
@@ -150,33 +205,53 @@ module Aws
|
|
150
205
|
open_connection do |conn|
|
151
206
|
# attempt to fetch token to start secure flow first
|
152
207
|
# and rescue to failover
|
153
|
-
|
154
|
-
retry_errors(NETWORK_ERRORS, max_retries: @retries) do
|
155
|
-
unless token_set?
|
156
|
-
token_value, ttl = http_put(
|
157
|
-
conn, METADATA_TOKEN_PATH, @token_ttl
|
158
|
-
)
|
159
|
-
@token = Token.new(token_value, ttl) if token_value && ttl
|
160
|
-
end
|
161
|
-
end
|
162
|
-
rescue *NETWORK_ERRORS
|
163
|
-
# token attempt failed, reset token
|
164
|
-
# fallback to non-token mode
|
165
|
-
@token = nil
|
166
|
-
end
|
167
|
-
|
208
|
+
fetch_token(conn) unless @imds_v1_fallback
|
168
209
|
token = @token.value if token_set?
|
169
|
-
|
170
|
-
|
171
|
-
|
210
|
+
|
211
|
+
# disable insecure flow if we couldn't get token
|
212
|
+
# and imds v1 is disabled
|
213
|
+
raise TokenRetrivalError if token.nil? && @disable_imds_v1
|
214
|
+
|
215
|
+
_get_credentials(conn, token)
|
172
216
|
end
|
173
217
|
end
|
174
|
-
rescue
|
218
|
+
rescue => e
|
219
|
+
warn("Error retrieving instance profile credentials: #{e}")
|
175
220
|
'{}'
|
176
221
|
end
|
177
222
|
end
|
178
223
|
end
|
179
224
|
|
225
|
+
def fetch_token(conn)
|
226
|
+
retry_errors(NETWORK_ERRORS, max_retries: @retries) do
|
227
|
+
unless token_set?
|
228
|
+
created_time = Time.now
|
229
|
+
token_value, ttl = http_put(
|
230
|
+
conn, METADATA_TOKEN_PATH, @token_ttl
|
231
|
+
)
|
232
|
+
@token = Token.new(token_value, ttl, created_time) if token_value && ttl
|
233
|
+
end
|
234
|
+
end
|
235
|
+
rescue *NETWORK_ERRORS
|
236
|
+
# token attempt failed, reset token
|
237
|
+
# fallback to non-token mode
|
238
|
+
@token = nil
|
239
|
+
@imds_v1_fallback = true
|
240
|
+
end
|
241
|
+
|
242
|
+
# token is optional - if nil, uses v1 (insecure) flow
|
243
|
+
def _get_credentials(conn, token)
|
244
|
+
metadata = http_get(conn, METADATA_PATH_BASE, token)
|
245
|
+
profile_name = metadata.lines.first.strip
|
246
|
+
http_get(conn, METADATA_PATH_BASE + profile_name, token)
|
247
|
+
rescue TokenExpiredError
|
248
|
+
# Token has expired, reset it
|
249
|
+
# The next retry should fetch it
|
250
|
+
@token = nil
|
251
|
+
@imds_v1_fallback = false
|
252
|
+
raise Non200Response
|
253
|
+
end
|
254
|
+
|
180
255
|
def token_set?
|
181
256
|
@token && !@token.expired?
|
182
257
|
end
|
@@ -187,7 +262,7 @@ module Aws
|
|
187
262
|
|
188
263
|
def open_connection
|
189
264
|
uri = URI.parse(@endpoint)
|
190
|
-
http = Net::HTTP.new(uri.hostname || @endpoint,
|
265
|
+
http = Net::HTTP.new(uri.hostname || @endpoint, uri.port || @port)
|
191
266
|
http.open_timeout = @http_open_timeout
|
192
267
|
http.read_timeout = @http_read_timeout
|
193
268
|
http.set_debug_output(@http_debug_output) if @http_debug_output
|
@@ -200,9 +275,15 @@ module Aws
|
|
200
275
|
headers = { 'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}" }
|
201
276
|
headers['x-aws-ec2-metadata-token'] = token if token
|
202
277
|
response = connection.request(Net::HTTP::Get.new(path, headers))
|
203
|
-
raise Non200Response unless response.code.to_i == 200
|
204
278
|
|
205
|
-
response.
|
279
|
+
case response.code.to_i
|
280
|
+
when 200
|
281
|
+
response.body
|
282
|
+
when 401
|
283
|
+
raise TokenExpiredError
|
284
|
+
else
|
285
|
+
raise Non200Response
|
286
|
+
end
|
206
287
|
end
|
207
288
|
|
208
289
|
# PUT request fetch token with ttl
|
@@ -220,8 +301,6 @@ module Aws
|
|
220
301
|
]
|
221
302
|
when 400
|
222
303
|
raise TokenRetrivalError
|
223
|
-
when 401
|
224
|
-
raise TokenExpiredError
|
225
304
|
else
|
226
305
|
raise Non200Response
|
227
306
|
end
|
@@ -241,13 +320,28 @@ module Aws
|
|
241
320
|
end
|
242
321
|
end
|
243
322
|
|
323
|
+
def warn_expired_credentials
|
324
|
+
warn("Attempting credential expiration extension due to a credential "\
|
325
|
+
"service availability issue. A refresh of these credentials "\
|
326
|
+
"will be attempted again in 5 minutes.")
|
327
|
+
end
|
328
|
+
|
329
|
+
def empty_credentials?(creds)
|
330
|
+
!creds || !creds.access_key_id || creds.access_key_id.empty?
|
331
|
+
end
|
332
|
+
|
333
|
+
# Compute an offset for refresh with jitter
|
334
|
+
def refresh_offset
|
335
|
+
300 + rand(0..60)
|
336
|
+
end
|
337
|
+
|
244
338
|
# @api private
|
245
339
|
# Token used to fetch IMDS profile and credentials
|
246
340
|
class Token
|
247
|
-
def initialize(value, ttl)
|
341
|
+
def initialize(value, ttl, created_time = Time.now)
|
248
342
|
@ttl = ttl
|
249
343
|
@value = value
|
250
|
-
@created_time =
|
344
|
+
@created_time = created_time
|
251
345
|
end
|
252
346
|
|
253
347
|
# [String] token value
|
@@ -8,7 +8,7 @@ module Aws
|
|
8
8
|
|
9
9
|
include Seahorse::Model::Shapes
|
10
10
|
|
11
|
-
def initialize(rules)
|
11
|
+
def initialize(rules, _options = {})
|
12
12
|
@rules = rules
|
13
13
|
end
|
14
14
|
|
@@ -20,6 +20,8 @@ module Aws
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def structure(ref, values)
|
23
|
+
return nil if values.nil?
|
24
|
+
|
23
25
|
shape = ref.shape
|
24
26
|
values.each_pair.with_object({}) do |(key, value), data|
|
25
27
|
if shape.member?(key) && !value.nil?
|
@@ -31,11 +33,15 @@ module Aws
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def list(ref, values)
|
36
|
+
return nil if values.nil?
|
37
|
+
|
34
38
|
member_ref = ref.shape.member
|
35
39
|
values.collect { |value| format(member_ref, value) }
|
36
40
|
end
|
37
41
|
|
38
42
|
def map(ref, values)
|
43
|
+
return nil if values.nil?
|
44
|
+
|
39
45
|
value_ref = ref.shape.value
|
40
46
|
values.each.with_object({}) do |(key, value), data|
|
41
47
|
data[key] = format(value_ref, value)
|
@@ -49,6 +55,7 @@ module Aws
|
|
49
55
|
when MapShape then map(ref, value)
|
50
56
|
when TimestampShape then timestamp(ref, value)
|
51
57
|
when BlobShape then encode(value)
|
58
|
+
when FloatShape then Util.serialize_number(value)
|
52
59
|
else value
|
53
60
|
end
|
54
61
|
end
|
@@ -26,7 +26,13 @@ module Aws
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def error_code(json, context)
|
29
|
-
code =
|
29
|
+
code =
|
30
|
+
if aws_query_error?(context)
|
31
|
+
error = context.http_response.headers['x-amzn-query-error'].split(';')[0]
|
32
|
+
remove_prefix(error, context)
|
33
|
+
else
|
34
|
+
json['__type']
|
35
|
+
end
|
30
36
|
code ||= json['code']
|
31
37
|
code ||= context.http_response.headers['x-amzn-errortype']
|
32
38
|
if code
|
@@ -36,6 +42,19 @@ module Aws
|
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
45
|
+
def aws_query_error?(context)
|
46
|
+
context.config.api.metadata['awsQueryCompatible'] &&
|
47
|
+
context.http_response.headers['x-amzn-query-error']
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove_prefix(error_code, context)
|
51
|
+
if prefix = context.config.api.metadata['errorPrefix']
|
52
|
+
error_code.sub(/^#{prefix}/, '')
|
53
|
+
else
|
54
|
+
error_code
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
39
58
|
def error_message(code, json)
|
40
59
|
if code == 'RequestEntityTooLarge'
|
41
60
|
'Request body must be less than 1 MB'
|
@@ -52,14 +71,21 @@ module Aws
|
|
52
71
|
# some type(code) might contains invalid characters
|
53
72
|
# such as ':' (efs) etc
|
54
73
|
match = rule.shape.name == code.gsub(/[^^a-zA-Z0-9]/, '')
|
55
|
-
|
56
|
-
|
57
|
-
|
74
|
+
next unless match && rule.shape.members.any?
|
75
|
+
|
76
|
+
data = Parser.new(rule).parse(context.http_response.body_contents)
|
77
|
+
# errors support HTTP bindings
|
78
|
+
apply_error_headers(rule, context, data)
|
58
79
|
end
|
59
80
|
end
|
60
81
|
data
|
61
82
|
end
|
62
83
|
|
84
|
+
def apply_error_headers(rule, context, data)
|
85
|
+
headers = Aws::Rest::Response::Headers.new(rule)
|
86
|
+
headers.apply(context.http_response, data)
|
87
|
+
end
|
88
|
+
|
63
89
|
end
|
64
90
|
end
|
65
91
|
end
|
@@ -59,7 +59,10 @@ module Aws
|
|
59
59
|
end
|
60
60
|
resp_struct
|
61
61
|
else
|
62
|
-
Parser.new(
|
62
|
+
Parser.new(
|
63
|
+
rules,
|
64
|
+
query_compatible: query_compatible?(context)
|
65
|
+
).parse(json == '' ? '{}' : json)
|
63
66
|
end
|
64
67
|
else
|
65
68
|
EmptyStructure.new
|
@@ -83,6 +86,10 @@ module Aws
|
|
83
86
|
context.config.simple_json
|
84
87
|
end
|
85
88
|
|
89
|
+
def query_compatible?(context)
|
90
|
+
context.config.api.metadata.key?('awsQueryCompatible')
|
91
|
+
end
|
92
|
+
|
86
93
|
end
|
87
94
|
end
|
88
95
|
end
|
@@ -2,16 +2,18 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Json
|
5
|
-
|
5
|
+
module JSONEngine
|
6
|
+
class << self
|
7
|
+
def load(json)
|
8
|
+
JSON.parse(json)
|
9
|
+
rescue JSON::ParserError => e
|
10
|
+
raise ParseError.new(e)
|
11
|
+
end
|
6
12
|
|
7
|
-
|
8
|
-
|
13
|
+
def dump(value)
|
14
|
+
JSON.dump(value)
|
15
|
+
end
|
9
16
|
end
|
10
|
-
|
11
|
-
def self.dump(value)
|
12
|
-
JSON.dump(value)
|
13
|
-
end
|
14
|
-
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -2,16 +2,43 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Json
|
5
|
-
|
5
|
+
module OjEngine
|
6
|
+
# @api private
|
7
|
+
LOAD_OPTIONS = { mode: :compat, symbol_keys: false, empty_string: false }.freeze
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
9
|
+
# @api private
|
10
|
+
DUMP_OPTIONS = { mode: :compat }.freeze
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def load(json)
|
14
|
+
Oj.load(json, LOAD_OPTIONS)
|
15
|
+
rescue *PARSE_ERRORS => e
|
16
|
+
raise ParseError.new(e)
|
17
|
+
end
|
18
|
+
|
19
|
+
def dump(value)
|
20
|
+
Oj.dump(value, DUMP_OPTIONS)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Oj before 1.4.0 does not define Oj::ParseError and instead raises
|
26
|
+
# SyntaxError on failure
|
27
|
+
def detect_oj_parse_errors
|
28
|
+
require 'oj'
|
10
29
|
|
11
|
-
|
12
|
-
|
30
|
+
if Oj.const_defined?(:ParseError)
|
31
|
+
[Oj::ParseError, EncodingError, JSON::ParserError]
|
32
|
+
else
|
33
|
+
[SyntaxError]
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
nil
|
37
|
+
end
|
13
38
|
end
|
14
39
|
|
40
|
+
# @api private
|
41
|
+
PARSE_ERRORS = detect_oj_parse_errors
|
15
42
|
end
|
16
43
|
end
|
17
44
|
end
|
@@ -10,8 +10,9 @@ module Aws
|
|
10
10
|
include Seahorse::Model::Shapes
|
11
11
|
|
12
12
|
# @param [Seahorse::Model::ShapeRef] rules
|
13
|
-
def initialize(rules)
|
13
|
+
def initialize(rules, query_compatible: false)
|
14
14
|
@rules = rules
|
15
|
+
@query_compatible = query_compatible
|
15
16
|
end
|
16
17
|
|
17
18
|
# @param [String<JSON>] json
|
@@ -28,8 +29,32 @@ module Aws
|
|
28
29
|
member_name, member_ref = shape.member_by_location_name(key)
|
29
30
|
if member_ref
|
30
31
|
target[member_name] = parse_ref(member_ref, value)
|
32
|
+
elsif shape.union && key != '__type'
|
33
|
+
target[:unknown] = { 'name' => key, 'value' => value }
|
31
34
|
end
|
32
35
|
end
|
36
|
+
# In services that were previously Query/XML, members that were
|
37
|
+
# "flattened" defaulted to empty lists. In JSON, these values are nil,
|
38
|
+
# which is backwards incompatible. To preserve backwards compatibility,
|
39
|
+
# we set a default value of [] for these members.
|
40
|
+
if @query_compatible
|
41
|
+
ref.shape.members.each do |member_name, member_target|
|
42
|
+
next unless target[member_name].nil?
|
43
|
+
|
44
|
+
if flattened_list?(member_target.shape)
|
45
|
+
target[member_name] = []
|
46
|
+
elsif flattened_map?(member_target.shape)
|
47
|
+
target[member_name] = {}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if shape.union
|
53
|
+
# convert to subclass
|
54
|
+
member_subclass = shape.member_subclass(target.member).new
|
55
|
+
member_subclass[target.member] = target.value
|
56
|
+
target = member_subclass
|
57
|
+
end
|
33
58
|
target
|
34
59
|
end
|
35
60
|
|
@@ -44,6 +69,8 @@ module Aws
|
|
44
69
|
def map(ref, values, target = nil)
|
45
70
|
target = {} if target.nil?
|
46
71
|
values.each do |key, value|
|
72
|
+
next if value.nil?
|
73
|
+
|
47
74
|
target[key] = parse_ref(ref.shape.value, value)
|
48
75
|
end
|
49
76
|
target
|
@@ -60,6 +87,7 @@ module Aws
|
|
60
87
|
when TimestampShape then time(value)
|
61
88
|
when BlobShape then Base64.decode64(value)
|
62
89
|
when BooleanShape then value.to_s == 'true'
|
90
|
+
when FloatShape then Util.deserialize_number(value)
|
63
91
|
else value
|
64
92
|
end
|
65
93
|
end
|
@@ -68,7 +96,15 @@ module Aws
|
|
68
96
|
# @param [String, Integer] value
|
69
97
|
# @return [Time]
|
70
98
|
def time(value)
|
71
|
-
value.is_a?(Numeric) ? Time.at(value) :
|
99
|
+
value.is_a?(Numeric) ? Time.at(value) : Aws::Util.deserialize_time(value)
|
100
|
+
end
|
101
|
+
|
102
|
+
def flattened_list?(shape)
|
103
|
+
shape.is_a?(ListShape) && shape.flattened
|
104
|
+
end
|
105
|
+
|
106
|
+
def flattened_map?(shape)
|
107
|
+
shape.is_a?(MapShape) && shape.flattened
|
72
108
|
end
|
73
109
|
|
74
110
|
end
|
data/lib/aws-sdk-core/json.rb
CHANGED
@@ -5,6 +5,8 @@ require_relative 'json/builder'
|
|
5
5
|
require_relative 'json/error_handler'
|
6
6
|
require_relative 'json/handler'
|
7
7
|
require_relative 'json/parser'
|
8
|
+
require_relative 'json/json_engine'
|
9
|
+
require_relative 'json/oj_engine'
|
8
10
|
|
9
11
|
module Aws
|
10
12
|
# @api private
|
@@ -20,9 +22,7 @@ module Aws
|
|
20
22
|
|
21
23
|
class << self
|
22
24
|
def load(json)
|
23
|
-
ENGINE.load(json
|
24
|
-
rescue *ENGINE_ERRORS => e
|
25
|
-
raise ParseError, e
|
25
|
+
ENGINE.load(json)
|
26
26
|
end
|
27
27
|
|
28
28
|
def load_file(path)
|
@@ -30,38 +30,20 @@ module Aws
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def dump(value)
|
33
|
-
ENGINE.dump(value
|
33
|
+
ENGINE.dump(value)
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
-
def
|
38
|
+
def select_engine
|
39
39
|
require 'oj'
|
40
|
-
|
41
|
-
Oj,
|
42
|
-
[{ mode: :compat, symbol_keys: false, empty_string: false }],
|
43
|
-
[{ mode: :compat }],
|
44
|
-
oj_parse_error
|
45
|
-
]
|
40
|
+
OjEngine
|
46
41
|
rescue LoadError
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def json_engine
|
51
|
-
[JSON, [], [], [JSON::ParserError]]
|
52
|
-
end
|
53
|
-
|
54
|
-
def oj_parse_error
|
55
|
-
if Oj.const_defined?('ParseError')
|
56
|
-
[Oj::ParseError, EncodingError, JSON::ParserError]
|
57
|
-
else
|
58
|
-
[SyntaxError]
|
59
|
-
end
|
42
|
+
JSONEngine
|
60
43
|
end
|
61
44
|
end
|
62
45
|
|
63
46
|
# @api private
|
64
|
-
ENGINE
|
65
|
-
oj_engine || json_engine
|
47
|
+
ENGINE = select_engine
|
66
48
|
end
|
67
49
|
end
|
@@ -26,6 +26,8 @@ module Aws
|
|
26
26
|
#
|
27
27
|
# You can put any of these placeholders into you pattern.
|
28
28
|
#
|
29
|
+
# * `:region` - The region configured for the client.
|
30
|
+
#
|
29
31
|
# * `:client_class` - The name of the client class.
|
30
32
|
#
|
31
33
|
# * `:operation` - The name of the client request method.
|
@@ -116,6 +118,10 @@ module Aws
|
|
116
118
|
|
117
119
|
private
|
118
120
|
|
121
|
+
def _region(response)
|
122
|
+
response.context.config.region
|
123
|
+
end
|
124
|
+
|
119
125
|
def _client_class(response)
|
120
126
|
response.context.client.class.name
|
121
127
|
end
|
@@ -26,7 +26,8 @@ module Aws
|
|
26
26
|
|
27
27
|
def filter(values, type)
|
28
28
|
case values
|
29
|
-
when Struct
|
29
|
+
when Struct then filter_struct(values, type)
|
30
|
+
when Hash then filter_hash(values, type)
|
30
31
|
when Array then filter_array(values, type)
|
31
32
|
else values
|
32
33
|
end
|
@@ -34,6 +35,13 @@ module Aws
|
|
34
35
|
|
35
36
|
private
|
36
37
|
|
38
|
+
def filter_struct(values, type)
|
39
|
+
if values.class.include? Aws::Structure::Union
|
40
|
+
values = { values.member => values.value }
|
41
|
+
end
|
42
|
+
filter_hash(values, type)
|
43
|
+
end
|
44
|
+
|
37
45
|
def filter_hash(values, type)
|
38
46
|
if type.const_defined?('SENSITIVE')
|
39
47
|
filters = type::SENSITIVE + @additional_filters
|