aws-sdk-core 3.117.0 → 3.197.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +836 -0
- data/VERSION +1 -1
- data/lib/aws-defaults/default_configuration.rb +153 -0
- data/lib/aws-defaults/defaults_mode_config_resolver.rb +107 -0
- data/lib/aws-defaults.rb +3 -0
- data/lib/aws-sdk-core/arn.rb +13 -0
- data/lib/aws-sdk-core/assume_role_credentials.rb +21 -7
- data/lib/aws-sdk-core/assume_role_web_identity_credentials.rb +14 -10
- data/lib/aws-sdk-core/binary/decode_handler.rb +0 -5
- data/lib/aws-sdk-core/binary/encode_handler.rb +12 -1
- data/lib/aws-sdk-core/binary/event_builder.rb +34 -37
- data/lib/aws-sdk-core/client_stubs.rb +20 -13
- data/lib/aws-sdk-core/credential_provider.rb +4 -1
- data/lib/aws-sdk-core/credential_provider_chain.rb +8 -5
- data/lib/aws-sdk-core/ec2_metadata.rb +4 -3
- data/lib/aws-sdk-core/ecs_credentials.rb +187 -52
- data/lib/aws-sdk-core/endpoints/condition.rb +41 -0
- data/lib/aws-sdk-core/endpoints/endpoint.rb +17 -0
- data/lib/aws-sdk-core/endpoints/endpoint_rule.rb +75 -0
- data/lib/aws-sdk-core/endpoints/error_rule.rb +42 -0
- data/lib/aws-sdk-core/endpoints/function.rb +80 -0
- data/lib/aws-sdk-core/endpoints/matchers.rb +135 -0
- data/lib/aws-sdk-core/endpoints/reference.rb +31 -0
- data/lib/aws-sdk-core/endpoints/rule.rb +25 -0
- data/lib/aws-sdk-core/endpoints/rule_set.rb +52 -0
- data/lib/aws-sdk-core/endpoints/rules_provider.rb +37 -0
- data/lib/aws-sdk-core/endpoints/templater.rb +58 -0
- data/lib/aws-sdk-core/endpoints/tree_rule.rb +45 -0
- data/lib/aws-sdk-core/endpoints/url.rb +60 -0
- data/lib/aws-sdk-core/endpoints.rb +78 -0
- data/lib/aws-sdk-core/errors.rb +17 -4
- data/lib/aws-sdk-core/event_emitter.rb +0 -16
- data/lib/aws-sdk-core/ini_parser.rb +7 -0
- data/lib/aws-sdk-core/instance_profile_credentials.rb +127 -33
- data/lib/aws-sdk-core/json/builder.rb +8 -1
- data/lib/aws-sdk-core/json/error_handler.rb +30 -4
- data/lib/aws-sdk-core/json/handler.rb +8 -1
- data/lib/aws-sdk-core/json/json_engine.rb +10 -8
- data/lib/aws-sdk-core/json/oj_engine.rb +33 -6
- data/lib/aws-sdk-core/json/parser.rb +38 -2
- data/lib/aws-sdk-core/json.rb +8 -26
- data/lib/aws-sdk-core/log/formatter.rb +6 -0
- data/lib/aws-sdk-core/log/param_filter.rb +9 -1
- data/lib/aws-sdk-core/lru_cache.rb +75 -0
- data/lib/aws-sdk-core/pageable_response.rb +81 -32
- data/lib/aws-sdk-core/param_validator.rb +36 -2
- data/lib/aws-sdk-core/plugins/bearer_authorization.rb +67 -0
- data/lib/aws-sdk-core/plugins/checksum_algorithm.rb +342 -0
- data/lib/aws-sdk-core/plugins/client_metrics_plugin.rb +1 -0
- data/lib/aws-sdk-core/plugins/client_metrics_send_plugin.rb +14 -2
- data/lib/aws-sdk-core/plugins/credentials_configuration.rb +29 -1
- data/lib/aws-sdk-core/plugins/defaults_mode.rb +40 -0
- data/lib/aws-sdk-core/plugins/endpoint_discovery.rb +6 -2
- data/lib/aws-sdk-core/plugins/http_checksum.rb +9 -1
- data/lib/aws-sdk-core/plugins/invocation_id.rb +1 -11
- data/lib/aws-sdk-core/plugins/jsonvalue_converter.rb +34 -6
- data/lib/aws-sdk-core/plugins/logging.rb +2 -0
- data/lib/aws-sdk-core/plugins/protocols/api_gateway.rb +17 -0
- data/lib/aws-sdk-core/plugins/protocols/rest_json.rb +4 -2
- data/lib/aws-sdk-core/plugins/protocols/rest_xml.rb +1 -2
- data/lib/aws-sdk-core/plugins/recursion_detection.rb +38 -0
- data/lib/aws-sdk-core/plugins/regional_endpoint.rb +144 -17
- data/lib/aws-sdk-core/plugins/request_compression.rb +226 -0
- data/lib/aws-sdk-core/plugins/response_paging.rb +1 -1
- data/lib/aws-sdk-core/plugins/retries/error_inspector.rb +7 -4
- data/lib/aws-sdk-core/plugins/retry_errors.rb +33 -7
- data/lib/aws-sdk-core/plugins/sign.rb +211 -0
- data/lib/aws-sdk-core/plugins/signature_v2.rb +1 -0
- data/lib/aws-sdk-core/plugins/signature_v4.rb +28 -31
- data/lib/aws-sdk-core/plugins/stub_responses.rb +6 -1
- data/lib/aws-sdk-core/plugins/user_agent.rb +152 -14
- data/lib/aws-sdk-core/process_credentials.rb +50 -34
- data/lib/aws-sdk-core/query/ec2_param_builder.rb +5 -7
- data/lib/aws-sdk-core/query/param_builder.rb +2 -2
- data/lib/aws-sdk-core/refreshing_credentials.rb +49 -18
- data/lib/aws-sdk-core/refreshing_token.rb +71 -0
- data/lib/aws-sdk-core/rest/handler.rb +1 -1
- data/lib/aws-sdk-core/rest/request/body.rb +49 -4
- data/lib/aws-sdk-core/rest/request/content_type.rb +60 -0
- data/lib/aws-sdk-core/rest/request/endpoint.rb +24 -4
- data/lib/aws-sdk-core/rest/request/headers.rb +23 -7
- data/lib/aws-sdk-core/rest/request/querystring_builder.rb +62 -36
- data/lib/aws-sdk-core/rest/response/body.rb +15 -1
- data/lib/aws-sdk-core/rest/response/header_list_parser.rb +79 -0
- data/lib/aws-sdk-core/rest/response/headers.rb +10 -3
- data/lib/aws-sdk-core/rest.rb +1 -0
- data/lib/aws-sdk-core/shared_config.rb +112 -12
- data/lib/aws-sdk-core/sso_credentials.rb +92 -51
- data/lib/aws-sdk-core/sso_token_provider.rb +135 -0
- data/lib/aws-sdk-core/static_token_provider.rb +14 -0
- data/lib/aws-sdk-core/structure.rb +16 -5
- data/lib/aws-sdk-core/stubbing/stub_data.rb +11 -0
- data/lib/aws-sdk-core/token.rb +31 -0
- data/lib/aws-sdk-core/token_provider.rb +15 -0
- data/lib/aws-sdk-core/token_provider_chain.rb +51 -0
- data/lib/aws-sdk-core/util.rb +39 -0
- data/lib/aws-sdk-core/waiters/poller.rb +4 -2
- data/lib/aws-sdk-core/xml/builder.rb +17 -9
- data/lib/aws-sdk-core/xml/error_handler.rb +31 -8
- data/lib/aws-sdk-core/xml/parser/engines/oga.rb +2 -0
- data/lib/aws-sdk-core/xml/parser/engines/ox.rb +1 -1
- data/lib/aws-sdk-core/xml/parser/engines/rexml.rb +0 -8
- data/lib/aws-sdk-core/xml/parser/frame.rb +27 -20
- data/lib/aws-sdk-core/xml/parser/stack.rb +2 -0
- data/lib/aws-sdk-core.rb +21 -0
- data/lib/aws-sdk-sso/client.rb +157 -50
- data/lib/aws-sdk-sso/endpoint_parameters.rb +66 -0
- data/lib/aws-sdk-sso/endpoint_provider.rb +57 -0
- data/lib/aws-sdk-sso/endpoints.rb +72 -0
- data/lib/aws-sdk-sso/plugins/endpoints.rb +78 -0
- data/lib/aws-sdk-sso/types.rb +8 -43
- data/lib/aws-sdk-sso.rb +5 -1
- data/lib/aws-sdk-ssooidc/client.rb +1008 -0
- data/lib/aws-sdk-ssooidc/client_api.rb +293 -0
- data/lib/aws-sdk-ssooidc/customizations.rb +1 -0
- data/lib/aws-sdk-ssooidc/endpoint_parameters.rb +66 -0
- data/lib/aws-sdk-ssooidc/endpoint_provider.rb +57 -0
- data/lib/aws-sdk-ssooidc/endpoints.rb +72 -0
- data/lib/aws-sdk-ssooidc/errors.rb +342 -0
- data/lib/aws-sdk-ssooidc/plugins/endpoints.rb +78 -0
- data/lib/aws-sdk-ssooidc/resource.rb +26 -0
- data/lib/aws-sdk-ssooidc/types.rb +823 -0
- data/lib/aws-sdk-ssooidc.rb +59 -0
- data/lib/aws-sdk-sts/client.rb +472 -398
- data/lib/aws-sdk-sts/client_api.rb +20 -9
- data/lib/aws-sdk-sts/endpoint_parameters.rb +78 -0
- data/lib/aws-sdk-sts/endpoint_provider.rb +112 -0
- data/lib/aws-sdk-sts/endpoints.rb +136 -0
- data/lib/aws-sdk-sts/plugins/endpoints.rb +86 -0
- data/lib/aws-sdk-sts/plugins/sts_regional_endpoints.rb +5 -1
- data/lib/aws-sdk-sts/presigner.rb +14 -10
- data/lib/aws-sdk-sts/types.rb +168 -227
- data/lib/aws-sdk-sts.rb +5 -1
- data/lib/seahorse/client/async_base.rb +1 -2
- data/lib/seahorse/client/async_response.rb +19 -0
- data/lib/seahorse/client/base.rb +1 -0
- data/lib/seahorse/client/configuration.rb +5 -5
- data/lib/seahorse/client/h2/connection.rb +15 -16
- data/lib/seahorse/client/h2/handler.rb +5 -5
- data/lib/seahorse/client/net_http/connection_pool.rb +10 -9
- data/lib/seahorse/client/net_http/handler.rb +15 -7
- data/lib/seahorse/client/net_http/patches.rb +12 -86
- data/lib/seahorse/client/plugin.rb +9 -0
- data/lib/seahorse/client/plugins/content_length.rb +11 -5
- data/lib/seahorse/client/plugins/h2.rb +3 -3
- data/lib/seahorse/client/plugins/net_http.rb +73 -10
- data/lib/seahorse/client/plugins/request_callback.rb +40 -9
- data/lib/seahorse/client/response.rb +6 -0
- data/lib/seahorse/model/operation.rb +6 -0
- data/lib/seahorse/model/shapes.rb +27 -2
- data/lib/seahorse/util.rb +4 -0
- data/sig/aws-sdk-core/client_stubs.rbs +10 -0
- data/sig/aws-sdk-core/errors.rbs +22 -0
- data/sig/aws-sdk-core/resources/collection.rbs +21 -0
- data/sig/aws-sdk-core/structure.rbs +4 -0
- data/sig/aws-sdk-core/waiters/errors.rbs +20 -0
- data/sig/aws-sdk-core.rbs +7 -0
- data/sig/seahorse/client/base.rbs +25 -0
- data/sig/seahorse/client/handler_builder.rbs +16 -0
- data/sig/seahorse/client/response.rbs +61 -0
- metadata +82 -17
- data/lib/aws-sdk-sso/plugins/content_type.rb +0 -25
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
# @api private
|
5
|
+
# A simple thread safe LRU cache
|
6
|
+
class LRUCache
|
7
|
+
# @param [Hash] options
|
8
|
+
# @option options [Integer] :max_entries (100) Maximum number of entries
|
9
|
+
# @option options [Integer] :expiration (nil) Expiration time in seconds
|
10
|
+
def initialize(options = {})
|
11
|
+
@max_entries = options[:max_entries] || 100
|
12
|
+
@expiration = options[:expiration]
|
13
|
+
@entries = {}
|
14
|
+
@mutex = Mutex.new
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [String] key
|
18
|
+
# @return [Object]
|
19
|
+
def [](key)
|
20
|
+
@mutex.synchronize do
|
21
|
+
value = @entries[key]
|
22
|
+
if value
|
23
|
+
@entries.delete(key)
|
24
|
+
@entries[key] = value unless value.expired?
|
25
|
+
end
|
26
|
+
@entries[key]&.value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [String] key
|
31
|
+
# @param [Object] value
|
32
|
+
def []=(key, value)
|
33
|
+
@mutex.synchronize do
|
34
|
+
@entries.shift unless @entries.size < @max_entries
|
35
|
+
# delete old value if exists
|
36
|
+
@entries.delete(key)
|
37
|
+
@entries[key] = Entry.new(value: value, expiration: @expiration)
|
38
|
+
@entries[key].value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param [String] key
|
43
|
+
# @return [Boolean]
|
44
|
+
def key?(key)
|
45
|
+
@mutex.synchronize do
|
46
|
+
@entries.delete(key) if @entries.key?(key) && @entries[key].expired?
|
47
|
+
@entries.key?(key)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def clear
|
52
|
+
@mutex.synchronize do
|
53
|
+
@entries.clear
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @api private
|
58
|
+
class Entry
|
59
|
+
def initialize(options = {})
|
60
|
+
@value = options[:value]
|
61
|
+
@expiration = options[:expiration]
|
62
|
+
@created_time = Time.now
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Object]
|
66
|
+
attr_reader :value
|
67
|
+
|
68
|
+
def expired?
|
69
|
+
return false unless @expiration
|
70
|
+
|
71
|
+
Time.now - @created_time > @expiration
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -48,11 +48,11 @@ module Aws
|
|
48
48
|
#
|
49
49
|
module PageableResponse
|
50
50
|
|
51
|
-
def self.
|
52
|
-
base.extend
|
53
|
-
base.
|
54
|
-
base.instance_variable_set(
|
55
|
-
base
|
51
|
+
def self.apply(base)
|
52
|
+
base.extend Extension
|
53
|
+
base.instance_variable_set(:@last_page, nil)
|
54
|
+
base.instance_variable_set(:@more_results, nil)
|
55
|
+
base
|
56
56
|
end
|
57
57
|
|
58
58
|
# @return [Paging::Pager]
|
@@ -62,39 +62,26 @@ module Aws
|
|
62
62
|
# when this method returns `false` will raise an error.
|
63
63
|
# @return [Boolean]
|
64
64
|
def last_page?
|
65
|
-
|
66
|
-
@last_page = !@pager.truncated?(self)
|
67
|
-
end
|
68
|
-
@last_page
|
65
|
+
# Actual implementation is in PageableResponse::Extension
|
69
66
|
end
|
70
67
|
|
71
68
|
# Returns `true` if there are more results. Calling {#next_page} will
|
72
69
|
# return the next response.
|
73
70
|
# @return [Boolean]
|
74
71
|
def next_page?
|
75
|
-
|
72
|
+
# Actual implementation is in PageableResponse::Extension
|
76
73
|
end
|
77
74
|
|
78
75
|
# @return [Seahorse::Client::Response]
|
79
76
|
def next_page(params = {})
|
80
|
-
|
81
|
-
raise LastPageError.new(self)
|
82
|
-
else
|
83
|
-
next_response(params)
|
84
|
-
end
|
77
|
+
# Actual implementation is in PageableResponse::Extension
|
85
78
|
end
|
86
79
|
|
87
80
|
# Yields the current and each following response to the given block.
|
88
81
|
# @yieldparam [Response] response
|
89
82
|
# @return [Enumerable,nil] Returns a new Enumerable if no block is given.
|
90
83
|
def each(&block)
|
91
|
-
|
92
|
-
response = self
|
93
|
-
yield(response)
|
94
|
-
until response.last_page?
|
95
|
-
response = response.next_page
|
96
|
-
yield(response)
|
97
|
-
end
|
84
|
+
# Actual implementation is in PageableResponse::Extension
|
98
85
|
end
|
99
86
|
alias each_page each
|
100
87
|
|
@@ -105,9 +92,7 @@ module Aws
|
|
105
92
|
# @return [Seahorse::Client::Response] Returns the next page of
|
106
93
|
# results.
|
107
94
|
def next_response(params)
|
108
|
-
|
109
|
-
request = context.client.build_request(context.operation_name, params)
|
110
|
-
request.send_request
|
95
|
+
# Actual implementation is in PageableResponse::Extension
|
111
96
|
end
|
112
97
|
|
113
98
|
# @param [Hash] params A hash of additional request params to
|
@@ -115,13 +100,7 @@ module Aws
|
|
115
100
|
# @return [Hash] Returns the hash of request parameters for the
|
116
101
|
# next page, merging any given params.
|
117
102
|
def next_page_params(params)
|
118
|
-
#
|
119
|
-
# Sometimes a token can be nil and merge would not include it.
|
120
|
-
tokens = @pager.tokens.values.map(&:to_sym)
|
121
|
-
|
122
|
-
params_without_tokens = context[:original_params].reject { |k, _v| tokens.include?(k) }
|
123
|
-
params_without_tokens.merge!(@pager.next_tokens(self).merge(params))
|
124
|
-
params_without_tokens
|
103
|
+
# Actual implementation is in PageableResponse::Extension
|
125
104
|
end
|
126
105
|
|
127
106
|
# Raised when calling {PageableResponse#next_page} on a pager that
|
@@ -167,6 +146,76 @@ module Aws
|
|
167
146
|
data.to_h
|
168
147
|
end
|
169
148
|
|
149
|
+
def as_json(_options = {})
|
150
|
+
data.to_h(data, as_json: true)
|
151
|
+
end
|
152
|
+
|
153
|
+
def to_json(options = {})
|
154
|
+
as_json.to_json(options)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# The actual decorator module implementation. It is in a distinct module
|
159
|
+
# so that it can be used to extend objects without busting Ruby's constant cache.
|
160
|
+
# object.extend(mod) bust the constant cache only if `mod` contains constants of its own.
|
161
|
+
# @api private
|
162
|
+
module Extension
|
163
|
+
|
164
|
+
include Enumerable
|
165
|
+
include UnsafeEnumerableMethods
|
166
|
+
|
167
|
+
attr_accessor :pager
|
168
|
+
|
169
|
+
def last_page?
|
170
|
+
if @last_page.nil?
|
171
|
+
@last_page = !@pager.truncated?(self)
|
172
|
+
end
|
173
|
+
@last_page
|
174
|
+
end
|
175
|
+
|
176
|
+
def next_page?
|
177
|
+
!last_page?
|
178
|
+
end
|
179
|
+
|
180
|
+
def next_page(params = {})
|
181
|
+
if last_page?
|
182
|
+
raise LastPageError.new(self)
|
183
|
+
else
|
184
|
+
next_response(params)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def each(&block)
|
189
|
+
return enum_for(:each_page) unless block_given?
|
190
|
+
response = self
|
191
|
+
yield(response)
|
192
|
+
until response.last_page?
|
193
|
+
response = response.next_page
|
194
|
+
yield(response)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
alias each_page each
|
198
|
+
|
199
|
+
private
|
200
|
+
|
201
|
+
def next_response(params)
|
202
|
+
params = next_page_params(params)
|
203
|
+
request = context.client.build_request(context.operation_name, params)
|
204
|
+
Aws::Plugins::UserAgent.metric('PAGINATOR') do
|
205
|
+
request.send_request
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def next_page_params(params)
|
210
|
+
# Remove all previous tokens from original params
|
211
|
+
# Sometimes a token can be nil and merge would not include it.
|
212
|
+
tokens = @pager.tokens.values.map(&:to_sym)
|
213
|
+
|
214
|
+
params_without_tokens = context[:original_params].reject { |k, _v| tokens.include?(k) }
|
215
|
+
params_without_tokens.merge!(@pager.next_tokens(self).merge(params))
|
216
|
+
params_without_tokens
|
217
|
+
end
|
218
|
+
|
170
219
|
end
|
171
220
|
end
|
172
221
|
end
|
@@ -6,7 +6,7 @@ module Aws
|
|
6
6
|
|
7
7
|
include Seahorse::Model::Shapes
|
8
8
|
|
9
|
-
EXPECTED_GOT =
|
9
|
+
EXPECTED_GOT = 'expected %s to be %s, got class %s instead.'
|
10
10
|
|
11
11
|
# @param [Seahorse::Model::Shapes::ShapeRef] rules
|
12
12
|
# @param [Hash] params
|
@@ -70,6 +70,15 @@ module Aws
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
if @validate_required && shape.union
|
74
|
+
set_values = @input ? values.length : values.to_h.length
|
75
|
+
if set_values > 1
|
76
|
+
errors << "multiple values provided to union at #{context} - must contain exactly one of the supported types: #{shape.member_names.join(', ')}"
|
77
|
+
elsif set_values == 0
|
78
|
+
errors << "No values provided to union at #{context} - must contain exactly one of the supported types: #{shape.member_names.join(', ')}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
73
82
|
# validate non-nil members
|
74
83
|
values.each_pair do |name, value|
|
75
84
|
unless value.nil?
|
@@ -98,6 +107,8 @@ module Aws
|
|
98
107
|
# validate members
|
99
108
|
member_ref = ref.shape.member
|
100
109
|
values.each.with_index do |value, index|
|
110
|
+
next unless value
|
111
|
+
|
101
112
|
shape(member_ref, value, errors, context + "[#{index}]")
|
102
113
|
end
|
103
114
|
end
|
@@ -113,15 +124,38 @@ module Aws
|
|
113
124
|
|
114
125
|
values.each do |key, value|
|
115
126
|
shape(key_ref, key, errors, "#{context} #{key.inspect} key")
|
127
|
+
next unless value
|
128
|
+
|
116
129
|
shape(value_ref, value, errors, context + "[#{key.inspect}]")
|
117
130
|
end
|
118
131
|
end
|
119
132
|
|
133
|
+
def document(ref, value, errors, context)
|
134
|
+
document_types = [Hash, Array, Numeric, String, TrueClass, FalseClass, NilClass]
|
135
|
+
unless document_types.any? { |t| value.is_a?(t) }
|
136
|
+
errors << expected_got(context, "one of #{document_types.join(', ')}", value)
|
137
|
+
end
|
138
|
+
|
139
|
+
# recursively validate types for aggregated types
|
140
|
+
case value
|
141
|
+
when Hash
|
142
|
+
value.each do |k, v|
|
143
|
+
document(ref, v, errors, context + "[#{k}]")
|
144
|
+
end
|
145
|
+
when Array
|
146
|
+
value.each do |v|
|
147
|
+
document(ref, v, errors, context)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
120
153
|
def shape(ref, value, errors, context)
|
121
154
|
case ref.shape
|
122
155
|
when StructureShape then structure(ref, value, errors, context)
|
123
156
|
when ListShape then list(ref, value, errors, context)
|
124
157
|
when MapShape then map(ref, value, errors, context)
|
158
|
+
when DocumentShape then document(ref, value, errors, context)
|
125
159
|
when StringShape
|
126
160
|
unless value.is_a?(String)
|
127
161
|
errors << expected_got(context, "a String", value)
|
@@ -201,7 +235,7 @@ module Aws
|
|
201
235
|
end
|
202
236
|
|
203
237
|
def expected_got(context, expected, got)
|
204
|
-
EXPECTED_GOT % [context, expected, got.
|
238
|
+
EXPECTED_GOT % [context, expected, got.class.name]
|
205
239
|
end
|
206
240
|
|
207
241
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Aws
|
4
|
+
# @api private
|
5
|
+
module Plugins
|
6
|
+
# @api private
|
7
|
+
class BearerAuthorization < Seahorse::Client::Plugin
|
8
|
+
|
9
|
+
option(:token_provider,
|
10
|
+
required: false,
|
11
|
+
doc_type: 'Aws::TokenProvider',
|
12
|
+
docstring: <<-DOCS
|
13
|
+
A Bearer Token Provider. This can be an instance of any one of the
|
14
|
+
following classes:
|
15
|
+
|
16
|
+
* `Aws::StaticTokenProvider` - Used for configuring static, non-refreshing
|
17
|
+
tokens.
|
18
|
+
|
19
|
+
* `Aws::SSOTokenProvider` - Used for loading tokens from AWS SSO using an
|
20
|
+
access token generated from `aws login`.
|
21
|
+
|
22
|
+
When `:token_provider` is not configured directly, the `Aws::TokenProviderChain`
|
23
|
+
will be used to search for tokens configured for your profile in shared configuration files.
|
24
|
+
DOCS
|
25
|
+
) do |config|
|
26
|
+
if config.stub_responses
|
27
|
+
StaticTokenProvider.new('token')
|
28
|
+
else
|
29
|
+
TokenProviderChain.new(config).resolve
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def add_handlers(handlers, cfg)
|
35
|
+
bearer_operations =
|
36
|
+
if cfg.api.metadata['signatureVersion'] == 'bearer'
|
37
|
+
# select operations where authtype is either not set or is bearer
|
38
|
+
cfg.api.operation_names.select do |o|
|
39
|
+
!cfg.api.operation(o)['authtype'] || cfg.api.operation(o)['authtype'] == 'bearer'
|
40
|
+
end
|
41
|
+
else # service is not bearer auth
|
42
|
+
# select only operations where authtype is explicitly bearer
|
43
|
+
cfg.api.operation_names.select do |o|
|
44
|
+
cfg.api.operation(o)['authtype'] == 'bearer'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
handlers.add(Handler, step: :sign, operations: bearer_operations)
|
48
|
+
end
|
49
|
+
|
50
|
+
class Handler < Seahorse::Client::Handler
|
51
|
+
def call(context)
|
52
|
+
if context.http_request.endpoint.scheme != 'https'
|
53
|
+
raise ArgumentError, 'Unable to use bearer authorization on non https endpoint.'
|
54
|
+
end
|
55
|
+
|
56
|
+
token_provider = context.config.token_provider
|
57
|
+
if token_provider && token_provider.set?
|
58
|
+
context.http_request.headers['Authorization'] = "Bearer #{token_provider.token.token}"
|
59
|
+
else
|
60
|
+
raise Errors::MissingBearerTokenError
|
61
|
+
end
|
62
|
+
@handler.call(context)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|