-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(middleware-flexible-checksums): add config resolver (#6470)
- Loading branch information
Showing
7 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
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
3 changes: 1 addition & 2 deletions
3
...ges/middleware-flexible-checksums/src/NODE_REQUEST_CHECKSUM_CALCULATION_CONFIG_OPTIONS.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
3 changes: 1 addition & 2 deletions
3
...ges/middleware-flexible-checksums/src/NODE_RESPONSE_CHECKSUM_VALIDATION_CONFIG_OPTIONS.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
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
35 changes: 35 additions & 0 deletions
35
packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.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,35 @@ | ||
import { normalizeProvider } from "@smithy/util-middleware"; | ||
|
||
import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION } from "./constants"; | ||
import { resolveFlexibleChecksumsConfig } from "./resolveFlexibleChecksumsConfig"; | ||
|
||
jest.mock("@smithy/util-middleware"); | ||
|
||
describe(resolveFlexibleChecksumsConfig.name, () => { | ||
beforeEach(() => { | ||
(normalizeProvider as jest.Mock).mockImplementation((input) => input); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("returns default client checksums configuration, if not provided", () => { | ||
const resolvedConfig = resolveFlexibleChecksumsConfig({}); | ||
expect(resolvedConfig).toEqual({ | ||
requestChecksumCalculation: DEFAULT_REQUEST_CHECKSUM_CALCULATION, | ||
responseChecksumValidation: DEFAULT_RESPONSE_CHECKSUM_VALIDATION, | ||
}); | ||
expect(normalizeProvider).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it("normalizes client checksums configuration", () => { | ||
const mockInput = { | ||
requestChecksumCalculation: "WHEN_REQUIRED", | ||
responseChecksumValidation: "WHEN_REQUIRED", | ||
}; | ||
const resolvedConfig = resolveFlexibleChecksumsConfig(mockInput); | ||
expect(resolvedConfig).toEqual(mockInput); | ||
expect(normalizeProvider).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.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,33 @@ | ||
import { Provider } from "@smithy/types"; | ||
import { normalizeProvider } from "@smithy/util-middleware"; | ||
|
||
import { DEFAULT_REQUEST_CHECKSUM_CALCULATION, DEFAULT_RESPONSE_CHECKSUM_VALIDATION } from "./constants"; | ||
|
||
export interface FlexibleChecksumsInputConfig { | ||
/** | ||
* Determines when a checksum will be calculated for request payloads. | ||
*/ | ||
requestChecksumCalculation?: string | Provider<string>; | ||
|
||
/** | ||
* Determines when checksum validation will be performed on response payloads. | ||
*/ | ||
responseChecksumValidation?: string | Provider<string>; | ||
} | ||
|
||
export interface FlexibleChecksumsResolvedConfig { | ||
requestChecksumCalculation: Provider<string>; | ||
responseChecksumValidation: Provider<string>; | ||
} | ||
|
||
export const resolveFlexibleChecksumsConfig = <T>( | ||
input: T & FlexibleChecksumsInputConfig | ||
): T & FlexibleChecksumsResolvedConfig => ({ | ||
...input, | ||
requestChecksumCalculation: normalizeProvider( | ||
input.requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION | ||
), | ||
responseChecksumValidation: normalizeProvider( | ||
input.responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION | ||
), | ||
}); |