Skip to content

Commit

Permalink
chore(config-resolver): update RegionHash and PartitionHash
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Nov 2, 2021
1 parent 33f9d6e commit 6d2bf78
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
9 changes: 9 additions & 0 deletions packages/config-resolver/src/regionInfo/EndpointVariant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { EndpointVariantTag } from "./EndpointVariantTag";

/**
* Provides hostname information for specific host label.
*/
export type EndpointVariant = {
hostname: string;
tags: EndpointVariantTag[];
};
5 changes: 5 additions & 0 deletions packages/config-resolver/src/regionInfo/EndpointVariantTag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* The tag which mentions which area variant is providing information for.
* Can be either "fips" or "dualstack".
*/
export type EndpointVariantTag = "fips" | "dualstack";
11 changes: 10 additions & 1 deletion packages/config-resolver/src/regionInfo/PartitionHash.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { EndpointVariant } from "./EndpointVariant";

/**
* The hash of partition with the information specific to that partition.
* The information includes the list of regions belonging to that partition,
* and the hostname to be used for the partition.
*/
export type PartitionHash = {
[key: string]: { regions: string[]; regionRegex: string; hostname?: string; endpoint?: string };
[key: string]: {
regions: string[];
regionRegex: string;
// TODO: Remove hostname after fully switching to variants.
hostname: string;
variants: EndpointVariant[];
endpoint?: string;
};
};
12 changes: 10 additions & 2 deletions packages/config-resolver/src/regionInfo/RegionHash.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { RegionInfo } from "@aws-sdk/types";
import { EndpointVariant } from "./EndpointVariant";

/**
* The hash of region with the information specific to that region.
* The information can include hostname, signingService and signingRegion.
*/
export type RegionHash = { [key: string]: Partial<Omit<RegionInfo, "partition" | "path">> };
export type RegionHash = {
[key: string]: {
// TODO: Remove hostname after fully switching to variants.
hostname: string;
variants: EndpointVariant[];
signingService?: string;
signingRegion?: string;
};
};
7 changes: 4 additions & 3 deletions packages/config-resolver/src/regionInfo/getRegionInfo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ describe(getRegionInfo.name, () => {
...((regionCase === RegionCase.REGION || regionCase === RegionCase.REGION_AND_ENDPOINT) && {
[mockRegion]: {
hostname: mockHostname,
variants: [{ hostname: mockHostname, tags: [] }],
},
}),
...((regionCase === RegionCase.ENDPOINT || regionCase === RegionCase.REGION_AND_ENDPOINT) && {
[mockEndpointRegion]: {
hostname: mockEndpointHostname,
variants: [{ hostname: mockEndpointHostname, tags: [] }],
},
}),
});
Expand All @@ -42,9 +44,8 @@ describe(getRegionInfo.name, () => {
[mockPartition]: {
regions: [mockRegion, `${mockRegion}2`, `${mockRegion}3`],
regionRegex: mockRegionRegex,
...((regionCase === RegionCase.REGION || regionCase === RegionCase.REGION_AND_ENDPOINT) && {
hostname: mockHostname,
}),
hostname: mockHostname,
variants: [{ hostname: mockHostname, tags: [] }],
...((regionCase === RegionCase.ENDPOINT || regionCase === RegionCase.REGION_AND_ENDPOINT) && {
endpoint: mockEndpointRegion,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe(getResolvedPartition.name, () => {
regions: [mockRegion, `${mockRegion}2`, `${mockRegion}3`],
regionRegex: mockRegionRegex,
hostname: mockHostname,
variants: [{ hostname: mockHostname, tags: [] }],
},
};
expect(getResolvedPartition(mockRegion, { partitionHash: mockPartitionHash })).toBe(mockPartition);
Expand All @@ -24,6 +25,7 @@ describe(getResolvedPartition.name, () => {
regions: [`${mockRegion}2`, `${mockRegion}3`],
regionRegex: mockRegionRegex,
hostname: mockHostname,
variants: [{ hostname: mockHostname, tags: [] }],
},
};
expect(getResolvedPartition(mockRegion, { partitionHash: mockPartitionHash })).toBe("aws");
Expand Down

0 comments on commit 6d2bf78

Please sign in to comment.