Skip to content

chore(codegen,config-resolver): refactor how endpoint is resolved for non-AWS client #2287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ public List<RuntimeClientPlugin> getClientPlugins() {
.withConventions(TypeScriptDependency.CONFIG_RESOLVER.dependency, "Region", HAS_CONFIG)
.servicePredicate((m, s) -> isAwsService(s))
.build(),
// Only one of Endpoints or CustomEndpoints should be used
RuntimeClientPlugin.builder()
.withConventions(TypeScriptDependency.CONFIG_RESOLVER.dependency, "Endpoints", HAS_CONFIG)
.servicePredicate((m, s) -> isAwsService(s))
.build(),
RuntimeClientPlugin.builder()
.withConventions(TypeScriptDependency.CONFIG_RESOLVER.dependency, "CustomEndpoints", HAS_CONFIG)
.servicePredicate((m, s) -> !isAwsService(s))
.build(),
RuntimeClientPlugin.builder()
.withConventions(TypeScriptDependency.MIDDLEWARE_RETRY.dependency, "Retry")
Expand Down
45 changes: 45 additions & 0 deletions packages/config-resolver/src/CustomEndpointsConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// TODO: Create a .spec.ts for this
import { Endpoint, Provider, UrlParser } from "@aws-sdk/types";

export interface CustomEndpointsInputConfig {
/**
* The fully qualified endpoint of the webservice.
*/
endpoint: string | Endpoint | Provider<Endpoint>;

/**
* Whether TLS is enabled for requests.
*/
tls?: boolean;
}

interface PreviouslyResolved {
urlParser: UrlParser;
}

export interface CustomEndpointsResolvedConfig extends Required<CustomEndpointsInputConfig> {
endpoint: Provider<Endpoint>;
isCustomEndpoint: true; // TODO: Can this be removed or some other logic depends on this?
}

export const resolveCustomEndpointsConfig = <T>(
input: T & CustomEndpointsInputConfig & PreviouslyResolved
): T & CustomEndpointsResolvedConfig => ({
...input,
tls: input.tls ?? true,
endpoint: normalizeEndpoint(input),
isCustomEndpoint: true,
});

// TODO: can this be shared with EndpointsConfig.ts
const normalizeEndpoint = (input: CustomEndpointsInputConfig & PreviouslyResolved): Provider<Endpoint> => {
const { endpoint, urlParser } = input;
if (typeof endpoint === "string") {
const promisified = Promise.resolve(urlParser(endpoint));
return () => promisified;
} else if (typeof endpoint === "object") {
const promisified = Promise.resolve(endpoint);
return () => promisified;
}
return endpoint;
};
8 changes: 2 additions & 6 deletions packages/config-resolver/src/EndpointsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export interface EndpointsInputConfig {
}

interface PreviouslyResolved {
regionInfoProvider?: RegionInfoProvider;
regionInfoProvider: RegionInfoProvider;
urlParser: UrlParser;
region?: Provider<string>;
region: Provider<string>;
}

export interface EndpointsResolvedConfig extends Required<EndpointsInputConfig> {
Expand Down Expand Up @@ -45,10 +45,6 @@ const normalizeEndpoint = (input: EndpointsInputConfig & PreviouslyResolved): Pr
};

const getEndPointFromRegion = async (input: EndpointsInputConfig & PreviouslyResolved) => {
if (input.region === undefined || input.regionInfoProvider === undefined) {
throw new Error("No endpoint specified and region is not defined");
}

const { tls = true } = input;
const region = await input.region();

Expand Down
1 change: 1 addition & 0 deletions packages/config-resolver/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./CustomEndpointsConfig";
export * from "./EndpointsConfig";
export * from "./RegionConfig";