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
@@ -1,16 +1,22 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'time'
|
3
4
|
require 'net/http'
|
4
5
|
|
5
6
|
module Aws
|
6
7
|
class InstanceProfileCredentials
|
7
|
-
|
8
8
|
include CredentialProvider
|
9
9
|
include RefreshingCredentials
|
10
10
|
|
11
11
|
# @api private
|
12
12
|
class Non200Response < RuntimeError; end
|
13
13
|
|
14
|
+
# @api private
|
15
|
+
class TokenRetrivalError < RuntimeError; end
|
16
|
+
|
17
|
+
# @api private
|
18
|
+
class TokenExpiredError < RuntimeError; end
|
19
|
+
|
14
20
|
# These are the errors we trap when attempting to talk to the
|
15
21
|
# instance metadata service. Any of these imply the service
|
16
22
|
# is not present, no responding or some other non-recoverable
|
@@ -23,16 +29,30 @@ module Aws
|
|
23
29
|
Errno::ENETUNREACH,
|
24
30
|
SocketError,
|
25
31
|
Timeout::Error,
|
26
|
-
Non200Response
|
27
|
-
]
|
32
|
+
Non200Response
|
33
|
+
].freeze
|
34
|
+
|
35
|
+
# Path base for GET request for profile and credentials
|
36
|
+
# @api private
|
37
|
+
METADATA_PATH_BASE = '/latest/meta-data/iam/security-credentials/'.freeze
|
38
|
+
|
39
|
+
# Path for PUT request for token
|
40
|
+
# @api private
|
41
|
+
METADATA_TOKEN_PATH = '/latest/api/token'.freeze
|
28
42
|
|
29
43
|
# @param [Hash] options
|
30
|
-
# @option options [Integer] :retries (
|
44
|
+
# @option options [Integer] :retries (1) Number of times to retry
|
31
45
|
# when retrieving credentials.
|
32
|
-
# @option options [String] :
|
46
|
+
# @option options [String] :endpoint ('http://169.254.169.254') The IMDS
|
47
|
+
# endpoint. This option has precedence over the :endpoint_mode.
|
48
|
+
# @option options [String] :endpoint_mode ('IPv4') The endpoint mode for
|
49
|
+
# the instance metadata service. This is either 'IPv4' ('169.254.169.254')
|
50
|
+
# or 'IPv6' ('[fd00:ec2::254]').
|
51
|
+
# @option options [String] :ip_address ('169.254.169.254') Deprecated. Use
|
52
|
+
# :endpoint instead. The IP address for the endpoint.
|
33
53
|
# @option options [Integer] :port (80)
|
34
|
-
# @option options [Float] :http_open_timeout (
|
35
|
-
# @option options [Float] :http_read_timeout (
|
54
|
+
# @option options [Float] :http_open_timeout (1)
|
55
|
+
# @option options [Float] :http_read_timeout (1)
|
36
56
|
# @option options [Numeric, Proc] :delay By default, failures are retried
|
37
57
|
# with exponential back-off, i.e. `sleep(1.2 ** num_failures)`. You can
|
38
58
|
# pass a number of seconds to sleep between failed attempts, or
|
@@ -40,28 +60,63 @@ module Aws
|
|
40
60
|
# @option options [IO] :http_debug_output (nil) HTTP wire
|
41
61
|
# traces are sent to this object. You can specify something
|
42
62
|
# like $stdout.
|
43
|
-
|
44
|
-
|
45
|
-
|
63
|
+
# @option options [Integer] :token_ttl Time-to-Live in seconds for EC2
|
64
|
+
# Metadata Token used for fetching Metadata Profile Credentials, defaults
|
65
|
+
# to 21600 seconds
|
66
|
+
def initialize(options = {})
|
67
|
+
@retries = options[:retries] || 1
|
68
|
+
endpoint_mode = resolve_endpoint_mode(options)
|
69
|
+
@endpoint = resolve_endpoint(options, endpoint_mode)
|
46
70
|
@port = options[:port] || 80
|
47
|
-
@http_open_timeout = options[:http_open_timeout] ||
|
48
|
-
@http_read_timeout = options[:http_read_timeout] ||
|
71
|
+
@http_open_timeout = options[:http_open_timeout] || 1
|
72
|
+
@http_read_timeout = options[:http_read_timeout] || 1
|
49
73
|
@http_debug_output = options[:http_debug_output]
|
50
74
|
@backoff = backoff(options[:backoff])
|
75
|
+
@token_ttl = options[:token_ttl] || 21_600
|
76
|
+
@token = nil
|
51
77
|
super
|
52
78
|
end
|
53
79
|
|
54
|
-
# @return [Integer]
|
55
|
-
#
|
80
|
+
# @return [Integer] Number of times to retry when retrieving credentials
|
81
|
+
# from the instance metadata service. Defaults to 0 when resolving from
|
82
|
+
# the default credential chain ({Aws::CredentialProviderChain}).
|
56
83
|
attr_reader :retries
|
57
84
|
|
58
85
|
private
|
59
86
|
|
87
|
+
def resolve_endpoint_mode(options)
|
88
|
+
value = options[:endpoint_mode]
|
89
|
+
value ||= ENV['AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE']
|
90
|
+
value ||= Aws.shared_config.ec2_metadata_service_endpoint_mode(
|
91
|
+
profile: options[:profile]
|
92
|
+
)
|
93
|
+
value || 'IPv4'
|
94
|
+
end
|
95
|
+
|
96
|
+
def resolve_endpoint(options, endpoint_mode)
|
97
|
+
value = options[:endpoint] || options[:ip_address]
|
98
|
+
value ||= ENV['AWS_EC2_METADATA_SERVICE_ENDPOINT']
|
99
|
+
value ||= Aws.shared_config.ec2_metadata_service_endpoint(
|
100
|
+
profile: options[:profile]
|
101
|
+
)
|
102
|
+
|
103
|
+
return value if value
|
104
|
+
|
105
|
+
case endpoint_mode.downcase
|
106
|
+
when 'ipv4' then 'http://169.254.169.254'
|
107
|
+
when 'ipv6' then 'http://[fd00:ec2::254]'
|
108
|
+
else
|
109
|
+
raise ArgumentError,
|
110
|
+
':endpoint_mode is not valid, expected IPv4 or IPv6, '\
|
111
|
+
"got: #{endpoint_mode}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
60
115
|
def backoff(backoff)
|
61
116
|
case backoff
|
62
117
|
when Proc then backoff
|
63
|
-
when Numeric then
|
64
|
-
else
|
118
|
+
when Numeric then ->(_) { sleep(backoff) }
|
119
|
+
else ->(num_failures) { Kernel.sleep(1.2**num_failures) }
|
65
120
|
end
|
66
121
|
end
|
67
122
|
|
@@ -70,8 +125,8 @@ module Aws
|
|
70
125
|
# service is responding but is returning invalid JSON documents
|
71
126
|
# in response to the GET profile credentials call.
|
72
127
|
begin
|
73
|
-
retry_errors([
|
74
|
-
c =
|
128
|
+
retry_errors([Aws::Json::ParseError, StandardError], max_retries: 3) do
|
129
|
+
c = Aws::Json.load(get_credentials.to_s)
|
75
130
|
@credentials = Credentials.new(
|
76
131
|
c['AccessKeyId'],
|
77
132
|
c['SecretAccessKey'],
|
@@ -79,8 +134,8 @@ module Aws
|
|
79
134
|
)
|
80
135
|
@expiration = c['Expiration'] ? Time.iso8601(c['Expiration']) : nil
|
81
136
|
end
|
82
|
-
rescue
|
83
|
-
raise Aws::Errors::MetadataParserError
|
137
|
+
rescue Aws::Json::ParseError
|
138
|
+
raise Aws::Errors::MetadataParserError
|
84
139
|
end
|
85
140
|
end
|
86
141
|
|
@@ -93,9 +148,27 @@ module Aws
|
|
93
148
|
begin
|
94
149
|
retry_errors(NETWORK_ERRORS, max_retries: @retries) do
|
95
150
|
open_connection do |conn|
|
96
|
-
|
97
|
-
|
98
|
-
|
151
|
+
# attempt to fetch token to start secure flow first
|
152
|
+
# and rescue to failover
|
153
|
+
begin
|
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
|
+
|
168
|
+
token = @token.value if token_set?
|
169
|
+
metadata = http_get(conn, METADATA_PATH_BASE, token)
|
170
|
+
profile_name = metadata.lines.first.strip
|
171
|
+
http_get(conn, METADATA_PATH_BASE + profile_name, token)
|
99
172
|
end
|
100
173
|
end
|
101
174
|
rescue
|
@@ -104,13 +177,17 @@ module Aws
|
|
104
177
|
end
|
105
178
|
end
|
106
179
|
|
180
|
+
def token_set?
|
181
|
+
@token && !@token.expired?
|
182
|
+
end
|
183
|
+
|
107
184
|
def _metadata_disabled?
|
108
|
-
|
109
|
-
!flag.nil? && flag.downcase == "true"
|
185
|
+
ENV.fetch('AWS_EC2_METADATA_DISABLED', 'false').downcase == 'true'
|
110
186
|
end
|
111
187
|
|
112
188
|
def open_connection
|
113
|
-
|
189
|
+
uri = URI.parse(@endpoint)
|
190
|
+
http = Net::HTTP.new(uri.hostname || @endpoint, @port || uri.port)
|
114
191
|
http.open_timeout = @http_open_timeout
|
115
192
|
http.read_timeout = @http_read_timeout
|
116
193
|
http.set_debug_output(@http_debug_output) if @http_debug_output
|
@@ -118,30 +195,67 @@ module Aws
|
|
118
195
|
yield(http).tap { http.finish }
|
119
196
|
end
|
120
197
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
198
|
+
# GET request fetch profile and credentials
|
199
|
+
def http_get(connection, path, token = nil)
|
200
|
+
headers = { 'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}" }
|
201
|
+
headers['x-aws-ec2-metadata-token'] = token if token
|
202
|
+
response = connection.request(Net::HTTP::Get.new(path, headers))
|
203
|
+
raise Non200Response unless response.code.to_i == 200
|
204
|
+
|
205
|
+
response.body
|
206
|
+
end
|
207
|
+
|
208
|
+
# PUT request fetch token with ttl
|
209
|
+
def http_put(connection, path, ttl)
|
210
|
+
headers = {
|
211
|
+
'User-Agent' => "aws-sdk-ruby3/#{CORE_GEM_VERSION}",
|
212
|
+
'x-aws-ec2-metadata-token-ttl-seconds' => ttl.to_s
|
213
|
+
}
|
214
|
+
response = connection.request(Net::HTTP::Put.new(path, headers))
|
215
|
+
case response.code.to_i
|
216
|
+
when 200
|
217
|
+
[
|
218
|
+
response.body,
|
219
|
+
response.header['x-aws-ec2-metadata-token-ttl-seconds'].to_i
|
220
|
+
]
|
221
|
+
when 400
|
222
|
+
raise TokenRetrivalError
|
223
|
+
when 401
|
224
|
+
raise TokenExpiredError
|
125
225
|
else
|
126
226
|
raise Non200Response
|
127
227
|
end
|
128
228
|
end
|
129
229
|
|
130
|
-
def retry_errors(error_classes, options = {}, &
|
230
|
+
def retry_errors(error_classes, options = {}, &_block)
|
131
231
|
max_retries = options[:max_retries]
|
132
232
|
retries = 0
|
133
233
|
begin
|
134
234
|
yield
|
135
235
|
rescue *error_classes
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
raise
|
142
|
-
end
|
236
|
+
raise unless retries < max_retries
|
237
|
+
|
238
|
+
@backoff.call(retries)
|
239
|
+
retries += 1
|
240
|
+
retry
|
143
241
|
end
|
144
242
|
end
|
145
243
|
|
244
|
+
# @api private
|
245
|
+
# Token used to fetch IMDS profile and credentials
|
246
|
+
class Token
|
247
|
+
def initialize(value, ttl)
|
248
|
+
@ttl = ttl
|
249
|
+
@value = value
|
250
|
+
@created_time = Time.now
|
251
|
+
end
|
252
|
+
|
253
|
+
# [String] token value
|
254
|
+
attr_reader :value
|
255
|
+
|
256
|
+
def expired?
|
257
|
+
Time.now - @created_time > @ttl
|
258
|
+
end
|
259
|
+
end
|
146
260
|
end
|
147
261
|
end
|
@@ -1,15 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
module Json
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
def dump(value)
|
14
|
+
JSON.dump(value)
|
15
|
+
end
|
11
16
|
end
|
12
|
-
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
@@ -1,15 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Aws
|
2
4
|
module Json
|
3
|
-
|
5
|
+
module OjEngine
|
6
|
+
# @api private
|
7
|
+
LOAD_OPTIONS = { mode: :compat, symbol_keys: false, empty_string: false }.freeze
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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'
|
8
29
|
|
9
|
-
|
10
|
-
|
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
|
11
38
|
end
|
12
39
|
|
40
|
+
# @api private
|
41
|
+
PARSE_ERRORS = detect_oj_parse_errors
|
13
42
|
end
|
14
43
|
end
|
15
44
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'base64'
|
2
4
|
require 'time'
|
3
5
|
|
@@ -26,8 +28,16 @@ module Aws
|
|
26
28
|
member_name, member_ref = shape.member_by_location_name(key)
|
27
29
|
if member_ref
|
28
30
|
target[member_name] = parse_ref(member_ref, value)
|
31
|
+
elsif shape.union
|
32
|
+
target[:unknown] = { 'name' => key, 'value' => value }
|
29
33
|
end
|
30
34
|
end
|
35
|
+
if shape.union
|
36
|
+
# convert to subclass
|
37
|
+
member_subclass = shape.member_subclass(target.member).new
|
38
|
+
member_subclass[target.member] = target.value
|
39
|
+
target = member_subclass
|
40
|
+
end
|
31
41
|
target
|
32
42
|
end
|
33
43
|
|
data/lib/aws-sdk-core/json.rb
CHANGED
@@ -1,66 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require_relative 'json/builder'
|
3
5
|
require_relative 'json/error_handler'
|
4
6
|
require_relative 'json/handler'
|
5
7
|
require_relative 'json/parser'
|
8
|
+
require_relative 'json/json_engine'
|
9
|
+
require_relative 'json/oj_engine'
|
6
10
|
|
7
11
|
module Aws
|
8
12
|
# @api private
|
9
13
|
module Json
|
10
|
-
|
11
14
|
class ParseError < StandardError
|
12
|
-
|
13
15
|
def initialize(error)
|
14
16
|
@error = error
|
15
17
|
super(error.message)
|
16
18
|
end
|
17
19
|
|
18
20
|
attr_reader :error
|
19
|
-
|
20
21
|
end
|
21
22
|
|
22
23
|
class << self
|
23
|
-
|
24
24
|
def load(json)
|
25
|
-
ENGINE.load(json
|
26
|
-
rescue ENGINE_ERROR => e
|
27
|
-
raise ParseError.new(e)
|
25
|
+
ENGINE.load(json)
|
28
26
|
end
|
29
27
|
|
30
28
|
def load_file(path)
|
31
|
-
|
29
|
+
load(File.open(path, 'r', encoding: 'UTF-8', &:read))
|
32
30
|
end
|
33
31
|
|
34
32
|
def dump(value)
|
35
|
-
ENGINE.dump(value
|
33
|
+
ENGINE.dump(value)
|
36
34
|
end
|
37
35
|
|
38
36
|
private
|
39
37
|
|
40
|
-
def
|
38
|
+
def select_engine
|
41
39
|
require 'oj'
|
42
|
-
|
40
|
+
OjEngine
|
43
41
|
rescue LoadError
|
44
|
-
|
42
|
+
JSONEngine
|
45
43
|
end
|
46
|
-
|
47
|
-
def json_engine
|
48
|
-
[JSON, [], [], JSON::ParserError]
|
49
|
-
end
|
50
|
-
|
51
|
-
def oj_parse_error
|
52
|
-
if Oj.const_defined?('ParseError')
|
53
|
-
Oj::ParseError
|
54
|
-
else
|
55
|
-
SyntaxError
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
44
|
end
|
60
45
|
|
61
46
|
# @api private
|
62
|
-
ENGINE
|
63
|
-
oj_engine || json_engine
|
64
|
-
|
47
|
+
ENGINE = select_engine
|
65
48
|
end
|
66
49
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
|
3
5
|
module Aws
|
@@ -83,6 +85,9 @@ module Aws
|
|
83
85
|
# The default list of filtered parameters is documented on the
|
84
86
|
# {ParamFilter} class.
|
85
87
|
#
|
88
|
+
# @option options [Boolean] :filter_sensitive_params (true) Set to false
|
89
|
+
# to disable the sensitive parameter filtering when logging
|
90
|
+
# `:request_params`.
|
86
91
|
def initialize(pattern, options = {})
|
87
92
|
@pattern = pattern
|
88
93
|
@param_formatter = ParamFormatter.new(options)
|
@@ -92,12 +97,12 @@ module Aws
|
|
92
97
|
# @return [String]
|
93
98
|
attr_reader :pattern
|
94
99
|
|
95
|
-
# Given a
|
100
|
+
# Given a response, this will format a log message and return it as a
|
96
101
|
# string according to {#pattern}.
|
97
102
|
# @param [Seahorse::Client::Response] response
|
98
103
|
# @return [String]
|
99
104
|
def format(response)
|
100
|
-
pattern.gsub(/:(\w+)/) {|sym| send("_#{sym[1..-1]}", response) }
|
105
|
+
pattern.gsub(/:(\w+)/) { |sym| send("_#{sym[1..-1]}", response) }
|
101
106
|
end
|
102
107
|
|
103
108
|
# @api private
|
@@ -121,7 +126,8 @@ module Aws
|
|
121
126
|
|
122
127
|
def _request_params(response)
|
123
128
|
params = response.context.params
|
124
|
-
|
129
|
+
type = response.context.operation.input.shape.struct_class
|
130
|
+
@param_formatter.summarize(@param_filter.filter(params, type))
|
125
131
|
end
|
126
132
|
|
127
133
|
def _time(response)
|
@@ -171,7 +177,13 @@ module Aws
|
|
171
177
|
end
|
172
178
|
|
173
179
|
def _http_response_body(response)
|
174
|
-
|
180
|
+
if response.context.http_response.body.respond_to?(:rewind)
|
181
|
+
@param_formatter.summarize(
|
182
|
+
response.context.http_response.body_contents
|
183
|
+
)
|
184
|
+
else
|
185
|
+
''
|
186
|
+
end
|
175
187
|
end
|
176
188
|
|
177
189
|
def _error_class(response)
|
@@ -1,43 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
require 'set'
|
3
5
|
|
4
6
|
module Aws
|
5
7
|
module Log
|
6
8
|
class ParamFilter
|
7
|
-
|
9
|
+
# DEPRECATED - This must exist for backwards compatibility. Sensitive
|
10
|
+
# members are now computed for each request/response type. This can be
|
11
|
+
# removed in a new major version. This list is no longer updated.
|
12
|
+
#
|
8
13
|
# A managed list of sensitive parameters that should be filtered from
|
9
14
|
# logs. This is updated automatically as part of each release. See the
|
10
|
-
# `tasks/sensitive.rake` for more information.
|
15
|
+
# `tasks/update-sensitive-params.rake` for more information.
|
11
16
|
#
|
12
17
|
# @api private
|
13
18
|
# begin
|
14
|
-
SENSITIVE = [:access_token, :account_name, :account_password, :address, :admin_contact, :admin_password, :artifact_credentials, :auth_code, :authentication_token, :authorization_result, :backup_plan_tags, :backup_vault_tags, :base_32_string_seed, :body, :bot_configuration, :bot_email, :cause, :client_id, :client_secret, :configuration, :copy_source_sse_customer_key, :credentials, :current_password, :custom_attributes, :db_password, :default_phone_number, :definition, :description, :display_name, :e164_phone_number, :email, :email_address, :email_message, :embed_url, :error, :feedback_token, :file, :first_name, :id, :id_token, :input, :input_text, :key_id, :key_store_password, :kms_key_id, :kms_master_key_id, :lambda_function_arn, :last_name, :local_console_password, :master_account_email, :master_user_password, :message, :name, :new_password, :next_password, :notes, :old_password, :outbound_events_https_endpoint, :output, :owner_information, :parameters, :passphrase, :password, :payload, :phone_number, :plaintext, :previous_password, :primary_email, :primary_provisioned_number, :private_key, :proposed_password, :public_key, :qr_code_png, :query, :recovery_point_tags, :refresh_token, :registrant_contact, :request_attributes, :search_query, :secret_access_key, :secret_binary, :secret_code, :secret_hash, :secret_string, :secret_to_authenticate_initiator, :secret_to_authenticate_target, :security_token, :service_password, :session_attributes, :share_notes, :shared_secret, :slots, :sse_customer_key, :ssekms_key_id, :status_message, :tag_key_list, :tags, :task_parameters, :tech_contact, :temporary_password, :text, :token, :trust_password, :upload_credentials, :upload_url, :user_email, :user_name, :username, :value, :values, :variables, :zip_file]
|
19
|
+
SENSITIVE = [:access_token, :account_name, :account_password, :address, :admin_contact, :admin_password, :alexa_for_business_room_arn, :artifact_credentials, :auth_code, :auth_parameters, :authentication_token, :authorization_result, :backup_plan_tags, :backup_vault_tags, :base_32_string_seed, :basic_auth_credentials, :block, :block_address, :block_data, :blocks, :body, :bot_configuration, :bot_email, :calling_name, :cause, :client_id, :client_request_token, :client_secret, :comment, :configuration, :content, :copy_source_sse_customer_key, :credentials, :current_password, :custom_attributes, :custom_private_key, :db_password, :default_phone_number, :definition, :description, :destination_access_token, :digest_tip_address, :display_name, :domain_signing_private_key, :e164_phone_number, :email, :email_address, :email_message, :embed_url, :emergency_phone_number, :error, :external_meeting_id, :external_model_endpoint_data_blobs, :external_user_id, :fall_back_phone_number, :feedback_token, :file, :filter_expression, :first_name, :full_name, :host_key, :id, :id_token, :input, :input_text, :ion_text, :join_token, :key, :key_id, :key_material, :key_store_password, :kms_key_id, :kms_master_key_id, :lambda_function_arn, :last_name, :local_console_password, :master_account_email, :master_user_name, :master_user_password, :meeting_host_id, :message, :metadata, :name, :new_password, :next_password, :notes, :number, :oauth_token, :old_password, :outbound_events_https_endpoint, :output, :owner_information, :parameters, :passphrase, :password, :payload, :phone_number, :plaintext, :previous_password, :primary_email, :primary_provisioned_number, :private_key, :private_key_plaintext, :proof, :proposed_password, :proxy_phone_number, :public_key, :qr_code_png, :query, :random_password, :recovery_point_tags, :refresh_token, :registrant_contact, :request_attributes, :resource_arn, :restore_metadata, :revision, :saml_assertion, :search_query, :secret_access_key, :secret_binary, :secret_code, :secret_hash, :secret_string, :secret_to_authenticate_initiator, :secret_to_authenticate_target, :security_token, :service_password, :session_attributes, :session_token, :share_notes, :shared_secret, :slots, :sns_topic_arn, :source_access_token, :sqs_queue_arn, :sse_customer_key, :ssekms_encryption_context, :ssekms_key_id, :status_message, :tag_key_list, :tags, :target_address, :task_parameters, :tech_contact, :temporary_password, :test_phone_number, :text, :token, :trust_password, :type, :upload_credentials, :upload_url, :uri, :user_data, :user_email, :user_name, :user_password, :username, :value, :values, :variables, :vpn_psk, :web_identity_token, :zip_file]
|
15
20
|
# end
|
16
21
|
|
17
22
|
def initialize(options = {})
|
18
|
-
@
|
23
|
+
@enabled = options[:filter_sensitive_params] != false
|
24
|
+
@additional_filters = options[:filter] || []
|
19
25
|
end
|
20
26
|
|
21
|
-
def filter(
|
22
|
-
case
|
23
|
-
when Struct
|
24
|
-
when
|
25
|
-
|
27
|
+
def filter(values, type)
|
28
|
+
case values
|
29
|
+
when Struct then filter_struct(values, type)
|
30
|
+
when Hash then filter_hash(values, type)
|
31
|
+
when Array then filter_array(values, type)
|
32
|
+
else values
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
29
36
|
private
|
30
37
|
|
31
|
-
def
|
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
|
+
|
45
|
+
def filter_hash(values, type)
|
46
|
+
if type.const_defined?('SENSITIVE')
|
47
|
+
filters = type::SENSITIVE + @additional_filters
|
48
|
+
else
|
49
|
+
# Support backwards compatibility (new core + old service)
|
50
|
+
filters = SENSITIVE + @additional_filters
|
51
|
+
end
|
52
|
+
|
32
53
|
filtered = {}
|
33
54
|
values.each_pair do |key, value|
|
34
|
-
filtered[key] = @filters.include?(key)
|
55
|
+
filtered[key] = if @enabled && filters.include?(key)
|
56
|
+
'[FILTERED]'
|
57
|
+
else
|
58
|
+
filter(value, type)
|
59
|
+
end
|
35
60
|
end
|
36
61
|
filtered
|
37
62
|
end
|
38
63
|
|
39
|
-
def filter_array(values)
|
40
|
-
values.map { |value| filter(value) }
|
64
|
+
def filter_array(values, type)
|
65
|
+
values.map { |value| filter(value, type) }
|
41
66
|
end
|
42
67
|
|
43
68
|
end
|