Skip to content

Commit 912dcec

Browse files
authored
Changes needed for DDB (#333)
1 parent bec7e95 commit 912dcec

File tree

23 files changed

+157
-71
lines changed

23 files changed

+157
-71
lines changed

gems/smithy-client/lib/smithy-client/handler_list.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def entries
5555
# * `:validate`
5656
# * `:build`
5757
# * `:retry`
58-
# * `:parse`
5958
# * `:sign`
6059
# * `:send`
6160
#
@@ -86,7 +85,6 @@ def entries
8685
# * `:validate`
8786
# * `:build`
8887
# * `:retry`
89-
# * `:parse`
9088
# * `:sign`
9189
# * `:send`
9290
#

gems/smithy-client/lib/smithy-client/http/response.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ def signal_done(options = {})
9898
@done = true
9999
emit(:done)
100100
else
101-
msg = 'options must be empty or must contain :status_code, :headers, ' \
102-
'and :body'
103-
raise ArgumentError, msg
101+
raise ArgumentError, 'options must be empty or must contain :status_code, :headers, and :body'
104102
end
105103
end
106104

gems/smithy-client/lib/smithy-client/log_param_formatter.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def initialize(options = {})
1515

1616
def summarize(value)
1717
case value
18-
when Array then "[#{array(value)}]"
18+
when Array then array(value)
1919
when File then file(value)
20-
when Hash then "{ #{hash(value)} }"
20+
when Hash then hash(value)
2121
when Pathname then pathname(value)
2222
when String then string(value)
2323
when Tempfile then tempfile(value)
@@ -36,17 +36,24 @@ def string(str)
3636
end
3737

3838
def hash(hash)
39-
hash.map do |key, value|
40-
if key.is_a?(String)
41-
"#{key.inspect} => #{summarize(value)}"
42-
else
43-
"#{key}: #{summarize(value)}"
44-
end
45-
end.join(', ')
39+
return if hash.empty?
40+
41+
res =
42+
hash.map do |key, value|
43+
if key.is_a?(String)
44+
"#{key.inspect} => #{summarize(value)}"
45+
else
46+
"#{key}: #{summarize(value)}"
47+
end
48+
end.join(', ')
49+
"{ #{res} }"
4650
end
4751

4852
def array(array)
49-
array.map { |v| summarize(v) }.join(', ')
53+
return if array.empty?
54+
55+
res = array.map { |v| summarize(v) }.join(', ')
56+
"[#{res}]"
5057
end
5158

5259
def file(file)

gems/smithy-client/lib/smithy-client/net_http/handler.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,7 @@ def net_http_request_class(request)
137137
# @param [Http::Request] request
138138
# @return [Hash<String, String>]
139139
def net_headers_for(request)
140-
# Net::HTTP adds a default header for accept-encoding (2.0.0+).
141-
# Setting a default empty value defeats this.
142-
# Removing this is necessary for most services to not break request
143-
# signatures as well as dynamodb crc32 checks (these fail if the
144-
# response is gzipped).
145-
headers = { 'accept-encoding' => '' }
140+
headers = {}
146141
request.headers.each_pair do |key, value|
147142
headers[key] = value
148143
end

gems/smithy-client/lib/smithy-client/pageable_response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def next_page_params(params)
130130
prev_tokens = @paginator.prev_tokens(context.params)
131131
# Remove all previous tokens from original params
132132
# Sometimes a token can be nil and merge would not include it.
133-
new_params = context.params.except(*prev_tokens)
133+
new_params = context[:original_params].except(*prev_tokens)
134134
new_params.merge!(@paginator.next_tokens(data).merge(params))
135135
end
136136
end

gems/smithy-client/lib/smithy-client/param_converter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def union(ref, values)
8484
if values.is_a?(Schema::Union)
8585
_name, member_ref = ref.shape.member_by_type(values.class)
8686
values = shape(member_ref, values)
87-
else
87+
elsif values.is_a?(Hash)
8888
key, value = values.first
8989
values[key] = shape(ref.shape.member(key), value)
9090
end

gems/smithy-client/lib/smithy-client/param_validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def union(ref, values, errors, context)
150150
if values.is_a?(Schema::Union)
151151
_name, member_ref = ref.shape.member_by_type(values.class)
152152
shape(member_ref, values.value, errors, context)
153-
else
153+
elsif values.is_a?(Hash)
154154
values.each_pair do |name, value|
155155
next if value.nil?
156156

gems/smithy-client/lib/smithy-client/plugins/pageable_response.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class PageableResponse < Plugin
88
# @api private
99
class Handler < Client::Handler
1010
def call(context)
11+
context[:original_params] = context.params
1112
response = @handler.call(context)
1213
response.extend(Client::PageableResponse)
1314
response.paginator = context.operation[:paginator] || NullPaginator.new

gems/smithy-client/lib/smithy-client/plugins/retry_errors.rb

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,38 @@ class RetryErrors < Plugin
3333
DOCS
3434

3535
option(
36-
:retry_backoff,
37-
default: Retry::EXPONENTIAL_BACKOFF,
38-
doc_default: 'Smithy::Client::Retry::EXPONENTIAL_BACKOFF',
39-
doc_type: 'lambda',
36+
:retry_max_delay,
37+
default: 20,
38+
docstring: <<~DOCS)
39+
The maximum delay, in seconds, between retry attempts. This option is ignored
40+
if a custom `retry_backoff` is provided. Used in the `standard` and `adaptive`
41+
retry strategies.
42+
DOCS
43+
44+
option(
45+
:retry_base_delay,
46+
default: 2,
4047
docstring: <<~DOCS)
48+
The base delay, in seconds, used to calculate the exponential backoff for
49+
retry attempts. This option is ignored if a custom `retry_backoff` is provided.
50+
Used in the `standard` and `adaptive` retry strategies.
51+
DOCS
52+
53+
option(
54+
:retry_backoff,
55+
doc_default: 'Smithy::Client::Retry::ExponentialBackoff.new',
56+
rbs_type: 'Smithy::Client::Retry::ExponentialBackoff',
57+
doc_type: '#call(attempts)',
58+
docstring: <<~DOCS) do |config|
4159
A callable object that calculates a backoff delay for a retry attempt. The callable
4260
should accept a single argument, `attempts`, that represents the number of attempts
4361
that have been made. Used in the `standard` and `adaptive` retry strategies.
4462
DOCS
63+
Retry::ExponentialBackoff.new(
64+
retry_base_delay: config.retry_base_delay,
65+
retry_max_delay: config.retry_max_delay
66+
)
67+
end
4568

4669
option(
4770
:adaptive_retry_wait_to_fill,

gems/smithy-client/lib/smithy-client/retry.rb

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,7 @@
22

33
require_relative 'retry/adaptive'
44
require_relative 'retry/client_rate_limiter'
5+
require_relative 'retry/exponential_backoff'
56
require_relative 'retry/quota'
67
require_relative 'retry/standard'
7-
8-
module Smithy
9-
module Client
10-
module Retry
11-
# The maximum backoff delay for retrying requests.
12-
MAX_BACKOFF = 20
13-
14-
# The default backoff for retrying requests.
15-
EXPONENTIAL_BACKOFF = lambda do |attempts|
16-
[Kernel.rand * (2**attempts), MAX_BACKOFF].min || 0
17-
end
18-
19-
# Represents a token that can be used to retry an operation.
20-
class Token
21-
def initialize
22-
@retry_count = 0
23-
@retry_delay = 0
24-
end
25-
26-
# The number of times the operation has been retried.
27-
# @return [Integer]
28-
attr_accessor :retry_count
29-
30-
# The delay before the next retry.
31-
# @return [Numeric]
32-
attr_accessor :retry_delay
33-
end
34-
end
35-
end
36-
end
8+
require_relative 'retry/token'

0 commit comments

Comments
 (0)