aws-sdk-core 3.54.2 → 3.126.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1247 -0
- data/LICENSE.txt +202 -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 +92 -0
- data/lib/aws-sdk-core/arn_parser.rb +40 -0
- data/lib/aws-sdk-core/assume_role_credentials.rb +2 -0
- data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +104 -0
- data/lib/aws-sdk-core/async_client_stubs.rb +4 -2
- data/lib/aws-sdk-core/binary/decode_handler.rb +2 -0
- data/lib/aws-sdk-core/binary/encode_handler.rb +2 -0
- data/lib/aws-sdk-core/binary/event_builder.rb +8 -6
- data/lib/aws-sdk-core/binary/event_parser.rb +5 -3
- data/lib/aws-sdk-core/binary/event_stream_decoder.rb +2 -0
- data/lib/aws-sdk-core/binary/event_stream_encoder.rb +2 -0
- data/lib/aws-sdk-core/binary.rb +2 -0
- data/lib/aws-sdk-core/client_side_monitoring/publisher.rb +11 -1
- data/lib/aws-sdk-core/client_side_monitoring/request_metrics.rb +2 -0
- data/lib/aws-sdk-core/client_stubs.rb +15 -12
- data/lib/aws-sdk-core/credential_provider.rb +1 -30
- data/lib/aws-sdk-core/credential_provider_chain.rb +102 -40
- data/lib/aws-sdk-core/credentials.rb +2 -0
- data/lib/aws-sdk-core/deprecations.rb +17 -11
- data/lib/aws-sdk-core/eager_loader.rb +2 -0
- data/lib/aws-sdk-core/ec2_metadata.rb +237 -0
- data/lib/aws-sdk-core/ecs_credentials.rb +5 -4
- data/lib/aws-sdk-core/endpoint_cache.rb +16 -11
- data/lib/aws-sdk-core/errors.rb +102 -15
- data/lib/aws-sdk-core/event_emitter.rb +2 -0
- data/lib/aws-sdk-core/ini_parser.rb +2 -0
- data/lib/aws-sdk-core/instance_profile_credentials.rb +153 -39
- data/lib/aws-sdk-core/json/builder.rb +2 -0
- data/lib/aws-sdk-core/json/error_handler.rb +2 -0
- data/lib/aws-sdk-core/json/handler.rb +2 -0
- data/lib/aws-sdk-core/json/json_engine.rb +12 -8
- data/lib/aws-sdk-core/json/oj_engine.rb +35 -6
- data/lib/aws-sdk-core/json/parser.rb +10 -0
- data/lib/aws-sdk-core/json.rb +11 -28
- data/lib/aws-sdk-core/log/formatter.rb +16 -4
- data/lib/aws-sdk-core/log/handler.rb +2 -0
- data/lib/aws-sdk-core/log/param_filter.rb +38 -13
- data/lib/aws-sdk-core/log/param_formatter.rb +2 -0
- data/lib/aws-sdk-core/pageable_response.rb +48 -24
- data/lib/aws-sdk-core/pager.rb +5 -0
- data/lib/aws-sdk-core/param_converter.rb +2 -0
- data/lib/aws-sdk-core/param_validator.rb +55 -7
- data/lib/aws-sdk-core/plugins/api_key.rb +5 -1
- data/lib/aws-sdk-core/plugins/apig_authorizer_token.rb +2 -0
- data/lib/aws-sdk-core/plugins/apig_credentials_configuration.rb +2 -0
- data/lib/aws-sdk-core/plugins/apig_user_agent.rb +2 -0
- data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +28 -1
- data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +2 -0
- data/lib/aws-sdk-core/plugins/credentials_configuration.rb +26 -7
- data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
- data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +12 -4
- data/lib/aws-sdk-core/plugins/endpoint_pattern.rb +8 -6
- data/lib/aws-sdk-core/plugins/event_stream_configuration.rb +2 -0
- data/lib/aws-sdk-core/plugins/global_configuration.rb +2 -0
- data/lib/aws-sdk-core/plugins/helpful_socket_errors.rb +2 -0
- data/lib/aws-sdk-core/plugins/http_checksum.rb +57 -0
- data/lib/aws-sdk-core/plugins/idempotency_token.rb +2 -0
- data/lib/aws-sdk-core/plugins/invocation_id.rb +2 -0
- data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +2 -0
- data/lib/aws-sdk-core/plugins/logging.rb +2 -0
- data/lib/aws-sdk-core/plugins/param_converter.rb +2 -0
- data/lib/aws-sdk-core/plugins/param_validator.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +19 -0
- data/lib/aws-sdk-core/plugins/protocols/ec2.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/json_rpc.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/query.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +18 -1
- data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +2 -0
- data/lib/aws-sdk-core/plugins/recursion_detection.rb +27 -0
- data/lib/aws-sdk-core/plugins/regional_endpoint.rb +74 -16
- data/lib/aws-sdk-core/plugins/response_paging.rb +2 -0
- data/lib/aws-sdk-core/plugins/retries/client_rate_limiter.rb +139 -0
- data/lib/aws-sdk-core/plugins/retries/clock_skew.rb +100 -0
- data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +146 -0
- data/lib/aws-sdk-core/plugins/retries/retry_quota.rb +59 -0
- data/lib/aws-sdk-core/plugins/retry_errors.rb +295 -108
- data/lib/aws-sdk-core/plugins/signature_v2.rb +2 -0
- data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -25
- data/lib/aws-sdk-core/plugins/stub_responses.rb +5 -0
- data/lib/aws-sdk-core/plugins/transfer_encoding.rb +4 -4
- data/lib/aws-sdk-core/plugins/user_agent.rb +6 -8
- data/lib/aws-sdk-core/process_credentials.rb +8 -7
- data/lib/aws-sdk-core/query/ec2_param_builder.rb +2 -0
- data/lib/aws-sdk-core/query/handler.rb +2 -0
- data/lib/aws-sdk-core/query/param.rb +2 -0
- data/lib/aws-sdk-core/query/param_builder.rb +2 -0
- data/lib/aws-sdk-core/query/param_list.rb +2 -0
- data/lib/aws-sdk-core/query.rb +2 -0
- data/lib/aws-sdk-core/refreshing_credentials.rb +2 -0
- data/lib/aws-sdk-core/resources/collection.rb +2 -0
- data/lib/aws-sdk-core/rest/handler.rb +2 -0
- data/lib/aws-sdk-core/rest/request/body.rb +21 -1
- data/lib/aws-sdk-core/rest/request/builder.rb +2 -0
- data/lib/aws-sdk-core/rest/request/endpoint.rb +10 -3
- data/lib/aws-sdk-core/rest/request/headers.rb +20 -6
- data/lib/aws-sdk-core/rest/request/querystring_builder.rb +4 -2
- data/lib/aws-sdk-core/rest/response/body.rb +2 -0
- data/lib/aws-sdk-core/rest/response/headers.rb +6 -3
- data/lib/aws-sdk-core/rest/response/parser.rb +2 -0
- data/lib/aws-sdk-core/rest/response/status_code.rb +2 -0
- data/lib/aws-sdk-core/rest.rb +2 -0
- data/lib/aws-sdk-core/shared_config.rb +153 -122
- data/lib/aws-sdk-core/shared_credentials.rb +9 -1
- data/lib/aws-sdk-core/sso_credentials.rb +131 -0
- data/lib/aws-sdk-core/structure.rb +13 -2
- data/lib/aws-sdk-core/stubbing/data_applicator.rb +2 -0
- data/lib/aws-sdk-core/stubbing/empty_stub.rb +2 -0
- data/lib/aws-sdk-core/stubbing/protocols/api_gateway.rb +2 -0
- data/lib/aws-sdk-core/stubbing/protocols/ec2.rb +2 -0
- data/lib/aws-sdk-core/stubbing/protocols/json.rb +3 -1
- data/lib/aws-sdk-core/stubbing/protocols/query.rb +4 -2
- data/lib/aws-sdk-core/stubbing/protocols/rest.rb +33 -7
- data/lib/aws-sdk-core/stubbing/protocols/rest_json.rb +3 -1
- data/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb +2 -2
- data/lib/aws-sdk-core/stubbing/stub_data.rb +2 -0
- data/lib/aws-sdk-core/stubbing/xml_error.rb +2 -0
- data/lib/aws-sdk-core/type_builder.rb +2 -0
- data/lib/aws-sdk-core/util.rb +6 -0
- data/lib/aws-sdk-core/waiters/errors.rb +2 -0
- data/lib/aws-sdk-core/waiters/poller.rb +2 -0
- data/lib/aws-sdk-core/waiters/waiter.rb +2 -0
- data/lib/aws-sdk-core/waiters.rb +2 -0
- data/lib/aws-sdk-core/xml/builder.rb +5 -3
- data/lib/aws-sdk-core/xml/default_list.rb +2 -0
- data/lib/aws-sdk-core/xml/default_map.rb +2 -0
- data/lib/aws-sdk-core/xml/doc_builder.rb +15 -4
- data/lib/aws-sdk-core/xml/error_handler.rb +3 -1
- data/lib/aws-sdk-core/xml/parser/engines/libxml.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/engines/nokogiri.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/engines/ox.rb +3 -1
- data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +4 -1
- data/lib/aws-sdk-core/xml/parser/frame.rb +25 -0
- data/lib/aws-sdk-core/xml/parser/parsing_error.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
- data/lib/aws-sdk-core/xml/parser.rb +7 -0
- data/lib/aws-sdk-core/xml.rb +2 -0
- data/lib/aws-sdk-core.rb +22 -4
- data/lib/aws-sdk-sso/client.rb +568 -0
- data/lib/aws-sdk-sso/client_api.rb +190 -0
- data/lib/aws-sdk-sso/customizations.rb +1 -0
- data/lib/aws-sdk-sso/errors.rb +102 -0
- data/lib/aws-sdk-sso/resource.rb +26 -0
- data/lib/aws-sdk-sso/types.rb +352 -0
- data/lib/aws-sdk-sso.rb +55 -0
- data/lib/aws-sdk-sts/client.rb +970 -414
- data/lib/aws-sdk-sts/client_api.rb +41 -1
- data/lib/aws-sdk-sts/customizations.rb +4 -0
- data/lib/aws-sdk-sts/errors.rb +33 -9
- data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +38 -0
- data/lib/aws-sdk-sts/presigner.rb +75 -0
- data/lib/aws-sdk-sts/resource.rb +4 -1
- data/lib/aws-sdk-sts/types.rb +632 -236
- data/lib/aws-sdk-sts.rb +16 -6
- data/lib/seahorse/client/async_base.rb +2 -0
- data/lib/seahorse/client/async_response.rb +2 -0
- data/lib/seahorse/client/base.rb +6 -1
- data/lib/seahorse/client/block_io.rb +6 -2
- data/lib/seahorse/client/configuration.rb +6 -0
- data/lib/seahorse/client/events.rb +2 -0
- data/lib/seahorse/client/h2/connection.rb +31 -25
- data/lib/seahorse/client/h2/handler.rb +6 -5
- data/lib/seahorse/client/handler.rb +2 -0
- data/lib/seahorse/client/handler_builder.rb +2 -0
- data/lib/seahorse/client/handler_list.rb +2 -0
- data/lib/seahorse/client/handler_list_entry.rb +6 -4
- data/lib/seahorse/client/http/async_response.rb +2 -0
- data/lib/seahorse/client/http/headers.rb +2 -0
- data/lib/seahorse/client/http/request.rb +5 -3
- data/lib/seahorse/client/http/response.rb +5 -3
- data/lib/seahorse/client/logging/formatter.rb +6 -2
- data/lib/seahorse/client/logging/handler.rb +2 -0
- data/lib/seahorse/client/managed_file.rb +2 -0
- data/lib/seahorse/client/net_http/connection_pool.rb +30 -23
- data/lib/seahorse/client/net_http/handler.rb +24 -7
- data/lib/seahorse/client/net_http/patches.rb +15 -84
- data/lib/seahorse/client/networking_error.rb +2 -0
- data/lib/seahorse/client/plugin.rb +9 -6
- data/lib/seahorse/client/plugin_list.rb +2 -0
- data/lib/seahorse/client/plugins/content_length.rb +13 -7
- data/lib/seahorse/client/plugins/endpoint.rb +4 -2
- data/lib/seahorse/client/plugins/h2.rb +6 -1
- data/lib/seahorse/client/plugins/logging.rb +2 -0
- data/lib/seahorse/client/plugins/net_http.rb +39 -3
- data/lib/seahorse/client/plugins/operation_methods.rb +2 -0
- data/lib/seahorse/client/plugins/raise_response_errors.rb +2 -0
- data/lib/seahorse/client/plugins/request_callback.rb +110 -0
- data/lib/seahorse/client/plugins/response_target.rb +23 -14
- data/lib/seahorse/client/request.rb +2 -0
- data/lib/seahorse/client/request_context.rb +2 -0
- data/lib/seahorse/client/response.rb +5 -5
- data/lib/seahorse/model/api.rb +6 -0
- data/lib/seahorse/model/authorizer.rb +2 -0
- data/lib/seahorse/model/operation.rb +5 -0
- data/lib/seahorse/model/shapes.rb +27 -0
- data/lib/seahorse/util.rb +8 -1
- data/lib/seahorse/version.rb +2 -0
- data/lib/seahorse.rb +3 -0
- metadata +43 -11
@@ -0,0 +1,237 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
module Aws
|
7
|
+
# A client that can query version 2 of the EC2 Instance Metadata
|
8
|
+
class EC2Metadata
|
9
|
+
# Path for PUT request for token
|
10
|
+
# @api private
|
11
|
+
METADATA_TOKEN_PATH = '/latest/api/token'.freeze
|
12
|
+
|
13
|
+
# Raised when the PUT request is not valid. This would be thrown if
|
14
|
+
# `token_ttl` is not an Integer.
|
15
|
+
# @api private
|
16
|
+
class TokenRetrievalError < RuntimeError; end
|
17
|
+
|
18
|
+
# Token has expired, and the request can be retried with a new token.
|
19
|
+
# @api private
|
20
|
+
class TokenExpiredError < RuntimeError; end
|
21
|
+
|
22
|
+
# The requested metadata path does not exist.
|
23
|
+
# @api private
|
24
|
+
class MetadataNotFoundError < RuntimeError; end
|
25
|
+
|
26
|
+
# The request is not allowed or IMDS is turned off.
|
27
|
+
# @api private
|
28
|
+
class RequestForbiddenError < RuntimeError; end
|
29
|
+
|
30
|
+
# Creates a client that can query version 2 of the EC2 Instance Metadata
|
31
|
+
# service (IMDS).
|
32
|
+
#
|
33
|
+
# @note Customers using containers may need to increase their hop limit
|
34
|
+
# to access IMDSv2.
|
35
|
+
# @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#instance-metadata-transition-to-version-2
|
36
|
+
#
|
37
|
+
# @param [Hash] options
|
38
|
+
# @option options [Integer] :token_ttl (21600) The session token's TTL,
|
39
|
+
# defaulting to 6 hours.
|
40
|
+
# @option options [Integer] :retries (3) The number of retries for failed
|
41
|
+
# requests.
|
42
|
+
# @option options [String] :endpoint ('http://169.254.169.254') The IMDS
|
43
|
+
# endpoint. This option has precedence over the :endpoint_mode.
|
44
|
+
# @option options [String] :endpoint_mode ('IPv4') The endpoint mode for
|
45
|
+
# the instance metadata service. This is either 'IPv4'
|
46
|
+
# ('http://169.254.169.254') or 'IPv6' ('http://[fd00:ec2::254]').
|
47
|
+
# @option options [Integer] :port (80) The IMDS endpoint port.
|
48
|
+
# @option options [Integer] :http_open_timeout (1) The number of seconds to
|
49
|
+
# wait for the connection to open.
|
50
|
+
# @option options [Integer] :http_read_timeout (1) The number of seconds for
|
51
|
+
# one chunk of data to be read.
|
52
|
+
# @option options [IO] :http_debug_output An output stream for debugging. Do
|
53
|
+
# not use this in production.
|
54
|
+
# @option options [Integer,Proc] :backoff A backoff used for retryable
|
55
|
+
# requests. When given an Integer, it sleeps that amount. When given a
|
56
|
+
# Proc, it is called with the current number of failed retries.
|
57
|
+
def initialize(options = {})
|
58
|
+
@token_ttl = options[:token_ttl] || 21_600
|
59
|
+
@retries = options[:retries] || 3
|
60
|
+
@backoff = backoff(options[:backoff])
|
61
|
+
|
62
|
+
endpoint_mode = options[:endpoint_mode] || 'IPv4'
|
63
|
+
@endpoint = resolve_endpoint(options[:endpoint], endpoint_mode)
|
64
|
+
@port = options[:port] || 80
|
65
|
+
|
66
|
+
@http_open_timeout = options[:http_open_timeout] || 1
|
67
|
+
@http_read_timeout = options[:http_read_timeout] || 1
|
68
|
+
@http_debug_output = options[:http_debug_output]
|
69
|
+
|
70
|
+
@token = nil
|
71
|
+
@mutex = Mutex.new
|
72
|
+
end
|
73
|
+
|
74
|
+
# Fetches a given metadata category using a String path, and returns the
|
75
|
+
# result as a String. A path starts with the API version (usually
|
76
|
+
# "/latest/"). See the instance data categories for possible paths.
|
77
|
+
#
|
78
|
+
# @example Fetching the instance ID
|
79
|
+
#
|
80
|
+
# ec2_metadata = Aws::EC2Metadata.new
|
81
|
+
# ec2_metadata.get('/latest/meta-data/instance-id')
|
82
|
+
# => "i-023a25f10a73a0f79"
|
83
|
+
#
|
84
|
+
# @note This implementation always returns a String and will not parse any
|
85
|
+
# responses. Parsable responses may include JSON objects or directory
|
86
|
+
# listings, which are strings separated by line feeds (ASCII 10).
|
87
|
+
#
|
88
|
+
# @example Fetching and parsing JSON meta-data
|
89
|
+
#
|
90
|
+
# require 'json'
|
91
|
+
# data = ec2_metadata.get('/latest/dynamic/instance-identity/document')
|
92
|
+
# JSON.parse(data)
|
93
|
+
# => {"accountId"=>"012345678912", ... }
|
94
|
+
#
|
95
|
+
# @example Fetching and parsing directory listings
|
96
|
+
#
|
97
|
+
# listing = ec2_metadata.get('/latest/meta-data')
|
98
|
+
# listing.split(10.chr)
|
99
|
+
# => ["ami-id", "ami-launch-index", ...]
|
100
|
+
#
|
101
|
+
# @note Unlike other services, IMDS does not have a service API model. This
|
102
|
+
# means that we cannot confidently generate code with methods and
|
103
|
+
# response structures. This implementation ensures that new IMDS features
|
104
|
+
# are always supported by being deployed to the instance and does not
|
105
|
+
# require code changes.
|
106
|
+
#
|
107
|
+
# @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html
|
108
|
+
# @see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html
|
109
|
+
# @param [String] path The full path to the metadata.
|
110
|
+
def get(path)
|
111
|
+
retry_errors(max_retries: @retries) do
|
112
|
+
@mutex.synchronize do
|
113
|
+
fetch_token unless @token && !@token.expired?
|
114
|
+
end
|
115
|
+
|
116
|
+
open_connection do |conn|
|
117
|
+
http_get(conn, path, @token.value)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def resolve_endpoint(endpoint, endpoint_mode)
|
125
|
+
return endpoint if endpoint
|
126
|
+
|
127
|
+
case endpoint_mode.downcase
|
128
|
+
when 'ipv4' then 'http://169.254.169.254'
|
129
|
+
when 'ipv6' then 'http://[fd00:ec2::254]'
|
130
|
+
else
|
131
|
+
raise ArgumentError,
|
132
|
+
':endpoint_mode is not valid, expected IPv4 or IPv6, '\
|
133
|
+
"got: #{endpoint_mode}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def fetch_token
|
138
|
+
open_connection do |conn|
|
139
|
+
token_value, token_ttl = http_put(conn, @token_ttl)
|
140
|
+
@token = Token.new(value: token_value, ttl: token_ttl)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def http_get(connection, path, token)
|
145
|
+
headers = {
|
146
|
+
'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}",
|
147
|
+
'x-aws-ec2-metadata-token' => token
|
148
|
+
}
|
149
|
+
request = Net::HTTP::Get.new(path, headers)
|
150
|
+
response = connection.request(request)
|
151
|
+
|
152
|
+
case response.code.to_i
|
153
|
+
when 200
|
154
|
+
response.body
|
155
|
+
when 401
|
156
|
+
raise TokenExpiredError
|
157
|
+
when 404
|
158
|
+
raise MetadataNotFoundError
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def http_put(connection, ttl)
|
163
|
+
headers = {
|
164
|
+
'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}",
|
165
|
+
'x-aws-ec2-metadata-token-ttl-seconds' => ttl.to_s
|
166
|
+
}
|
167
|
+
request = Net::HTTP::Put.new(METADATA_TOKEN_PATH, headers)
|
168
|
+
response = connection.request(request)
|
169
|
+
|
170
|
+
case response.code.to_i
|
171
|
+
when 200
|
172
|
+
[
|
173
|
+
response.body,
|
174
|
+
response.header['x-aws-ec2-metadata-token-ttl-seconds'].to_i
|
175
|
+
]
|
176
|
+
when 400
|
177
|
+
raise TokenRetrievalError
|
178
|
+
when 403
|
179
|
+
raise RequestForbiddenError
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def open_connection
|
184
|
+
uri = URI.parse(@endpoint)
|
185
|
+
http = Net::HTTP.new(uri.hostname || @endpoint, @port || uri.port)
|
186
|
+
http.open_timeout = @http_open_timeout
|
187
|
+
http.read_timeout = @http_read_timeout
|
188
|
+
http.set_debug_output(@http_debug_output) if @http_debug_output
|
189
|
+
http.start
|
190
|
+
yield(http).tap { http.finish }
|
191
|
+
end
|
192
|
+
|
193
|
+
def retry_errors(options = {}, &_block)
|
194
|
+
max_retries = options[:max_retries]
|
195
|
+
retries = 0
|
196
|
+
begin
|
197
|
+
yield
|
198
|
+
# These errors should not be retried.
|
199
|
+
rescue TokenRetrievalError, MetadataNotFoundError, RequestForbiddenError
|
200
|
+
raise
|
201
|
+
# StandardError is not ideal but it covers Net::HTTP errors.
|
202
|
+
# https://gist.github.com/tenderlove/245188
|
203
|
+
rescue StandardError, TokenExpiredError
|
204
|
+
raise unless retries < max_retries
|
205
|
+
|
206
|
+
@backoff.call(retries)
|
207
|
+
retries += 1
|
208
|
+
retry
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def backoff(backoff)
|
213
|
+
case backoff
|
214
|
+
when Proc then backoff
|
215
|
+
when Numeric then ->(_) { Kernel.sleep(backoff) }
|
216
|
+
else ->(num_failures) { Kernel.sleep(1.2**num_failures) }
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# @api private
|
221
|
+
class Token
|
222
|
+
def initialize(options = {})
|
223
|
+
@ttl = options[:ttl]
|
224
|
+
@value = options[:value]
|
225
|
+
@created_time = Time.now
|
226
|
+
end
|
227
|
+
|
228
|
+
# [String] Returns the token value.
|
229
|
+
attr_reader :value
|
230
|
+
|
231
|
+
# [Boolean] Returns true if the token expired.
|
232
|
+
def expired?
|
233
|
+
Time.now - @created_time > @ttl
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'time'
|
3
4
|
require 'net/http'
|
4
5
|
|
@@ -79,8 +80,8 @@ module Aws
|
|
79
80
|
# service is responding but is returning invalid JSON documents
|
80
81
|
# in response to the GET profile credentials call.
|
81
82
|
begin
|
82
|
-
retry_errors([
|
83
|
-
c =
|
83
|
+
retry_errors([Aws::Json::ParseError, StandardError], max_retries: 3) do
|
84
|
+
c = Aws::Json.load(get_credentials.to_s)
|
84
85
|
@credentials = Credentials.new(
|
85
86
|
c['AccessKeyId'],
|
86
87
|
c['SecretAccessKey'],
|
@@ -88,7 +89,7 @@ module Aws
|
|
88
89
|
)
|
89
90
|
@expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
|
90
91
|
end
|
91
|
-
rescue
|
92
|
+
rescue Aws::Json::ParseError
|
92
93
|
raise Aws::Errors::MetadataParserError.new
|
93
94
|
end
|
94
95
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
# @api private
|
3
5
|
# a LRU cache caching endpoints data
|
@@ -47,8 +49,8 @@ module Aws
|
|
47
49
|
@mutex.synchronize do
|
48
50
|
# delete the least recent used endpoint when cache is full
|
49
51
|
unless @entries.size < @max_entries
|
50
|
-
old_key,
|
51
|
-
|
52
|
+
old_key, = @entries.shift
|
53
|
+
delete_polling_thread(old_key)
|
52
54
|
end
|
53
55
|
# delete old value if exists
|
54
56
|
@entries.delete(key)
|
@@ -60,10 +62,12 @@ module Aws
|
|
60
62
|
# @param [String] key
|
61
63
|
# @return [Boolean]
|
62
64
|
def key?(key)
|
63
|
-
|
64
|
-
|
65
|
+
@mutex.synchronize do
|
66
|
+
if @entries.key?(key) && (@entries[key].nil? || @entries[key].expired?)
|
67
|
+
@entries.delete(key)
|
68
|
+
end
|
69
|
+
@entries.key?(key)
|
65
70
|
end
|
66
|
-
@entries.key?(key)
|
67
71
|
end
|
68
72
|
|
69
73
|
# checking whether an polling thread exist for the key
|
@@ -84,7 +88,7 @@ module Aws
|
|
84
88
|
# kill the old polling thread and remove it from pool
|
85
89
|
# @param [String] key
|
86
90
|
def delete_polling_thread(key)
|
87
|
-
Thread.kill(@pool[key]) if
|
91
|
+
Thread.kill(@pool[key]) if threads_key?(key)
|
88
92
|
@pool.delete(key)
|
89
93
|
end
|
90
94
|
|
@@ -109,7 +113,7 @@ module Aws
|
|
109
113
|
if _endpoint_operation_identifier(ctx)
|
110
114
|
parts << ctx.operation_name
|
111
115
|
ctx.operation.input.shape.members.inject(parts) do |p, (name, ref)|
|
112
|
-
p << ctx.params[name] if ref[
|
116
|
+
p << ctx.params[name] if ref['endpointdiscoveryid']
|
113
117
|
p
|
114
118
|
end
|
115
119
|
end
|
@@ -141,7 +145,7 @@ module Aws
|
|
141
145
|
# build identifier params when available
|
142
146
|
params[:operation] = ctx.operation.name
|
143
147
|
ctx.operation.input.shape.members.inject(params) do |p, (name, ref)|
|
144
|
-
if ref[
|
148
|
+
if ref['endpointdiscoveryid']
|
145
149
|
p[:identifiers] ||= {}
|
146
150
|
p[:identifiers][ref.location_name] = ctx.params[name]
|
147
151
|
end
|
@@ -153,19 +157,20 @@ module Aws
|
|
153
157
|
endpoint_operation_name = ctx.config.api.endpoint_operation
|
154
158
|
ctx.client.send(endpoint_operation_name, params)
|
155
159
|
rescue Aws::Errors::ServiceError
|
156
|
-
nil
|
160
|
+
nil
|
157
161
|
end
|
158
162
|
end
|
159
163
|
|
160
164
|
def _endpoint_operation_identifier(ctx)
|
161
165
|
return @require_identifier unless @require_identifier.nil?
|
166
|
+
|
162
167
|
operation_name = ctx.config.api.endpoint_operation
|
163
168
|
operation = ctx.config.api.operation(operation_name)
|
164
169
|
@require_identifier = operation.input.shape.members.any?
|
165
170
|
end
|
166
171
|
|
167
172
|
class Endpoint
|
168
|
-
|
173
|
+
|
169
174
|
# default endpoint cache time, 1 minute
|
170
175
|
CACHE_PERIOD = 1
|
171
176
|
|
@@ -175,7 +180,7 @@ module Aws
|
|
175
180
|
@created_time = Time.now
|
176
181
|
end
|
177
182
|
|
178
|
-
# [String] valid URI address (with path)
|
183
|
+
# [String] valid URI address (with path)
|
179
184
|
attr_reader :address
|
180
185
|
|
181
186
|
def expired?
|
data/lib/aws-sdk-core/errors.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Errors
|
@@ -16,10 +16,10 @@ module Aws
|
|
16
16
|
# @param [Aws::Structure] data
|
17
17
|
def initialize(context, message, data = Aws::EmptyStructure.new)
|
18
18
|
@code = self.class.code
|
19
|
-
@message = message if message && !message.empty?
|
20
19
|
@context = context
|
21
20
|
@data = data
|
22
|
-
|
21
|
+
@message = message && !message.empty? ? message : self.class.to_s
|
22
|
+
super(@message)
|
23
23
|
end
|
24
24
|
|
25
25
|
# @return [String]
|
@@ -38,13 +38,23 @@ module Aws
|
|
38
38
|
attr_accessor :code
|
39
39
|
|
40
40
|
end
|
41
|
+
|
42
|
+
# @api private undocumented
|
43
|
+
def retryable?
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
# @api private undocumented
|
48
|
+
def throttling?
|
49
|
+
false
|
50
|
+
end
|
41
51
|
end
|
42
52
|
|
43
53
|
# Raised when InstanceProfileCredentialsProvider or
|
44
54
|
# EcsCredentialsProvider fails to parse the metadata response after retries
|
45
55
|
class MetadataParserError < RuntimeError
|
46
56
|
def initialize(*args)
|
47
|
-
msg =
|
57
|
+
msg = 'Failed to parse metadata service response.'
|
48
58
|
super(msg)
|
49
59
|
end
|
50
60
|
end
|
@@ -63,7 +73,7 @@ module Aws
|
|
63
73
|
class EndpointDiscoveryError < RuntimeError
|
64
74
|
def initialize(*args)
|
65
75
|
msg = 'Endpoint discovery failed for the operation or discovered endpoint is not working, '\
|
66
|
-
|
76
|
+
'request will keep failing until endpoint discovery succeeds or :endpoint option is provided.'
|
67
77
|
super(msg)
|
68
78
|
end
|
69
79
|
end
|
@@ -75,8 +85,8 @@ module Aws
|
|
75
85
|
|
76
86
|
def initialize(name)
|
77
87
|
msg = "Missing required parameter #{name} to construct"\
|
78
|
-
|
79
|
-
|
88
|
+
' endpoint host prefix. You can disable host prefix by'\
|
89
|
+
' setting :disable_host_prefix_injection to `true`.'
|
80
90
|
super(msg)
|
81
91
|
end
|
82
92
|
|
@@ -125,6 +135,29 @@ module Aws
|
|
125
135
|
|
126
136
|
end
|
127
137
|
|
138
|
+
# Raised when ARN string input doesn't follow the standard:
|
139
|
+
# https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-arns
|
140
|
+
class InvalidARNError < RuntimeError; end
|
141
|
+
|
142
|
+
# Raised when the region from the ARN string is different from the :region
|
143
|
+
# configured on the service client.
|
144
|
+
class InvalidARNRegionError < RuntimeError
|
145
|
+
def initialize(*args)
|
146
|
+
msg = 'ARN region is different from the configured client region.'
|
147
|
+
super(msg)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# Raised when the partition of the ARN region is different than the
|
152
|
+
# partition of the :region configured on the service client.
|
153
|
+
class InvalidARNPartitionError < RuntimeError
|
154
|
+
def initialize(*args)
|
155
|
+
msg = 'ARN region partition is different from the configured '\
|
156
|
+
'client region partition.'
|
157
|
+
super(msg)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
128
161
|
# Various plugins perform client-side checksums of responses.
|
129
162
|
# This error indicates a checksum failed.
|
130
163
|
class ChecksumError < RuntimeError; end
|
@@ -158,19 +191,66 @@ module Aws
|
|
158
191
|
end
|
159
192
|
end
|
160
193
|
|
194
|
+
# Raised when :web_identity_token_file parameter is not
|
195
|
+
# provided or the file doesn't exist when initializing
|
196
|
+
# AssumeRoleWebIdentityCredentials credential provider
|
197
|
+
class MissingWebIdentityTokenFile < RuntimeError
|
198
|
+
def initialize(*args)
|
199
|
+
msg = 'Missing :web_identity_token_file parameter or'\
|
200
|
+
' invalid file path provided for'\
|
201
|
+
' Aws::AssumeRoleWebIdentityCredentials provider'
|
202
|
+
super(msg)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
161
206
|
# Raised when a credentials provider process returns a JSON
|
162
207
|
# payload with either invalid version number or malformed contents
|
163
208
|
class InvalidProcessCredentialsPayload < RuntimeError; end
|
164
209
|
|
210
|
+
# Raised when SSO Credentials are invalid
|
211
|
+
class InvalidSSOCredentials < RuntimeError; end
|
212
|
+
|
213
|
+
# Raised when there is a circular reference in chained
|
214
|
+
# source_profiles
|
215
|
+
class SourceProfileCircularReferenceError < RuntimeError; end
|
216
|
+
|
165
217
|
# Raised when a client is constructed and region is not specified.
|
166
218
|
class MissingRegionError < ArgumentError
|
167
219
|
def initialize(*args)
|
168
|
-
msg =
|
169
|
-
|
220
|
+
msg = 'No region was provided. Configure the `:region` option or '\
|
221
|
+
"export the region name to ENV['AWS_REGION']"
|
170
222
|
super(msg)
|
171
223
|
end
|
172
224
|
end
|
173
225
|
|
226
|
+
# Raised when a client is contsructed and the region is not valid.
|
227
|
+
class InvalidRegionError < ArgumentError
|
228
|
+
def initialize(*args)
|
229
|
+
super(<<-MSG)
|
230
|
+
Invalid `:region` option was provided.
|
231
|
+
|
232
|
+
* Not every service is available in every region.
|
233
|
+
|
234
|
+
* Never suffix region names with availability zones.
|
235
|
+
Use "us-east-1", not "us-east-1a"
|
236
|
+
|
237
|
+
Known AWS regions include (not specific to this service):
|
238
|
+
|
239
|
+
#{possible_regions}
|
240
|
+
MSG
|
241
|
+
end
|
242
|
+
|
243
|
+
private
|
244
|
+
|
245
|
+
def possible_regions
|
246
|
+
Aws.partitions.each_with_object([]) do |partition, region_names|
|
247
|
+
partition.regions.each do |region|
|
248
|
+
region_names << region.name
|
249
|
+
end
|
250
|
+
end.join("\n")
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
174
254
|
# Raised when attempting to connect to an endpoint and a `SocketError`
|
175
255
|
# is received from the HTTP client. This error is typically the result
|
176
256
|
# of configuring an invalid `:region`.
|
@@ -183,14 +263,14 @@ module Aws
|
|
183
263
|
super(<<-MSG)
|
184
264
|
Encountered a `SocketError` while attempting to connect to:
|
185
265
|
|
186
|
-
#{endpoint
|
266
|
+
#{endpoint}
|
187
267
|
|
188
268
|
This is typically the result of an invalid `:region` option or a
|
189
269
|
poorly formatted `:endpoint` option.
|
190
270
|
|
191
271
|
* Avoid configuring the `:endpoint` option directly. Endpoints are constructed
|
192
|
-
from the `:region`. The `:endpoint` option is reserved for
|
193
|
-
non-standard test endpoints.
|
272
|
+
from the `:region`. The `:endpoint` option is reserved for certain services
|
273
|
+
or for connecting to non-standard test endpoints.
|
194
274
|
|
195
275
|
* Not every service is available in every region.
|
196
276
|
|
@@ -212,14 +292,21 @@ Known AWS regions include (not specific to this service):
|
|
212
292
|
private
|
213
293
|
|
214
294
|
def possible_regions
|
215
|
-
Aws.partitions.
|
295
|
+
Aws.partitions.each_with_object([]) do |partition, region_names|
|
216
296
|
partition.regions.each do |region|
|
217
297
|
region_names << region.name
|
218
298
|
end
|
219
|
-
region_names
|
220
299
|
end.join("\n")
|
221
300
|
end
|
301
|
+
end
|
222
302
|
|
303
|
+
# Raised when attempting to retry a request
|
304
|
+
# and no capacity is available to retry (See adaptive retry_mode)
|
305
|
+
class RetryCapacityNotAvailableError < RuntimeError
|
306
|
+
def initialize(*args)
|
307
|
+
msg = 'Insufficient client side capacity available to retry request.'
|
308
|
+
super(msg)
|
309
|
+
end
|
223
310
|
end
|
224
311
|
|
225
312
|
# This module is mixed into another module, providing dynamic
|
@@ -237,7 +324,7 @@ Known AWS regions include (not specific to this service):
|
|
237
324
|
module DynamicErrors
|
238
325
|
|
239
326
|
def self.extended(submodule)
|
240
|
-
submodule.instance_variable_set(
|
327
|
+
submodule.instance_variable_set('@const_set_mutex', Mutex.new)
|
241
328
|
submodule.const_set(:ServiceError, Class.new(ServiceError))
|
242
329
|
end
|
243
330
|
|