Skip to content

Commit

Permalink
fix(endpoint): endpoints 2.0 all-service TS compilation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 14, 2022
1 parent 5b03ad1 commit 147b366
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.smithy.aws.typescript.codegen;

import software.amazon.smithy.typescript.codegen.endpointsV2.EndpointsParamNameMap;
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
import software.amazon.smithy.utils.MapUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

@SmithyInternalApi
public class AddEndpointsV2ParameterNameMap implements TypeScriptIntegration {
public AddEndpointsV2ParameterNameMap() {
EndpointsParamNameMap.setNameMapping(MapUtils.of(
"Region", "region",
"UseFIPS", "useFipsEndpoint",
"UseDualStack", "useDualstackEndpoint",
"ForcePathStyle", "forcePathStyle",
"Accelerate", "useAccelerateEndpoint",
"DisableMRAP", "disableMultiregionAccessPoints",
"UseArnRegion", "useArnRegion"
));
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
software.amazon.smithy.aws.typescript.codegen.AddEndpointsV2ParameterNameMap
software.amazon.smithy.aws.typescript.codegen.AddClientRuntimeConfig
software.amazon.smithy.aws.typescript.codegen.AddAwsRuntimeConfig
software.amazon.smithy.aws.typescript.codegen.AddBuiltinPlugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface EndpointsInputConfig {
}

interface PreviouslyResolved {
regionInfoProvider: RegionInfoProvider;
regionInfoProvider?: RegionInfoProvider;
urlParser: UrlParser;
region: Provider<string>;
useFipsEndpoint: Provider<boolean>;
Expand All @@ -38,7 +38,7 @@ export interface EndpointsResolvedConfig extends Required<EndpointsInputConfig>
* Whether the endpoint is specified by caller.
* @internal
*/
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;

/**
* Resolved value for input {@link EndpointsInputConfig.useDualstackEndpoint}
Expand All @@ -56,7 +56,7 @@ export const resolveEndpointsConfig = <T>(
tls: input.tls ?? true,
endpoint: endpoint
? normalizeProvider(typeof endpoint === "string" ? urlParser(endpoint) : endpoint)
: () => getEndpointFromRegion({ ...input, useDualstackEndpoint, useFipsEndpoint }),
: () => getEndpointFromRegion({ ...input, regionInfoProvider: input.regionInfoProvider!, useDualstackEndpoint, useFipsEndpoint }),
isCustomEndpoint: !!endpoint,
useDualstackEndpoint,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface AccessPointArn extends ARN {
}

export interface BucketHostnameParams {
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
baseHostname: string;
bucketName: string;
clientRegion: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/middleware-bucket-endpoint/src/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface BucketEndpointInputConfig {
}

interface PreviouslyResolved {
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
region: Provider<string>;
regionInfoProvider: RegionInfoProvider;
useFipsEndpoint: Provider<boolean>;
Expand All @@ -46,7 +46,7 @@ export interface BucketEndpointResolvedConfig {
* Whether the endpoint is specified by caller.
* @internal
*/
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
/**
* Resolved value for input config {@link BucketEndpointInputConfig.bucketEndpoint}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Credentials, MemoizedProvider, Provider } from "@aws-sdk/types";
export interface EndpointDiscoveryInputConfig {}

export interface PreviouslyResolved {
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
credentials: MemoizedProvider<Credentials>;
endpointDiscoveryEnabledProvider: Provider<boolean | undefined>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { injectEndpointIdMiddleware } from "./inject-endpoint-id";

describe("injectEndpointIdMiddleware", () => {
type InjectEndpointIdMiddlewareConfig = {
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
customEndpoint?: string;
useFipsEndpoint: Provider<boolean>;
useDualstackEndpoint: Provider<boolean>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@aws-sdk/types";

type PreviouslyResolved = {
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
useFipsEndpoint: Provider<boolean>;
useDualstackEndpoint: Provider<boolean>;
};
Expand Down
8 changes: 4 additions & 4 deletions packages/middleware-sdk-s3-control/src/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export interface S3ControlInputConfig {
}

interface PreviouslyResolved {
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
region: Provider<string>;
regionInfoProvider: RegionInfoProvider;
regionInfoProvider?: RegionInfoProvider;
useFipsEndpoint: Provider<boolean>;
useDualstackEndpoint: Provider<boolean>;
}
Expand All @@ -21,7 +21,7 @@ export interface S3ControlResolvedConfig {
* Whether the endpoint is specified by caller.
* @internal
*/
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
/**
* Enables FIPS compatible endpoints.
*/
Expand All @@ -42,7 +42,7 @@ export interface S3ControlResolvedConfig {
* Fetch related hostname, signing name or signing region with given region.
* @internal
*/
regionInfoProvider: RegionInfoProvider;
regionInfoProvider?: RegionInfoProvider;
}

export function resolveS3ControlConfig<T>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@aws-sdk/middleware-bucket-endpoint";
import { InitializeHandlerOptions, InitializeMiddleware } from "@aws-sdk/types";
import { ARN, parse as parseArn, validate as validateArn } from "@aws-sdk/util-arn-parser";
import { partition } from "@aws-sdk/util-endpoints";

import { S3ControlResolvedConfig } from "../configurations";
import { CONTEXT_ARN_REGION, CONTEXT_OUTPOST_ID, CONTEXT_SIGNING_REGION, CONTEXT_SIGNING_SERVICE } from "../constants";
Expand Down Expand Up @@ -38,10 +39,19 @@ export const parseOutpostArnablesMiddleaware =
const useFipsEndpoint = await options.useFipsEndpoint();
const useDualstackEndpoint = await options.useDualstackEndpoint();
const baseRegion = clientRegion;
const { partition: clientPartition, signingRegion = baseRegion } = (await options.regionInfoProvider(baseRegion, {
useFipsEndpoint,
useDualstackEndpoint,
}))!;

let clientPartition: string;
let signingRegion: string;
if (options.regionInfoProvider) {
({ partition: clientPartition, signingRegion = baseRegion } = (await options.regionInfoProvider(baseRegion, {
useFipsEndpoint,
useDualstackEndpoint,
}))!);
} else {
signingRegion = context.endpointV2?.properties?.authSchemes?.[0]?.signingScope || baseRegion;
clientPartition = partition(signingRegion).name;
}

const validatorOptions: ValidateOutpostsArnOptions = {
useFipsEndpoint,
useDualstackEndpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ACCOUNT_ID_HEADER = "x-amz-account-id";
const OUTPOST_ID_HEADER = "x-amz-outpost-id";

export interface UpdateArnablesRequestMiddlewareConfig {
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
useFipsEndpoint: Provider<boolean>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type InputType = {
};

export interface RedirectFromPostIdMiddlewareConfig {
isCustomEndpoint: boolean;
isCustomEndpoint?: boolean;
useFipsEndpoint: Provider<boolean>;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-sdk-sts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface StsAuthInputConfig extends AwsAuthInputConfig {}
interface PreviouslyResolved {
credentialDefaultProvider: (input: any) => Provider<Credentials>;
region: string | Provider<string>;
regionInfoProvider: RegionInfoProvider;
regionInfoProvider?: RegionInfoProvider;
signingName?: string;
serviceId: string;
sha256: HashConstructor;
Expand Down
1 change: 1 addition & 0 deletions packages/util-endpoints/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./lib/aws/partition";
export * from "./resolveEndpoint";
export * from "./types";

0 comments on commit 147b366

Please sign in to comment.