Skip to content

Commit c1a56bb

Browse files
committed
chore(config-resolver): resolve fips/dualstack config
1 parent abebc99 commit c1a56bb

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

packages/config-resolver/src/endpointsConfig/resolveCustomEndpointsConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Endpoint, Provider, UrlParser } from "@aws-sdk/types";
22

33
import { EndpointsInputConfig, EndpointsResolvedConfig } from "./resolveEndpointsConfig";
4+
import { normalizeBoolean } from "./utils/normalizeBoolean";
45
import { normalizeEndpoint } from "./utils/normalizeEndpoint";
56

67
export interface CustomEndpointsInputConfig extends EndpointsInputConfig {
@@ -29,4 +30,6 @@ export const resolveCustomEndpointsConfig = <T>(
2930
tls: input.tls ?? true,
3031
endpoint: normalizeEndpoint(input),
3132
isCustomEndpoint: true,
33+
useDualstackEndpoint: normalizeBoolean(input.useDualstackEndpoint!),
34+
useFipsEndpoint: normalizeBoolean(input.useFipsEndpoint!),
3235
});

packages/config-resolver/src/endpointsConfig/resolveEndpointsConfig.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Endpoint, Provider, RegionInfoProvider, UrlParser } from "@aws-sdk/types";
22

33
import { getEndpointFromRegion } from "./utils/getEndpointFromRegion";
4+
import { normalizeBoolean } from "./utils/normalizeBoolean";
45
import { normalizeEndpoint } from "./utils/normalizeEndpoint";
56

67
export interface EndpointsInputConfig {
@@ -13,6 +14,16 @@ export interface EndpointsInputConfig {
1314
* Whether TLS is enabled for requests.
1415
*/
1516
tls?: boolean;
17+
18+
/**
19+
* Enables IPv6/IPv4 dualstack endpoint.
20+
*/
21+
useDualstackEndpoint?: boolean | Provider<boolean>;
22+
23+
/**
24+
* Enables FIPS compatible endpoints.
25+
*/
26+
useFipsEndpoint?: boolean | Provider<boolean>;
1627
}
1728

1829
interface PreviouslyResolved {
@@ -23,7 +34,7 @@ interface PreviouslyResolved {
2334

2435
export interface EndpointsResolvedConfig extends Required<EndpointsInputConfig> {
2536
/**
26-
* Resolved value for input {@link EndpointsResolvedConfig.endpoint}
37+
* Resolved value for input {@link EndpointsInputConfig.endpoint}
2738
*/
2839
endpoint: Provider<Endpoint>;
2940

@@ -32,6 +43,16 @@ export interface EndpointsResolvedConfig extends Required<EndpointsInputConfig>
3243
* @internal
3344
*/
3445
isCustomEndpoint: boolean;
46+
47+
/**
48+
* Resolved value for input {@link EndpointsInputConfig.useDualstackEndpoint}
49+
*/
50+
useDualstackEndpoint: Provider<boolean>;
51+
52+
/**
53+
* Resolved value for input {@link EndpointsInputConfig.useFipsEndpoint}
54+
*/
55+
useFipsEndpoint: Provider<boolean>;
3556
}
3657

3758
export const resolveEndpointsConfig = <T>(
@@ -43,4 +64,6 @@ export const resolveEndpointsConfig = <T>(
4364
? normalizeEndpoint({ ...input, endpoint: input.endpoint })
4465
: () => getEndpointFromRegion(input),
4566
isCustomEndpoint: input.endpoint ? true : false,
67+
useDualstackEndpoint: normalizeBoolean(input.useDualstackEndpoint!),
68+
useFipsEndpoint: normalizeBoolean(input.useFipsEndpoint!),
4669
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { normalizeBoolean } from "./normalizeBoolean";
2+
3+
describe(normalizeBoolean.name, () => {
4+
it.each([true, false])("returns Provider if value is boolean: %s", async (value) => {
5+
const output = normalizeBoolean(value);
6+
expect(await output()).toEqual(value);
7+
});
8+
9+
it.each([true, false])("returns Provider if it's a Provider which returns %s", (value) => {
10+
const mockBooleanProvider = () => Promise.resolve(value);
11+
expect(normalizeBoolean(mockBooleanProvider)).toBe(mockBooleanProvider);
12+
});
13+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Provider } from "@aws-sdk/types";
2+
3+
// TODO: Move to a utility file which can be used across packages
4+
export const normalizeBoolean = (value: boolean | Provider<boolean>): Provider<boolean> => {
5+
if (typeof value === "boolean") {
6+
const promisified = Promise.resolve(value);
7+
return () => promisified;
8+
}
9+
return value as Provider<boolean>;
10+
};

0 commit comments

Comments
 (0)