Skip to content

Commit d3be3fc

Browse files
author
Andre Araujo
committed
fix(maxAttempts): Add new configuration maxAttempts in RemoteProviderConfig
The configuration maxRetries was changed to maxAttempts in middleware-retry to be compliant with other SDKs and retry strategy smithy-lang#1244. This change adds new configuration maxAttempts in RemoteProviderConfig and deprecates maxRetries.
1 parent 86862ea commit d3be3fc

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

.changeset/red-coats-visit.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/credential-provider-imds": minor
3+
---
4+
5+
The configuration maxRetries was changed to maxAttempts in middleware-retry to be compliant with other SDKs and retry strategy #1244. This change adds new configuration maxAttempts in RemoteProviderConfig and deprecates maxRetries.

packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.spec.ts

+44
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,48 @@ describe("providerConfigFromInit", () => {
1717
maxRetries,
1818
});
1919
});
20+
21+
it("should return maxAttempts with the same value as the deprecated maxRetries if maxAttempts is NOT provided", () => {
22+
const timeout = 123456789;
23+
const maxRetries = 987654321;
24+
25+
expect(providerConfigFromInit({ timeout, maxRetries })).toEqual({
26+
timeout,
27+
maxRetries,
28+
maxAttempts: maxRetries,
29+
});
30+
});
31+
32+
it("should return maxAttempts with the same value as maxAttempts option if it is provided", () => {
33+
const timeout = 123456789;
34+
const maxRetries = 987654321;
35+
const maxAttempts = 987654322;
36+
37+
expect(providerConfigFromInit({ timeout, maxRetries, maxAttempts })).toEqual({
38+
timeout,
39+
maxRetries,
40+
maxAttempts,
41+
});
42+
});
43+
44+
it("should return maxAttempts with DEFAULT_MAX_RETRIES as value if both maxAttempts and maxRetries are NOT provided", () => {
45+
const timeout = 123456789;
46+
47+
expect(providerConfigFromInit({ timeout })).toEqual({
48+
timeout,
49+
maxRetries: 0,
50+
maxAttempts: 0,
51+
});
52+
});
53+
54+
it("should return maxRetries with the same value as the new maxRetries maxAttempts if maxAttempts is provided with any value", () => {
55+
const timeout = 123456789;
56+
const maxAttempts = 987654321;
57+
58+
expect(providerConfigFromInit({ timeout, maxAttempts })).toEqual({
59+
timeout,
60+
maxRetries: maxAttempts,
61+
maxAttempts,
62+
});
63+
});
2064
});

packages/credential-provider-imds/src/remoteProvider/RemoteProviderInit.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@ export interface RemoteProviderConfig {
2222
timeout: number;
2323

2424
/**
25+
* @deprecated The configuration maxRetries was changed to maxAttempts in middleware-retry to be compliant with other SDKs and retry strategy [#1244](https://github.com/aws/aws-sdk-js-v3/pull/1244). Use maxAttempts instead.
2526
* The maximum number of times the HTTP connection should be retried
2627
*/
27-
maxRetries: number;
28+
maxRetries?: number;
29+
30+
/**
31+
* The maximum number of times the HTTP connection should be retried
32+
*/
33+
maxAttempts?: number;
2834
}
2935

3036
/**
@@ -47,5 +53,14 @@ export interface RemoteProviderInit extends Partial<RemoteProviderConfig> {
4753
*/
4854
export const providerConfigFromInit = ({
4955
maxRetries = DEFAULT_MAX_RETRIES,
56+
maxAttempts,
5057
timeout = DEFAULT_TIMEOUT,
51-
}: RemoteProviderInit): RemoteProviderConfig => ({ maxRetries, timeout });
58+
}: RemoteProviderInit): RemoteProviderConfig => {
59+
const effectiveMaxAttempts = maxAttempts || maxRetries;
60+
61+
return {
62+
maxRetries: effectiveMaxAttempts,
63+
maxAttempts: effectiveMaxAttempts,
64+
timeout
65+
};
66+
}

0 commit comments

Comments
 (0)