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
@@ -24,15 +24,16 @@ module Aws
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# When a client is stubbed allow the user to access the requests made
|
27
|
-
@api_requests = []
|
28
|
-
|
29
|
-
requests = @api_requests
|
27
|
+
requests = @api_requests = []
|
28
|
+
requests_mutex = @requests_mutex = Mutex.new
|
30
29
|
self.handle do |context|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
requests_mutex.synchronize do
|
31
|
+
requests << {
|
32
|
+
operation_name: context.operation_name,
|
33
|
+
params: context.params,
|
34
|
+
context: context
|
35
|
+
}
|
36
|
+
end
|
36
37
|
@handler.call(context)
|
37
38
|
end
|
38
39
|
end
|
@@ -194,10 +195,12 @@ module Aws
|
|
194
195
|
# is not stubbed.
|
195
196
|
def api_requests(options = {})
|
196
197
|
if config.stub_responses
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
198
|
+
@requests_mutex.synchronize do
|
199
|
+
if options[:exclude_presign]
|
200
|
+
@api_requests.reject {|req| req[:context][:presigned_url] }
|
201
|
+
else
|
202
|
+
@api_requests
|
203
|
+
end
|
201
204
|
end
|
202
205
|
else
|
203
206
|
msg = 'This method is only implemented for stubbed clients, and is '\
|
@@ -305,10 +308,11 @@ module Aws
|
|
305
308
|
def protocol_helper
|
306
309
|
case config.api.metadata['protocol']
|
307
310
|
when 'json' then Stubbing::Protocols::Json
|
308
|
-
when 'query' then Stubbing::Protocols::Query
|
309
|
-
when 'ec2' then Stubbing::Protocols::EC2
|
310
311
|
when 'rest-json' then Stubbing::Protocols::RestJson
|
311
312
|
when 'rest-xml' then Stubbing::Protocols::RestXml
|
313
|
+
when 'query' then Stubbing::Protocols::Query
|
314
|
+
when 'ec2' then Stubbing::Protocols::EC2
|
315
|
+
when 'smithy-rpc-v2-cbor' then Stubbing::Protocols::RpcV2
|
312
316
|
when 'api-gateway' then Stubbing::Protocols::ApiGateway
|
313
317
|
else raise "unsupported protocol"
|
314
318
|
end.new
|
@@ -161,7 +161,8 @@ module Aws
|
|
161
161
|
|
162
162
|
def instance_profile_credentials(options)
|
163
163
|
profile_name = determine_profile_name(options)
|
164
|
-
if ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']
|
164
|
+
if ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] ||
|
165
|
+
ENV['AWS_CONTAINER_CREDENTIALS_FULL_URI']
|
165
166
|
ECSCredentials.new(options)
|
166
167
|
else
|
167
168
|
InstanceProfileCredentials.new(options.merge(profile: profile_name))
|
@@ -169,12 +170,14 @@ module Aws
|
|
169
170
|
end
|
170
171
|
|
171
172
|
def assume_role_with_profile(options, profile_name)
|
172
|
-
|
173
|
-
Aws.shared_config.assume_role_credentials_from_config(
|
173
|
+
assume_opts = {
|
174
174
|
profile: profile_name,
|
175
|
-
region: region,
|
176
175
|
chain_config: @config
|
177
|
-
|
176
|
+
}
|
177
|
+
if options[:config] && options[:config].region
|
178
|
+
assume_opts[:region] = options[:config].region
|
179
|
+
end
|
180
|
+
Aws.shared_config.assume_role_credentials_from_config(assume_opts)
|
178
181
|
end
|
179
182
|
end
|
180
183
|
end
|
@@ -183,7 +183,7 @@ module Aws
|
|
183
183
|
|
184
184
|
def open_connection
|
185
185
|
uri = URI.parse(@endpoint)
|
186
|
-
http = Net::HTTP.new(uri.hostname || @endpoint,
|
186
|
+
http = Net::HTTP.new(uri.hostname || @endpoint, uri.port || @port)
|
187
187
|
http.open_timeout = @http_open_timeout
|
188
188
|
http.read_timeout = @http_read_timeout
|
189
189
|
http.set_debug_output(@http_debug_output) if @http_debug_output
|
@@ -2,21 +2,27 @@
|
|
2
2
|
|
3
3
|
require 'time'
|
4
4
|
require 'net/http'
|
5
|
+
require 'resolv'
|
5
6
|
|
6
7
|
module Aws
|
7
8
|
# An auto-refreshing credential provider that loads credentials from
|
8
|
-
# instances running in
|
9
|
+
# instances running in containers.
|
9
10
|
#
|
10
11
|
# ecs_credentials = Aws::ECSCredentials.new(retries: 3)
|
11
12
|
# ec2 = Aws::EC2::Client.new(credentials: ecs_credentials)
|
12
13
|
class ECSCredentials
|
13
|
-
|
14
14
|
include CredentialProvider
|
15
15
|
include RefreshingCredentials
|
16
16
|
|
17
17
|
# @api private
|
18
18
|
class Non200Response < RuntimeError; end
|
19
19
|
|
20
|
+
# Raised when the token file cannot be read.
|
21
|
+
class TokenFileReadError < RuntimeError; end
|
22
|
+
|
23
|
+
# Raised when the token file is invalid.
|
24
|
+
class InvalidTokenError < RuntimeError; end
|
25
|
+
|
20
26
|
# These are the errors we trap when attempting to talk to the
|
21
27
|
# instance metadata service. Any of these imply the service
|
22
28
|
# is not present, no responding or some other non-recoverable
|
@@ -29,16 +35,22 @@ module Aws
|
|
29
35
|
Errno::ENETUNREACH,
|
30
36
|
SocketError,
|
31
37
|
Timeout::Error,
|
32
|
-
Non200Response
|
33
|
-
]
|
38
|
+
Non200Response
|
39
|
+
].freeze
|
34
40
|
|
35
41
|
# @param [Hash] options
|
36
42
|
# @option options [Integer] :retries (5) Number of times to retry
|
37
43
|
# when retrieving credentials.
|
38
|
-
# @option options [String] :ip_address ('169.254.170.2')
|
39
|
-
#
|
44
|
+
# @option options [String] :ip_address ('169.254.170.2') This value is
|
45
|
+
# ignored if `endpoint` is set and `credential_path` is not set.
|
46
|
+
# @option options [Integer] :port (80) This value is ignored if `endpoint`
|
47
|
+
# is set and `credential_path` is not set.
|
40
48
|
# @option options [String] :credential_path By default, the value of the
|
41
49
|
# AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variable.
|
50
|
+
# @option options [String] :endpoint The container credential endpoint.
|
51
|
+
# By default, this is the value of the AWS_CONTAINER_CREDENTIALS_FULL_URI
|
52
|
+
# environment variable. This value is ignored if `credential_path` or
|
53
|
+
# ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'] is set.
|
42
54
|
# @option options [Float] :http_open_timeout (5)
|
43
55
|
# @option options [Float] :http_read_timeout (5)
|
44
56
|
# @option options [Numeric, Proc] :delay By default, failures are retried
|
@@ -52,17 +64,14 @@ module Aws
|
|
52
64
|
# credentials are refreshed. `before_refresh` is called
|
53
65
|
# with an instance of this object when
|
54
66
|
# AWS credentials are required and need to be refreshed.
|
55
|
-
def initialize
|
67
|
+
def initialize(options = {})
|
68
|
+
credential_path = options[:credential_path] ||
|
69
|
+
ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']
|
70
|
+
endpoint = options[:endpoint] ||
|
71
|
+
ENV['AWS_CONTAINER_CREDENTIALS_FULL_URI']
|
72
|
+
initialize_uri(options, credential_path, endpoint)
|
73
|
+
|
56
74
|
@retries = options[:retries] || 5
|
57
|
-
@ip_address = options[:ip_address] || '169.254.170.2'
|
58
|
-
@port = options[:port] || 80
|
59
|
-
@credential_path = options[:credential_path]
|
60
|
-
@credential_path ||= ENV['AWS_CONTAINER_CREDENTIALS_RELATIVE_URI']
|
61
|
-
unless @credential_path
|
62
|
-
raise ArgumentError.new(
|
63
|
-
"Cannot instantiate an ECS Credential Provider without a credential path."
|
64
|
-
)
|
65
|
-
end
|
66
75
|
@http_open_timeout = options[:http_open_timeout] || 5
|
67
76
|
@http_read_timeout = options[:http_read_timeout] || 5
|
68
77
|
@http_debug_output = options[:http_debug_output]
|
@@ -77,11 +86,95 @@ module Aws
|
|
77
86
|
|
78
87
|
private
|
79
88
|
|
89
|
+
def initialize_uri(options, credential_path, endpoint)
|
90
|
+
if credential_path
|
91
|
+
initialize_relative_uri(options, credential_path)
|
92
|
+
# Use FULL_URI/endpoint only if RELATIVE_URI/path is not set
|
93
|
+
elsif endpoint
|
94
|
+
initialize_full_uri(endpoint)
|
95
|
+
else
|
96
|
+
raise ArgumentError,
|
97
|
+
'Cannot instantiate an ECS Credential Provider '\
|
98
|
+
'without a credential path or endpoint.'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def initialize_relative_uri(options, path)
|
103
|
+
@host = options[:ip_address] || '169.254.170.2'
|
104
|
+
@port = options[:port] || 80
|
105
|
+
@scheme = 'http'
|
106
|
+
@credential_path = path
|
107
|
+
end
|
108
|
+
|
109
|
+
def initialize_full_uri(endpoint)
|
110
|
+
uri = URI.parse(endpoint)
|
111
|
+
validate_full_uri_scheme!(uri)
|
112
|
+
validate_full_uri!(uri)
|
113
|
+
@host = uri.hostname
|
114
|
+
@port = uri.port
|
115
|
+
@scheme = uri.scheme
|
116
|
+
@credential_path = uri.request_uri
|
117
|
+
end
|
118
|
+
|
119
|
+
def validate_full_uri_scheme!(full_uri)
|
120
|
+
return if full_uri.is_a?(URI::HTTP) || full_uri.is_a?(URI::HTTPS)
|
121
|
+
|
122
|
+
raise ArgumentError, "'#{full_uri}' must be a valid HTTP or HTTPS URI"
|
123
|
+
end
|
124
|
+
|
125
|
+
# Validate that the full URI is using a loopback address if scheme is http.
|
126
|
+
def validate_full_uri!(full_uri)
|
127
|
+
return unless full_uri.scheme == 'http'
|
128
|
+
|
129
|
+
begin
|
130
|
+
return if valid_ip_address?(IPAddr.new(full_uri.host))
|
131
|
+
rescue IPAddr::InvalidAddressError
|
132
|
+
addresses = Resolv.getaddresses(full_uri.host)
|
133
|
+
return if addresses.all? { |addr| valid_ip_address?(IPAddr.new(addr)) }
|
134
|
+
end
|
135
|
+
|
136
|
+
raise ArgumentError,
|
137
|
+
'AWS_CONTAINER_CREDENTIALS_FULL_URI must use a local loopback '\
|
138
|
+
'or an ECS or EKS link-local address when using the http scheme.'
|
139
|
+
end
|
140
|
+
|
141
|
+
def valid_ip_address?(ip_address)
|
142
|
+
ip_loopback?(ip_address) || ecs_or_eks_ip?(ip_address)
|
143
|
+
end
|
144
|
+
|
145
|
+
# loopback? method is available in Ruby 2.5+
|
146
|
+
# Replicate the logic here.
|
147
|
+
# loopback (IPv4 127.0.0.0/8, IPv6 ::1/128)
|
148
|
+
def ip_loopback?(ip_address)
|
149
|
+
case ip_address.family
|
150
|
+
when Socket::AF_INET
|
151
|
+
ip_address & 0xff000000 == 0x7f000000
|
152
|
+
when Socket::AF_INET6
|
153
|
+
ip_address == 1
|
154
|
+
else
|
155
|
+
false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Verify that the IP address is a link-local address from ECS or EKS.
|
160
|
+
# ECS container host (IPv4 `169.254.170.2`)
|
161
|
+
# EKS container host (IPv4 `169.254.170.23`, IPv6 `fd00:ec2::23`)
|
162
|
+
def ecs_or_eks_ip?(ip_address)
|
163
|
+
case ip_address.family
|
164
|
+
when Socket::AF_INET
|
165
|
+
[0xa9feaa02, 0xa9feaa17].include?(ip_address)
|
166
|
+
when Socket::AF_INET6
|
167
|
+
ip_address == 0xfd00_0ec2_0000_0000_0000_0000_0000_0023
|
168
|
+
else
|
169
|
+
false
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
80
173
|
def backoff(backoff)
|
81
174
|
case backoff
|
82
175
|
when Proc then backoff
|
83
|
-
when Numeric then
|
84
|
-
else
|
176
|
+
when Numeric then ->(_) { sleep(backoff) }
|
177
|
+
else ->(num_failures) { Kernel.sleep(1.2**num_failures) }
|
85
178
|
end
|
86
179
|
end
|
87
180
|
|
@@ -89,68 +182,100 @@ module Aws
|
|
89
182
|
# Retry loading credentials up to 3 times is the instance metadata
|
90
183
|
# service is responding but is returning invalid JSON documents
|
91
184
|
# in response to the GET profile credentials call.
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
rescue Aws::Json::ParseError
|
103
|
-
raise Aws::Errors::MetadataParserError.new
|
185
|
+
|
186
|
+
retry_errors([Aws::Json::ParseError, StandardError], max_retries: 3) do
|
187
|
+
c = Aws::Json.load(get_credentials.to_s)
|
188
|
+
@credentials = Credentials.new(
|
189
|
+
c['AccessKeyId'],
|
190
|
+
c['SecretAccessKey'],
|
191
|
+
c['Token']
|
192
|
+
)
|
193
|
+
@expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
|
104
194
|
end
|
195
|
+
rescue Aws::Json::ParseError
|
196
|
+
raise Aws::Errors::MetadataParserError
|
105
197
|
end
|
106
198
|
|
107
199
|
def get_credentials
|
108
200
|
# Retry loading credentials a configurable number of times if
|
109
201
|
# the instance metadata service is not responding.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
202
|
+
|
203
|
+
retry_errors(NETWORK_ERRORS, max_retries: @retries) do
|
204
|
+
open_connection do |conn|
|
205
|
+
http_get(conn, @credential_path)
|
115
206
|
end
|
116
|
-
rescue
|
117
|
-
'{}'
|
118
207
|
end
|
208
|
+
rescue TokenFileReadError, InvalidTokenError
|
209
|
+
raise
|
210
|
+
rescue StandardError => e
|
211
|
+
warn("Error retrieving ECS Credentials: #{e.message}")
|
212
|
+
'{}'
|
213
|
+
end
|
214
|
+
|
215
|
+
def fetch_authorization_token
|
216
|
+
if (path = ENV['AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE'])
|
217
|
+
fetch_authorization_token_file(path)
|
218
|
+
elsif (token = ENV['AWS_CONTAINER_AUTHORIZATION_TOKEN'])
|
219
|
+
token
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def fetch_authorization_token_file(path)
|
224
|
+
File.read(path).strip
|
225
|
+
rescue Errno::ENOENT
|
226
|
+
raise TokenFileReadError,
|
227
|
+
'AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE is set '\
|
228
|
+
"but the file doesn't exist: #{path}"
|
229
|
+
end
|
230
|
+
|
231
|
+
def validate_authorization_token!(token)
|
232
|
+
return unless token.include?("\r\n")
|
233
|
+
|
234
|
+
raise InvalidTokenError,
|
235
|
+
'Invalid Authorization token: token contains '\
|
236
|
+
'a newline and carriage return character.'
|
119
237
|
end
|
120
238
|
|
121
239
|
def open_connection
|
122
|
-
http = Net::HTTP.new(@
|
240
|
+
http = Net::HTTP.new(@host, @port, nil)
|
123
241
|
http.open_timeout = @http_open_timeout
|
124
242
|
http.read_timeout = @http_read_timeout
|
125
243
|
http.set_debug_output(@http_debug_output) if @http_debug_output
|
244
|
+
http.use_ssl = @scheme == 'https'
|
126
245
|
http.start
|
127
246
|
yield(http).tap { http.finish }
|
128
247
|
end
|
129
248
|
|
130
249
|
def http_get(connection, path)
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
250
|
+
request = Net::HTTP::Get.new(path)
|
251
|
+
set_authorization_token(request)
|
252
|
+
response = connection.request(request)
|
253
|
+
raise Non200Response unless response.code.to_i == 200
|
254
|
+
|
255
|
+
response.body
|
256
|
+
end
|
257
|
+
|
258
|
+
def set_authorization_token(request)
|
259
|
+
if (authorization_token = fetch_authorization_token)
|
260
|
+
validate_authorization_token!(authorization_token)
|
261
|
+
request['Authorization'] = authorization_token
|
136
262
|
end
|
137
263
|
end
|
138
264
|
|
139
|
-
def retry_errors(error_classes, options = {}
|
265
|
+
def retry_errors(error_classes, options = {})
|
140
266
|
max_retries = options[:max_retries]
|
141
267
|
retries = 0
|
142
268
|
begin
|
143
269
|
yield
|
144
|
-
rescue
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
270
|
+
rescue TokenFileReadError, InvalidTokenError
|
271
|
+
raise
|
272
|
+
rescue *error_classes => _e
|
273
|
+
raise unless retries < max_retries
|
274
|
+
|
275
|
+
@backoff.call(retries)
|
276
|
+
retries += 1
|
277
|
+
retry
|
152
278
|
end
|
153
279
|
end
|
154
|
-
|
155
280
|
end
|
156
281
|
end
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
6
|
+
# resolution approach. It has been replaced by a code generated
|
7
|
+
# approach in each service gem. It can be removed in a new
|
8
|
+
# major version. It has to exist because
|
9
|
+
# old service gems can use a new core version.
|
5
10
|
# @api private
|
6
11
|
class Condition
|
7
12
|
def initialize(fn:, argv:, assign: nil)
|
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
|
-
#
|
5
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
6
|
+
# resolution approach. It has been replaced by a code generated
|
7
|
+
# approach in each service gem. It can be removed in a new
|
8
|
+
# major version. It has to exist because
|
9
|
+
# old service gems can use a new core version. # @api private
|
6
10
|
class EndpointRule < Rule
|
7
11
|
def initialize(type: 'endpoint', conditions:, endpoint:,
|
8
12
|
documentation: nil)
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
6
|
+
# resolution approach. It has been replaced by a code generated
|
7
|
+
# approach in each service gem. It can be removed in a new
|
8
|
+
# major version. It has to exist because
|
9
|
+
# old service gems can use a new core version.
|
5
10
|
# @api private
|
6
11
|
class ErrorRule < Rule
|
7
12
|
def initialize(type: 'error', conditions:, error: nil, documentation: nil)
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
6
|
+
# resolution approach. It has been replaced by a code generated
|
7
|
+
# approach in each service gem. It can be removed in a new
|
8
|
+
# major version. It has to exist because
|
9
|
+
# old service gems can use a new core version.
|
5
10
|
# @api private
|
6
11
|
class Function
|
7
12
|
def initialize(fn:, argv:)
|
@@ -28,7 +28,11 @@ module Aws
|
|
28
28
|
|
29
29
|
val = if (index = parts.first[BRACKET_REGEX, 1])
|
30
30
|
# remove brackets and index from part before indexing
|
31
|
-
|
31
|
+
if (base = parts.first.gsub(BRACKET_REGEX, '')) && !base.empty?
|
32
|
+
value[base][index.to_i]
|
33
|
+
else
|
34
|
+
value[index.to_i]
|
35
|
+
end
|
32
36
|
else
|
33
37
|
value[parts.first]
|
34
38
|
end
|
@@ -79,11 +83,11 @@ module Aws
|
|
79
83
|
return false if value.empty?
|
80
84
|
|
81
85
|
if allow_sub_domains
|
82
|
-
labels = value.split('.')
|
86
|
+
labels = value.split('.', -1)
|
83
87
|
return labels.all? { |l| valid_host_label?(l) }
|
84
88
|
end
|
85
89
|
|
86
|
-
value =~ /\A(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\z/
|
90
|
+
!!(value =~ /\A(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\z/)
|
87
91
|
end
|
88
92
|
|
89
93
|
# AWS
|
@@ -114,13 +118,17 @@ module Aws
|
|
114
118
|
|
115
119
|
# aws.isVirtualHostableS3Bucket(value: string, allowSubDomains: bool) bool
|
116
120
|
def self.aws_virtual_hostable_s3_bucket?(value, allow_sub_domains = false)
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
return false if value.empty?
|
122
|
+
|
123
|
+
if allow_sub_domains
|
124
|
+
labels = value.split('.', -1)
|
125
|
+
return labels.all? { |l| aws_virtual_hostable_s3_bucket?(l) }
|
126
|
+
end
|
127
|
+
|
128
|
+
# must be between 3 and 63 characters long, no uppercase
|
129
|
+
value =~ /\A(?!-)[a-z0-9-]{3,63}(?<!-)\z/ &&
|
130
|
+
# not an IP address
|
131
|
+
value !~ /(\d+\.){3}\d+/
|
124
132
|
end
|
125
133
|
end
|
126
134
|
end
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
6
|
+
# resolution approach. It has been replaced by a code generated
|
7
|
+
# approach in each service gem. It can be removed in a new
|
8
|
+
# major version. It has to exist because
|
9
|
+
# old service gems can use a new core version.
|
5
10
|
# @api private
|
6
11
|
class Reference
|
7
12
|
def initialize(ref:)
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
6
|
+
# resolution approach. It has been replaced by a code generated
|
7
|
+
# approach in each service gem. It can be removed in a new
|
8
|
+
# major version. It has to exist because
|
9
|
+
# old service gems can use a new core version.
|
5
10
|
# @api private
|
6
11
|
class Rule
|
7
12
|
# Resolves a value that is a function, reference, or template string.
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
6
|
+
# resolution approach. It has been replaced by a code generated
|
7
|
+
# approach in each service gem. It can be removed in a new
|
8
|
+
# major version. It has to exist because
|
9
|
+
# old service gems can use a new core version.
|
5
10
|
# @api private
|
6
11
|
class RuleSet
|
7
12
|
def initialize(version:, service_id:, parameters:, rules:)
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module Aws
|
2
2
|
module Endpoints
|
3
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
4
|
+
# resolution approach. It has been replaced by a code generated
|
5
|
+
# approach in each service gem. It can be removed in a new
|
6
|
+
# major version. It has to exist because
|
7
|
+
# old service gems can use a new core version.
|
3
8
|
# @api private
|
4
9
|
class RulesProvider
|
5
10
|
def initialize(rule_set)
|
@@ -3,6 +3,12 @@
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
5
|
# Does substitutions for templated endpoint strings
|
6
|
+
|
7
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
8
|
+
# resolution approach. It has been replaced by a code generated
|
9
|
+
# approach in each service gem. It can be removed in a new
|
10
|
+
# major version. It has to exist because
|
11
|
+
# old service gems can use a new core version.
|
6
12
|
# @api private
|
7
13
|
module Templater
|
8
14
|
class << self
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Aws
|
4
4
|
module Endpoints
|
5
|
+
# This class is deprecated. It is used by the Runtime endpoint
|
6
|
+
# resolution approach. It has been replaced by a code generated
|
7
|
+
# approach in each service gem. It can be removed in a new
|
8
|
+
# major version. It has to exist because
|
9
|
+
# old service gems can use a new core version.
|
5
10
|
# @api private
|
6
11
|
class TreeRule
|
7
12
|
def initialize(type: 'tree', conditions:, rules:, documentation: nil)
|