-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config-resolver): resolve hostname from variants (#2980)
* feat(config-resolver): resolve hostname from variants * test(functional): fips+dualstack endpoints
- Loading branch information
Showing
15 changed files
with
12,206 additions
and
478 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/config-resolver/src/regionInfo/getHostnameFromVariants.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { EndpointVariant } from "./EndpointVariant"; | ||
import { getHostnameFromVariants, GetHostnameFromVariantsOptions } from "./getHostnameFromVariants"; | ||
|
||
describe(getHostnameFromVariants.name, () => { | ||
const getMockHostname = (options: GetHostnameFromVariantsOptions) => JSON.stringify(options); | ||
const getMockTags = ({ useFipsEndpoint, useDualstackEndpoint }: GetHostnameFromVariantsOptions) => [ | ||
...(useFipsEndpoint ? ["fips"] : []), | ||
...(useDualstackEndpoint ? ["dualstack"] : []), | ||
]; | ||
const getMockVariants = () => | ||
[ | ||
{ useFipsEndpoint: false, useDualstackEndpoint: false }, | ||
{ useFipsEndpoint: false, useDualstackEndpoint: true }, | ||
{ useFipsEndpoint: true, useDualstackEndpoint: false }, | ||
{ useFipsEndpoint: true, useDualstackEndpoint: true }, | ||
].map((options) => ({ | ||
hostname: getMockHostname(options), | ||
tags: getMockTags(options), | ||
})); | ||
|
||
const testCases = [ | ||
[false, false], | ||
[false, true], | ||
[true, false], | ||
[true, true], | ||
]; | ||
|
||
describe("returns hostname if present in variants", () => { | ||
it.each(testCases)("useFipsEndpoint: %s, useDualstackEndpoint: %s", (useFipsEndpoint, useDualstackEndpoint) => { | ||
const options = { useFipsEndpoint, useDualstackEndpoint }; | ||
const variants = getMockVariants() as EndpointVariant[]; | ||
expect(getHostnameFromVariants(variants, options)).toEqual(getMockHostname(options)); | ||
}); | ||
}); | ||
|
||
describe("returns undefined if not present in variants", () => { | ||
it.each(testCases)("useFipsEndpoint: %s, useDualstackEndpoint: %s", (useFipsEndpoint, useDualstackEndpoint) => { | ||
const options = { useFipsEndpoint, useDualstackEndpoint }; | ||
const variants = getMockVariants() as EndpointVariant[]; | ||
expect( | ||
getHostnameFromVariants( | ||
variants.filter(({ tags }) => JSON.stringify(tags) !== JSON.stringify(getMockTags(options))), | ||
options | ||
) | ||
).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe("returns undefined if variants in undefined", () => { | ||
it.each(testCases)("useFipsEndpoint: %s, useDualstackEndpoint: %s", (useFipsEndpoint, useDualstackEndpoint) => { | ||
const options = { useFipsEndpoint, useDualstackEndpoint }; | ||
expect(getHostnameFromVariants(undefined, options)).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
packages/config-resolver/src/regionInfo/getHostnameFromVariants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { EndpointVariant } from "./EndpointVariant"; | ||
|
||
export interface GetHostnameFromVariantsOptions { | ||
useFipsEndpoint: boolean; | ||
useDualstackEndpoint: boolean; | ||
} | ||
|
||
export const getHostnameFromVariants = ( | ||
variants: EndpointVariant[] = [], | ||
{ useFipsEndpoint, useDualstackEndpoint }: GetHostnameFromVariantsOptions | ||
) => | ||
variants.find( | ||
({ tags }) => useFipsEndpoint === tags.includes("fips") && useDualstackEndpoint === tags.includes("dualstack") | ||
)?.hostname; |
18 changes: 0 additions & 18 deletions
18
packages/config-resolver/src/regionInfo/getHostnameTemplate.spec.ts
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
packages/config-resolver/src/regionInfo/getHostnameTemplate.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 5 additions & 15 deletions
20
packages/config-resolver/src/regionInfo/getResolvedHostname.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,30 @@ | ||
import { getHostnameTemplate } from "./getHostnameTemplate"; | ||
import { getResolvedHostname } from "./getResolvedHostname"; | ||
|
||
jest.mock("./getHostnameTemplate"); | ||
|
||
describe(getResolvedHostname.name, () => { | ||
const mockSigningService = "mockSigningService"; | ||
const mockRegion = "mockRegion"; | ||
const mockHostname = "{region}.mockHostname.com"; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("returns hostname if available in regionHash", () => { | ||
it("returns hostname if available in regionHostname", () => { | ||
expect( | ||
getResolvedHostname(mockRegion, { | ||
signingService: mockSigningService, | ||
regionHostname: mockHostname, | ||
}) | ||
).toBe(mockHostname); | ||
expect(getHostnameTemplate).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("returns hostname from hostname template when not available in regionHash", () => { | ||
(getHostnameTemplate as jest.Mock).mockReturnValue(mockHostname); | ||
|
||
it("returns hostname from partitionHostname when not available in partitionHostname", () => { | ||
expect( | ||
getResolvedHostname(mockRegion, { | ||
signingService: mockSigningService, | ||
partitionHostname: mockHostname, | ||
}) | ||
).toBe(mockHostname.replace("{region}", mockRegion)); | ||
}); | ||
|
||
expect(getHostnameTemplate).toHaveBeenCalledTimes(1); | ||
expect(getHostnameTemplate).toHaveBeenCalledWith(mockSigningService, { | ||
partitionHostname: mockHostname, | ||
}); | ||
it("returns undefined not available in either regionHostname or partitionHostname", () => { | ||
expect(getResolvedHostname(mockRegion, {})).toBeUndefined(); | ||
}); | ||
}); |
12 changes: 7 additions & 5 deletions
12
packages/config-resolver/src/regionInfo/getResolvedHostname.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { getHostnameTemplate } from "./getHostnameTemplate"; | ||
|
||
export interface GetResolvedHostnameOptions { | ||
signingService: string; | ||
regionHostname?: string; | ||
partitionHostname?: string; | ||
} | ||
|
||
export const getResolvedHostname = ( | ||
resolvedRegion: string, | ||
{ signingService, regionHostname, partitionHostname }: GetResolvedHostnameOptions | ||
) => regionHostname ?? getHostnameTemplate(signingService, { partitionHostname }).replace("{region}", resolvedRegion); | ||
{ regionHostname, partitionHostname }: GetResolvedHostnameOptions | ||
): string | undefined => | ||
regionHostname | ||
? regionHostname | ||
: partitionHostname | ||
? partitionHostname.replace("{region}", resolvedRegion) | ||
: undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.