aws-sdk-core 3.165.0 → 3.201.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +462 -0
- data/VERSION +1 -1
- data/lib/aws-defaults/default_configuration.rb +4 -4
- data/lib/aws-sdk-core/binary/decode_handler.rb +3 -9
- data/lib/aws-sdk-core/binary/encode_handler.rb +1 -1
- data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
- data/lib/aws-sdk-core/binary/event_stream_decoder.rb +1 -0
- data/lib/aws-sdk-core/binary/event_stream_encoder.rb +4 -3
- data/lib/aws-sdk-core/cbor/cbor_engine.rb +19 -0
- data/lib/aws-sdk-core/cbor/decoder.rb +310 -0
- data/lib/aws-sdk-core/cbor/encoder.rb +243 -0
- data/lib/aws-sdk-core/cbor.rb +106 -0
- data/lib/aws-sdk-core/client_stubs.rb +18 -14
- 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 +1 -1
- data/lib/aws-sdk-core/ecs_credentials.rb +178 -53
- data/lib/aws-sdk-core/endpoints/condition.rb +5 -0
- data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +5 -1
- data/lib/aws-sdk-core/endpoints/error_rule.rb +5 -0
- data/lib/aws-sdk-core/endpoints/function.rb +5 -0
- data/lib/aws-sdk-core/endpoints/matchers.rb +18 -10
- data/lib/aws-sdk-core/endpoints/reference.rb +5 -0
- data/lib/aws-sdk-core/endpoints/rule.rb +5 -0
- data/lib/aws-sdk-core/endpoints/rule_set.rb +5 -0
- data/lib/aws-sdk-core/endpoints/rules_provider.rb +5 -0
- data/lib/aws-sdk-core/endpoints/templater.rb +6 -0
- data/lib/aws-sdk-core/endpoints/tree_rule.rb +5 -0
- data/lib/aws-sdk-core/endpoints/url.rb +1 -0
- data/lib/aws-sdk-core/endpoints.rb +69 -19
- data/lib/aws-sdk-core/error_handler.rb +41 -0
- data/lib/aws-sdk-core/errors.rb +12 -3
- 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 +55 -32
- data/lib/aws-sdk-core/json/builder.rb +8 -1
- data/lib/aws-sdk-core/json/error_handler.rb +29 -14
- data/lib/aws-sdk-core/json/handler.rb +12 -6
- data/lib/aws-sdk-core/json/json_engine.rb +3 -1
- data/lib/aws-sdk-core/json/oj_engine.rb +7 -1
- data/lib/aws-sdk-core/json/parser.rb +33 -3
- data/lib/aws-sdk-core/json.rb +43 -14
- data/lib/aws-sdk-core/log/formatter.rb +6 -0
- data/lib/aws-sdk-core/lru_cache.rb +75 -0
- data/lib/aws-sdk-core/pageable_response.rb +3 -1
- data/lib/aws-sdk-core/param_validator.rb +9 -4
- data/lib/aws-sdk-core/plugins/bearer_authorization.rb +2 -0
- data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +7 -4
- 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 +2 -0
- data/lib/aws-sdk-core/plugins/global_configuration.rb +8 -9
- data/lib/aws-sdk-core/plugins/http_checksum.rb +2 -1
- data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
- data/lib/aws-sdk-core/plugins/logging.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +3 -1
- data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -24
- data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +6 -8
- data/lib/aws-sdk-core/plugins/protocols/query.rb +4 -2
- data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +3 -15
- data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +3 -0
- data/lib/aws-sdk-core/plugins/protocols/rpc_v2.rb +17 -0
- data/lib/aws-sdk-core/plugins/regional_endpoint.rb +140 -35
- data/lib/aws-sdk-core/plugins/request_compression.rb +226 -0
- data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +2 -1
- data/lib/aws-sdk-core/plugins/retry_errors.rb +12 -3
- data/lib/aws-sdk-core/plugins/sign.rb +43 -19
- data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -1
- data/lib/aws-sdk-core/plugins/signature_v4.rb +2 -1
- data/lib/aws-sdk-core/plugins/stub_responses.rb +1 -0
- data/lib/aws-sdk-core/plugins/transfer_encoding.rb +16 -9
- data/lib/aws-sdk-core/plugins/user_agent.rb +152 -14
- data/lib/aws-sdk-core/process_credentials.rb +45 -27
- data/lib/aws-sdk-core/query/ec2_handler.rb +27 -0
- data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
- data/lib/aws-sdk-core/query/handler.rb +4 -4
- data/lib/aws-sdk-core/query/param_builder.rb +2 -2
- data/lib/aws-sdk-core/query.rb +2 -1
- data/lib/aws-sdk-core/refreshing_credentials.rb +12 -12
- data/lib/aws-sdk-core/rest/content_type_handler.rb +60 -0
- data/lib/aws-sdk-core/rest/handler.rb +3 -4
- data/lib/aws-sdk-core/rest/request/body.rb +32 -5
- data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
- data/lib/aws-sdk-core/rest/request/headers.rb +15 -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 +8 -3
- data/lib/aws-sdk-core/rest.rb +1 -0
- data/lib/aws-sdk-core/rpc_v2/builder.rb +62 -0
- data/lib/aws-sdk-core/rpc_v2/content_type_handler.rb +45 -0
- data/lib/aws-sdk-core/rpc_v2/error_handler.rb +84 -0
- data/lib/aws-sdk-core/rpc_v2/handler.rb +74 -0
- data/lib/aws-sdk-core/rpc_v2/parser.rb +90 -0
- data/lib/aws-sdk-core/rpc_v2.rb +6 -0
- data/lib/aws-sdk-core/shared_config.rb +77 -18
- data/lib/aws-sdk-core/sso_credentials.rb +80 -45
- data/lib/aws-sdk-core/sso_token_provider.rb +3 -2
- data/lib/aws-sdk-core/stubbing/protocols/rpc_v2.rb +41 -0
- data/lib/aws-sdk-core/stubbing/stub_data.rb +11 -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 +32 -42
- data/lib/aws-sdk-core/xml/parser/frame.rb +4 -20
- data/lib/aws-sdk-core/xml/parser/{engines/oga.rb → oga_engine.rb} +2 -0
- data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
- data/lib/aws-sdk-core/xml/parser.rb +2 -6
- data/lib/aws-sdk-core.rb +8 -2
- data/lib/aws-sdk-sso/client.rb +103 -46
- data/lib/aws-sdk-sso/client_api.rb +6 -0
- data/lib/aws-sdk-sso/endpoint_provider.rb +41 -96
- data/lib/aws-sdk-sso/endpoints.rb +1 -0
- data/lib/aws-sdk-sso/plugins/endpoints.rb +4 -2
- data/lib/aws-sdk-sso/types.rb +0 -35
- data/lib/aws-sdk-sso.rb +1 -1
- data/lib/aws-sdk-ssooidc/client.rb +488 -74
- data/lib/aws-sdk-ssooidc/client_api.rb +82 -1
- data/lib/aws-sdk-ssooidc/endpoint_provider.rb +41 -95
- data/lib/aws-sdk-ssooidc/endpoints.rb +15 -0
- data/lib/aws-sdk-ssooidc/errors.rb +52 -0
- data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +6 -2
- data/lib/aws-sdk-ssooidc/types.rb +372 -83
- data/lib/aws-sdk-ssooidc.rb +1 -1
- data/lib/aws-sdk-sts/client.rb +361 -288
- data/lib/aws-sdk-sts/client_api.rb +24 -11
- data/lib/aws-sdk-sts/endpoint_provider.rb +96 -213
- data/lib/aws-sdk-sts/endpoints.rb +1 -0
- data/lib/aws-sdk-sts/plugins/endpoints.rb +4 -2
- data/lib/aws-sdk-sts/presigner.rb +1 -1
- data/lib/aws-sdk-sts/types.rb +128 -197
- data/lib/aws-sdk-sts.rb +1 -1
- data/lib/seahorse/client/async_base.rb +1 -1
- data/lib/seahorse/client/async_response.rb +19 -0
- data/lib/seahorse/client/base.rb +18 -7
- data/lib/seahorse/client/configuration.rb +0 -4
- data/lib/seahorse/client/h2/connection.rb +12 -11
- data/lib/seahorse/client/h2/handler.rb +1 -0
- data/lib/seahorse/client/handler.rb +1 -1
- data/lib/seahorse/client/net_http/connection_pool.rb +3 -9
- data/lib/seahorse/client/net_http/patches.rb +1 -4
- data/lib/seahorse/client/plugin.rb +9 -0
- data/lib/seahorse/client/plugins/endpoint.rb +0 -1
- data/lib/seahorse/client/plugins/h2.rb +3 -3
- data/lib/seahorse/client/plugins/net_http.rb +48 -16
- data/lib/seahorse/client/plugins/request_callback.rb +31 -0
- data/lib/seahorse/client/response.rb +6 -0
- data/lib/seahorse/model/operation.rb +3 -0
- data/lib/seahorse/model/shapes.rb +2 -2
- 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 +44 -17
- /data/lib/aws-sdk-core/xml/parser/{engines/libxml.rb → libxml_engine.rb} +0 -0
- /data/lib/aws-sdk-core/xml/parser/{engines/nokogiri.rb → nokogiri_engine.rb} +0 -0
- /data/lib/aws-sdk-core/xml/parser/{engines/ox.rb → ox_engine.rb} +0 -0
- /data/lib/aws-sdk-core/xml/parser/{engines/rexml.rb → rexml_engine.rb} +0 -0
@@ -14,9 +14,15 @@ require_relative 'endpoints/templater'
|
|
14
14
|
require_relative 'endpoints/tree_rule'
|
15
15
|
require_relative 'endpoints/url'
|
16
16
|
|
17
|
+
require 'aws-sigv4'
|
18
|
+
|
17
19
|
module Aws
|
18
20
|
# @api private
|
19
21
|
module Endpoints
|
22
|
+
supported_auth_traits = %w[aws.auth#sigv4 smithy.api#httpBearerAuth smithy.api#noAuth]
|
23
|
+
supported_auth_traits += ['aws.auth#sigv4a'] if Aws::Sigv4::Signer.use_crt?
|
24
|
+
SUPPORTED_AUTH_TRAITS = supported_auth_traits.freeze
|
25
|
+
|
20
26
|
class << self
|
21
27
|
def resolve_auth_scheme(context, endpoint)
|
22
28
|
if endpoint && (auth_schemes = endpoint.properties['authSchemes'])
|
@@ -33,13 +39,73 @@ module Aws
|
|
33
39
|
|
34
40
|
private
|
35
41
|
|
42
|
+
def merge_signing_defaults(auth_scheme, config)
|
43
|
+
if %w[sigv4 sigv4a sigv4-s3express].include?(auth_scheme['name'])
|
44
|
+
auth_scheme['signingName'] ||= sigv4_name(config)
|
45
|
+
if auth_scheme['name'] == 'sigv4a'
|
46
|
+
# config option supersedes endpoint properties
|
47
|
+
auth_scheme['signingRegionSet'] =
|
48
|
+
config.sigv4a_signing_region_set || auth_scheme['signingRegionSet'] || [config.region]
|
49
|
+
else
|
50
|
+
auth_scheme['signingRegion'] ||= config.region
|
51
|
+
end
|
52
|
+
end
|
53
|
+
auth_scheme
|
54
|
+
end
|
55
|
+
|
56
|
+
def sigv4_name(config)
|
57
|
+
config.api.metadata['signingName'] ||
|
58
|
+
config.api.metadata['endpointPrefix']
|
59
|
+
end
|
60
|
+
|
36
61
|
def default_auth_scheme(context)
|
37
|
-
|
62
|
+
if (auth_list = default_api_auth(context))
|
63
|
+
auth = auth_list.find { |a| SUPPORTED_AUTH_TRAITS.include?(a) }
|
64
|
+
case auth
|
65
|
+
when 'aws.auth#sigv4', 'aws.auth#sigv4a'
|
66
|
+
auth_scheme = { 'name' => auth.split('#').last }
|
67
|
+
if s3_or_s3v4_signature_version?(context)
|
68
|
+
auth_scheme = auth_scheme.merge(
|
69
|
+
'disableDoubleEncoding' => true,
|
70
|
+
'disableNormalizePath' => true
|
71
|
+
)
|
72
|
+
end
|
73
|
+
merge_signing_defaults(auth_scheme, context.config)
|
74
|
+
when 'smithy.api#httpBearerAuth'
|
75
|
+
{ 'name' => 'bearer' }
|
76
|
+
when 'smithy.api#noAuth'
|
77
|
+
{ 'name' => 'none' }
|
78
|
+
else
|
79
|
+
raise 'No supported auth trait for this endpoint.'
|
80
|
+
end
|
81
|
+
else
|
82
|
+
legacy_default_auth_scheme(context)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def default_api_auth(context)
|
87
|
+
context.config.api.operation(context.operation_name)['auth'] ||
|
88
|
+
context.config.api.metadata['auth']
|
89
|
+
end
|
90
|
+
|
91
|
+
def s3_or_s3v4_signature_version?(context)
|
92
|
+
%w[s3 s3v4].include?(context.config.api.metadata['signatureVersion'])
|
93
|
+
end
|
94
|
+
|
95
|
+
# Legacy auth resolution - looks for deprecated signatureVersion
|
96
|
+
# and authType traits.
|
97
|
+
|
98
|
+
def legacy_default_auth_scheme(context)
|
99
|
+
case legacy_default_api_authtype(context)
|
38
100
|
when 'v4', 'v4-unsigned-body'
|
39
101
|
auth_scheme = { 'name' => 'sigv4' }
|
40
102
|
merge_signing_defaults(auth_scheme, context.config)
|
41
103
|
when 's3', 's3v4'
|
42
|
-
auth_scheme = {
|
104
|
+
auth_scheme = {
|
105
|
+
'name' => 'sigv4',
|
106
|
+
'disableDoubleEncoding' => true,
|
107
|
+
'disableNormalizePath' => true
|
108
|
+
}
|
43
109
|
merge_signing_defaults(auth_scheme, context.config)
|
44
110
|
when 'bearer'
|
45
111
|
{ 'name' => 'bearer' }
|
@@ -48,27 +114,11 @@ module Aws
|
|
48
114
|
end
|
49
115
|
end
|
50
116
|
|
51
|
-
def
|
52
|
-
if %w[sigv4 sigv4a].include?(auth_scheme['name'])
|
53
|
-
auth_scheme['signingName'] ||= sigv4_name(config)
|
54
|
-
if auth_scheme['name'] == 'sigv4a'
|
55
|
-
auth_scheme['signingRegionSet'] ||= ['*']
|
56
|
-
else
|
57
|
-
auth_scheme['signingRegion'] ||= config.region
|
58
|
-
end
|
59
|
-
end
|
60
|
-
auth_scheme
|
61
|
-
end
|
62
|
-
|
63
|
-
def default_api_authtype(context)
|
117
|
+
def legacy_default_api_authtype(context)
|
64
118
|
context.config.api.operation(context.operation_name)['authtype'] ||
|
65
119
|
context.config.api.metadata['signatureVersion']
|
66
120
|
end
|
67
121
|
|
68
|
-
def sigv4_name(config)
|
69
|
-
config.api.metadata['signingName'] ||
|
70
|
-
config.api.metadata['endpointPrefix']
|
71
|
-
end
|
72
122
|
end
|
73
123
|
end
|
74
124
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
class ErrorHandler < Seahorse::Client::Handler
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def error(context)
|
9
|
+
body = context.http_response.body_contents
|
10
|
+
if body.empty?
|
11
|
+
code, message, data = http_status_error(context)
|
12
|
+
else
|
13
|
+
code, message, data = extract_error(body, context)
|
14
|
+
end
|
15
|
+
build_error(context, code, message, data)
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_error(context, code, message, data)
|
19
|
+
errors_module = context.client.class.errors_module
|
20
|
+
errors_module.error_class(code).new(context, message, data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def http_status_error(context)
|
24
|
+
[http_status_error_code(context), '', EmptyStructure.new]
|
25
|
+
end
|
26
|
+
|
27
|
+
def http_status_error_code(context)
|
28
|
+
status_code = context.http_response.status_code
|
29
|
+
{
|
30
|
+
302 => 'MovedTemporarily',
|
31
|
+
304 => 'NotModified',
|
32
|
+
400 => 'BadRequest',
|
33
|
+
403 => 'Forbidden',
|
34
|
+
404 => 'NotFound',
|
35
|
+
412 => 'PreconditionFailed',
|
36
|
+
413 => 'RequestEntityTooLarge',
|
37
|
+
}[status_code] || "Http#{status_code}Error"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/aws-sdk-core/errors.rb
CHANGED
@@ -12,7 +12,7 @@ module Aws
|
|
12
12
|
class ServiceError < RuntimeError
|
13
13
|
|
14
14
|
# @param [Seahorse::Client::RequestContext] context
|
15
|
-
# @param [String] message
|
15
|
+
# @param [String, nil] message
|
16
16
|
# @param [Aws::Structure] data
|
17
17
|
def initialize(context, message, data = Aws::EmptyStructure.new)
|
18
18
|
@code = self.class.code
|
@@ -30,11 +30,11 @@ module Aws
|
|
30
30
|
attr_reader :context
|
31
31
|
|
32
32
|
# @return [Aws::Structure]
|
33
|
-
|
33
|
+
attr_accessor :data
|
34
34
|
|
35
35
|
class << self
|
36
36
|
|
37
|
-
# @return [String]
|
37
|
+
# @return [String, nil]
|
38
38
|
attr_accessor :code
|
39
39
|
|
40
40
|
end
|
@@ -236,6 +236,15 @@ module Aws
|
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
239
|
+
# Raised when a client is constructed and the sigv4a region set is invalid.
|
240
|
+
# It is invalid when it is empty and/or contains empty strings.
|
241
|
+
class InvalidRegionSetError < ArgumentError
|
242
|
+
def initialize(*args)
|
243
|
+
msg = 'The provided sigv4a region set was empty or invalid.'
|
244
|
+
super(msg)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
239
248
|
# Raised when a client is contsructed and the region is not valid.
|
240
249
|
class InvalidRegionError < ArgumentError
|
241
250
|
def initialize(*args)
|
@@ -6,7 +6,6 @@ module Aws
|
|
6
6
|
def initialize
|
7
7
|
@listeners = {}
|
8
8
|
@validate_event = true
|
9
|
-
@status = :sleep
|
10
9
|
@signal_queue = Queue.new
|
11
10
|
end
|
12
11
|
|
@@ -40,25 +39,10 @@ module Aws
|
|
40
39
|
Aws::ParamValidator.validate!(
|
41
40
|
@encoder.rules.shape.member(type), params)
|
42
41
|
end
|
43
|
-
_ready_for_events?
|
44
42
|
@stream.data(
|
45
43
|
@encoder.encode(type, params),
|
46
44
|
end_stream: type == :end_stream
|
47
45
|
)
|
48
46
|
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def _ready_for_events?
|
53
|
-
return true if @status == :ready
|
54
|
-
|
55
|
-
# blocked until once initial 200 response is received
|
56
|
-
# signal will be available in @signal_queue
|
57
|
-
# and this check will no longer be blocked
|
58
|
-
@signal_queue.pop
|
59
|
-
@status = :ready
|
60
|
-
true
|
61
|
-
end
|
62
|
-
|
63
47
|
end
|
64
48
|
end
|
@@ -8,6 +8,8 @@ module Aws
|
|
8
8
|
def ini_parse(raw)
|
9
9
|
current_profile = nil
|
10
10
|
current_prefix = nil
|
11
|
+
item = nil
|
12
|
+
previous_item = nil
|
11
13
|
raw.lines.inject({}) do |acc, line|
|
12
14
|
line = line.split(/^|\s;/).first # remove comments
|
13
15
|
profile = line.match(/^\[([^\[\]]+)\]\s*(#.+)?$/) unless line.nil?
|
@@ -17,11 +19,16 @@ module Aws
|
|
17
19
|
current_profile = named_profile[1] if named_profile
|
18
20
|
elsif current_profile
|
19
21
|
unless line.nil?
|
22
|
+
previous_item = item
|
20
23
|
item = line.match(/^(.+?)\s*=\s*(.+?)\s*$/)
|
21
24
|
prefix = line.match(/^(.+?)\s*=\s*$/)
|
22
25
|
end
|
23
26
|
if item && item[1].match(/^\s+/)
|
24
27
|
# Need to add lines to a nested configuration.
|
28
|
+
if current_prefix.nil? && previous_item[2].strip.empty?
|
29
|
+
current_prefix = previous_item[1]
|
30
|
+
acc[current_profile][current_prefix] = {}
|
31
|
+
end
|
25
32
|
inner_item = line.match(/^\s*(.+?)\s*=\s*(.+?)\s*$/)
|
26
33
|
acc[current_profile] ||= {}
|
27
34
|
acc[current_profile][current_prefix] ||= {}
|
@@ -53,6 +53,8 @@ module Aws
|
|
53
53
|
# @option options [String] :endpoint_mode ('IPv4') The endpoint mode for
|
54
54
|
# the instance metadata service. This is either 'IPv4' ('169.254.169.254')
|
55
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.
|
56
58
|
# @option options [String] :ip_address ('169.254.169.254') Deprecated. Use
|
57
59
|
# :endpoint instead. The IP address for the endpoint.
|
58
60
|
# @option options [Integer] :port (80)
|
@@ -77,6 +79,9 @@ module Aws
|
|
77
79
|
endpoint_mode = resolve_endpoint_mode(options)
|
78
80
|
@endpoint = resolve_endpoint(options, endpoint_mode)
|
79
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
|
80
85
|
@http_open_timeout = options[:http_open_timeout] || 1
|
81
86
|
@http_read_timeout = options[:http_read_timeout] || 1
|
82
87
|
@http_debug_output = options[:http_debug_output]
|
@@ -123,6 +128,16 @@ module Aws
|
|
123
128
|
end
|
124
129
|
end
|
125
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
|
+
|
126
141
|
def backoff(backoff)
|
127
142
|
case backoff
|
128
143
|
when Proc then backoff
|
@@ -141,7 +156,7 @@ module Aws
|
|
141
156
|
# service is responding but is returning invalid JSON documents
|
142
157
|
# in response to the GET profile credentials call.
|
143
158
|
begin
|
144
|
-
retry_errors([Aws::Json::ParseError
|
159
|
+
retry_errors([Aws::Json::ParseError], max_retries: 3) do
|
145
160
|
c = Aws::Json.load(get_credentials.to_s)
|
146
161
|
if empty_credentials?(@credentials)
|
147
162
|
@credentials = Credentials.new(
|
@@ -173,7 +188,6 @@ module Aws
|
|
173
188
|
end
|
174
189
|
end
|
175
190
|
end
|
176
|
-
|
177
191
|
end
|
178
192
|
rescue Aws::Json::ParseError
|
179
193
|
raise Aws::Errors::MetadataParserError
|
@@ -191,42 +205,53 @@ module Aws
|
|
191
205
|
open_connection do |conn|
|
192
206
|
# attempt to fetch token to start secure flow first
|
193
207
|
# and rescue to failover
|
194
|
-
|
195
|
-
retry_errors(NETWORK_ERRORS, max_retries: @retries) do
|
196
|
-
unless token_set?
|
197
|
-
created_time = Time.now
|
198
|
-
token_value, ttl = http_put(
|
199
|
-
conn, METADATA_TOKEN_PATH, @token_ttl
|
200
|
-
)
|
201
|
-
@token = Token.new(token_value, ttl, created_time) if token_value && ttl
|
202
|
-
end
|
203
|
-
end
|
204
|
-
rescue *NETWORK_ERRORS
|
205
|
-
# token attempt failed, reset token
|
206
|
-
# fallback to non-token mode
|
207
|
-
@token = nil
|
208
|
-
end
|
209
|
-
|
208
|
+
fetch_token(conn) unless @imds_v1_fallback
|
210
209
|
token = @token.value if token_set?
|
211
210
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
# Token has expired, reset it
|
218
|
-
# The next retry should fetch it
|
219
|
-
@token = nil
|
220
|
-
raise Non200Response
|
221
|
-
end
|
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)
|
222
216
|
end
|
223
217
|
end
|
224
|
-
rescue
|
218
|
+
rescue => e
|
219
|
+
warn("Error retrieving instance profile credentials: #{e}")
|
225
220
|
'{}'
|
226
221
|
end
|
227
222
|
end
|
228
223
|
end
|
229
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
|
+
|
230
255
|
def token_set?
|
231
256
|
@token && !@token.expired?
|
232
257
|
end
|
@@ -237,7 +262,7 @@ module Aws
|
|
237
262
|
|
238
263
|
def open_connection
|
239
264
|
uri = URI.parse(@endpoint)
|
240
|
-
http = Net::HTTP.new(uri.hostname || @endpoint,
|
265
|
+
http = Net::HTTP.new(uri.hostname || @endpoint, uri.port || @port)
|
241
266
|
http.open_timeout = @http_open_timeout
|
242
267
|
http.read_timeout = @http_read_timeout
|
243
268
|
http.set_debug_output(@http_debug_output) if @http_debug_output
|
@@ -276,8 +301,6 @@ module Aws
|
|
276
301
|
]
|
277
302
|
when 400
|
278
303
|
raise TokenRetrivalError
|
279
|
-
when 401
|
280
|
-
raise TokenExpiredError
|
281
304
|
else
|
282
305
|
raise Non200Response
|
283
306
|
end
|
@@ -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
|
@@ -2,10 +2,8 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Json
|
5
|
-
class ErrorHandler <
|
5
|
+
class ErrorHandler < Aws::ErrorHandler
|
6
6
|
|
7
|
-
# @param [Seahorse::Client::RequestContext] context
|
8
|
-
# @return [Seahorse::Client::Response]
|
9
7
|
def call(context)
|
10
8
|
@handler.call(context).on(300..599) do |response|
|
11
9
|
response.error = error(context)
|
@@ -19,18 +17,20 @@ module Aws
|
|
19
17
|
json = Json.load(body)
|
20
18
|
code = error_code(json, context)
|
21
19
|
message = error_message(code, json)
|
22
|
-
data = parse_error_data(context, code)
|
20
|
+
data = parse_error_data(context, body, code)
|
23
21
|
[code, message, data]
|
24
22
|
rescue Json::ParseError
|
25
23
|
[http_status_error_code(context), '', EmptyStructure.new]
|
26
24
|
end
|
27
25
|
|
28
26
|
def error_code(json, context)
|
29
|
-
code =
|
30
|
-
context
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
code =
|
28
|
+
if aws_query_error?(context)
|
29
|
+
error = context.http_response.headers['x-amzn-query-error'].split(';')[0]
|
30
|
+
remove_prefix(error, context)
|
31
|
+
else
|
32
|
+
json['__type']
|
33
|
+
end
|
34
34
|
code ||= json['code']
|
35
35
|
code ||= context.http_response.headers['x-amzn-errortype']
|
36
36
|
if code
|
@@ -45,6 +45,14 @@ module Aws
|
|
45
45
|
context.http_response.headers['x-amzn-query-error']
|
46
46
|
end
|
47
47
|
|
48
|
+
def remove_prefix(error_code, context)
|
49
|
+
if (prefix = context.config.api.metadata['errorPrefix'])
|
50
|
+
error_code.sub(/^#{prefix}/, '')
|
51
|
+
else
|
52
|
+
error_code
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
48
56
|
def error_message(code, json)
|
49
57
|
if code == 'RequestEntityTooLarge'
|
50
58
|
'Request body must be less than 1 MB'
|
@@ -53,22 +61,29 @@ module Aws
|
|
53
61
|
end
|
54
62
|
end
|
55
63
|
|
56
|
-
def parse_error_data(context, code)
|
64
|
+
def parse_error_data(context, body, code)
|
57
65
|
data = EmptyStructure.new
|
58
|
-
if error_rules = context.operation.errors
|
66
|
+
if (error_rules = context.operation.errors)
|
59
67
|
error_rules.each do |rule|
|
60
68
|
# match modeled shape name with the type(code) only
|
61
69
|
# some type(code) might contains invalid characters
|
62
70
|
# such as ':' (efs) etc
|
63
71
|
match = rule.shape.name == code.gsub(/[^^a-zA-Z0-9]/, '')
|
64
|
-
|
65
|
-
|
66
|
-
|
72
|
+
next unless match && rule.shape.members.any?
|
73
|
+
|
74
|
+
data = Parser.new(rule).parse(body)
|
75
|
+
# errors support HTTP bindings
|
76
|
+
apply_error_headers(rule, context, data)
|
67
77
|
end
|
68
78
|
end
|
69
79
|
data
|
70
80
|
end
|
71
81
|
|
82
|
+
def apply_error_headers(rule, context, data)
|
83
|
+
headers = Aws::Rest::Response::Headers.new(rule)
|
84
|
+
headers.apply(context.http_response, data)
|
85
|
+
end
|
86
|
+
|
72
87
|
end
|
73
88
|
end
|
74
89
|
end
|
@@ -12,8 +12,7 @@ module Aws
|
|
12
12
|
build_request(context)
|
13
13
|
response = @handler.call(context)
|
14
14
|
response.on(200..299) { |resp| parse_response(resp) }
|
15
|
-
response.on(200..599) { |
|
16
|
-
response
|
15
|
+
response.on(200..599) { |_resp| apply_request_id(context) }
|
17
16
|
end
|
18
17
|
|
19
18
|
private
|
@@ -38,10 +37,10 @@ module Aws
|
|
38
37
|
end
|
39
38
|
|
40
39
|
def parse_body(context)
|
40
|
+
json = context.http_response.body_contents
|
41
41
|
if simple_json?(context)
|
42
|
-
Json.load(
|
43
|
-
elsif rules = context.operation.output
|
44
|
-
json = context.http_response.body_contents
|
42
|
+
Json.load(json)
|
43
|
+
elsif (rules = context.operation.output)
|
45
44
|
if json.is_a?(Array)
|
46
45
|
# an array of emitted events
|
47
46
|
if json[0].respond_to?(:response)
|
@@ -59,7 +58,10 @@ module Aws
|
|
59
58
|
end
|
60
59
|
resp_struct
|
61
60
|
else
|
62
|
-
Parser.new(
|
61
|
+
Parser.new(
|
62
|
+
rules,
|
63
|
+
query_compatible: query_compatible?(context)
|
64
|
+
).parse(json)
|
63
65
|
end
|
64
66
|
else
|
65
67
|
EmptyStructure.new
|
@@ -83,6 +85,10 @@ module Aws
|
|
83
85
|
context.config.simple_json
|
84
86
|
end
|
85
87
|
|
88
|
+
def query_compatible?(context)
|
89
|
+
context.config.api.metadata.key?('awsQueryCompatible')
|
90
|
+
end
|
91
|
+
|
86
92
|
end
|
87
93
|
end
|
88
94
|
end
|
@@ -1,10 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'oj'
|
4
|
+
|
3
5
|
module Aws
|
4
6
|
module Json
|
5
7
|
module OjEngine
|
6
8
|
# @api private
|
7
|
-
LOAD_OPTIONS = {
|
9
|
+
LOAD_OPTIONS = {
|
10
|
+
mode: :compat,
|
11
|
+
symbol_keys: false,
|
12
|
+
empty_string: false
|
13
|
+
}.freeze
|
8
14
|
|
9
15
|
# @api private
|
10
16
|
DUMP_OPTIONS = { mode: :compat }.freeze
|