Skip to content

Commit e71dc0a

Browse files
JordonPhillipsadamthom-amzngosar
authored
chore: merge ssdk branch into main (#2279)
* chore: serialize rest json error code header (#2166) * chore: short-circuit ssdk-incompatible integrations (#2167) * chore: disable idempotency autofill import when not generating a client (#2181) * Support generating non-AWS client (#2222) * feat(config-resolver): make region optional for non-AWS client * feat(codegen): skip integrations that are not relevant for non-AWS services This is an initial version to get a working version of generated code that compiles without manual edits in smithy-typescript-ssdk-demo. I expect to make updates to this logic. * chore(codegen): address code comments The minor ones from adamthom-amzn/aws-sdk-js-v3#1 * fix(codegen): use SigV4Trait check instead of ServiceTrait AddAwsRuntimeConfigTest is checking for some behaviors from AddAwsAuthPlugin too, which was failing with missing aws.auth#sigv4 trait after my change. Added the trait for now to the test, but unit tests will need to be added/refactored for all these changes. * chore(codegen): move isAwsService check to utils class * chore(codegen): code style formatting * chore(codegen): check SigV4 trait for including region * chore(codegen,config-resolver): refactor how endpoint is resolved for non-AWS client (#2287) * chore(config-resolver): refactor EndpointsConfig for non AWS services This reverts an earlier change to EndpointsConfig.ts and instead provides the new functionality in separate CustomEndpointsConfig.ts. This will be used as a separate plugin for endpoint resolution in non AWS clients. * feat(codegen): Use separate CustomEndpointsConfig for non-AWS clients This depends on newly added CustomEndpointsConfig in @aws-sdk/config-resolver package. * test(config-resolver): add test for CustomEndpointsConfig (#2305) Co-authored-by: Adam Thomas <[email protected]> Co-authored-by: Jaykumar Gosar <[email protected]>
1 parent ee27f42 commit e71dc0a

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Endpoint } from "@aws-sdk/types";
2+
3+
import { resolveCustomEndpointsConfig } from "./CustomEndpointsConfig";
4+
5+
describe("CustomEndpointsConfig", () => {
6+
const urlParser = jest.fn();
7+
8+
const input = { urlParser };
9+
10+
afterEach(() => {
11+
jest.clearAllMocks();
12+
});
13+
14+
describe("endpoint", () => {
15+
const mockEndpoint: Endpoint = { protocol: "protocol", hostname: "hostname", path: "path" };
16+
17+
it("returns output of urlParser if endpoint is of type string", async () => {
18+
const endpoint = "endpoint";
19+
urlParser.mockReturnValueOnce(mockEndpoint);
20+
const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint });
21+
expect(isCustomEndpoint).toBe(true);
22+
const endpointOutput = await endpointProvider();
23+
expect(endpointOutput).toStrictEqual(mockEndpoint);
24+
expect(urlParser).toHaveBeenCalledTimes(1);
25+
expect(urlParser).toHaveBeenCalledWith(endpoint);
26+
});
27+
28+
it("returns promisified endpoint if it's of type object", async () => {
29+
const endpoint = mockEndpoint;
30+
const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint });
31+
expect(isCustomEndpoint).toBe(true);
32+
const endpointOutput = await endpointProvider();
33+
expect(endpointOutput).toStrictEqual(endpoint);
34+
expect(urlParser).not.toHaveBeenCalled();
35+
});
36+
37+
it("returns endpoint if it's already Provider<Endpoint>", async () => {
38+
const endpoint = () => Promise.resolve(mockEndpoint);
39+
const { endpoint: endpointProvider, isCustomEndpoint } = resolveCustomEndpointsConfig({ ...input, endpoint });
40+
expect(isCustomEndpoint).toBe(true);
41+
const endpointOutput = await endpointProvider();
42+
expect(endpointOutput).toStrictEqual(mockEndpoint);
43+
expect(urlParser).not.toHaveBeenCalled();
44+
});
45+
});
46+
47+
describe("tls", () => {
48+
const endpoint = "endpoint";
49+
50+
beforeEach(() => {
51+
urlParser.mockReturnValueOnce({ protocol: "protocol", hostname: "hostname", path: "path" });
52+
});
53+
54+
[true, false].forEach((tls) => {
55+
it(`returns input.tls when it's ${tls}`, () => {
56+
expect(resolveCustomEndpointsConfig({ ...input, endpoint, tls }).tls).toStrictEqual(tls);
57+
});
58+
});
59+
60+
it("returns true is input.tls is undefined", () => {
61+
expect(resolveCustomEndpointsConfig({ ...input, endpoint }).tls).toStrictEqual(true);
62+
});
63+
});
64+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Endpoint, Provider, UrlParser } from "@aws-sdk/types";
2+
3+
export interface CustomEndpointsInputConfig {
4+
/**
5+
* The fully qualified endpoint of the webservice.
6+
*/
7+
endpoint: string | Endpoint | Provider<Endpoint>;
8+
9+
/**
10+
* Whether TLS is enabled for requests.
11+
*/
12+
tls?: boolean;
13+
}
14+
15+
interface PreviouslyResolved {
16+
urlParser: UrlParser;
17+
}
18+
19+
export interface CustomEndpointsResolvedConfig extends Required<CustomEndpointsInputConfig> {
20+
endpoint: Provider<Endpoint>;
21+
isCustomEndpoint: true;
22+
}
23+
24+
export const resolveCustomEndpointsConfig = <T>(
25+
input: T & CustomEndpointsInputConfig & PreviouslyResolved
26+
): T & CustomEndpointsResolvedConfig => ({
27+
...input,
28+
tls: input.tls ?? true,
29+
endpoint: normalizeEndpoint(input),
30+
isCustomEndpoint: true,
31+
});
32+
33+
const normalizeEndpoint = (input: CustomEndpointsInputConfig & PreviouslyResolved): Provider<Endpoint> => {
34+
const { endpoint, urlParser } = input;
35+
if (typeof endpoint === "string") {
36+
const promisified = Promise.resolve(urlParser(endpoint));
37+
return () => promisified;
38+
} else if (typeof endpoint === "object") {
39+
const promisified = Promise.resolve(endpoint);
40+
return () => promisified;
41+
}
42+
return endpoint;
43+
};

packages/config-resolver/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from "./CustomEndpointsConfig";
12
export * from "./EndpointsConfig";
23
export * from "./RegionConfig";

0 commit comments

Comments
 (0)