-
Notifications
You must be signed in to change notification settings - Fork 112
fix: handle clientContextParam collisions with builtin config keys #1788
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
Changes from all commits
947c39f
d28b53f
1edcd1e
7da325b
8fb3ddc
04fe9a0
d234258
880ecdd
05aa8c7
943e965
be513b1
596c0a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@smithy/middleware-endpoint": minor | ||
| --- | ||
|
|
||
| handle clientContextParam collisions with builtin config keys | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { describe, expect, test as it } from "vitest"; | ||
| import { XYZService } from "xyz"; | ||
|
|
||
| describe("client context parameters precedence integration test", () => { | ||
| it("should handle conflicting vs non-conflicting parameter precedence correctly", async () => { | ||
| // For non-conflicting params | ||
siddsriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const clientWithNonConflicting = new XYZService({ | ||
| endpoint: "https://localhost", | ||
| apiKey: async () => ({ apiKey: "test-key" }), | ||
| customParam: "user-custom-value", | ||
| clientContextParams: { | ||
| apiKey: "test-key", | ||
| customParam: "nested-custom-value", | ||
| }, | ||
| }); | ||
|
|
||
| // Verify that endpoint resolution uses the nested value over root value | ||
| const resolvedConfig = clientWithNonConflicting.config; | ||
| const effectiveCustomParam = resolvedConfig.clientContextParams?.customParam ?? resolvedConfig.customParam; | ||
| expect(effectiveCustomParam).toBe("nested-custom-value"); | ||
|
|
||
| // For conflicting parameters | ||
| const clientWithConflicting = new XYZService({ | ||
| endpoint: "https://localhost", | ||
| apiKey: async () => ({ apiKey: "auth-key" }), | ||
| clientContextParams: { | ||
| apiKey: "endpoint-key", | ||
| }, | ||
| }); | ||
|
|
||
| // Verify that both auth and endpoint contexts can coexist | ||
| const resolvedConfigConflicting = clientWithConflicting.config; | ||
|
|
||
| // Verify endpoint context has the nested value | ||
| expect(resolvedConfigConflicting.clientContextParams?.apiKey).toBe("endpoint-key"); | ||
|
|
||
| // Verify auth context has the auth provider | ||
| const authIdentity = await resolvedConfigConflicting.apiKey?.(); | ||
| expect(authIdentity?.apiKey).toBe("auth-key"); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,16 +9,29 @@ import type { Endpoint, EndpointV2 } from "@smithy/types"; | |
| * it will most likely not contain the config | ||
| * value, but we use it as a fallback. | ||
| * @param config - container of the config values. | ||
| * @param isClientContextParam - whether this is a client context parameter. | ||
| * | ||
| * @returns async function that will resolve with the value. | ||
| */ | ||
| export const createConfigValueProvider = <Config extends Record<string, unknown>>( | ||
| configKey: string, | ||
| canonicalEndpointParamKey: string, | ||
| config: Config | ||
| config: Config, | ||
| isClientContextParam = false | ||
| ) => { | ||
| const configProvider = async () => { | ||
| const configValue: unknown = config[configKey] ?? config[canonicalEndpointParamKey]; | ||
| let configValue: unknown; | ||
|
|
||
| if (isClientContextParam) { | ||
| // For client context parameters, check clientContextParams first | ||
| const clientContextParams = config.clientContextParams as Record<string, unknown> | undefined; | ||
| const nestedValue: unknown = clientContextParams?.[configKey]; | ||
| configValue = nestedValue ?? config[configKey] ?? config[canonicalEndpointParamKey]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for example, would this case correctly prefer the nested value? const client = new XYZService({
apiKey: async () => ({ apiKey: "auth-secret" }),
clientContextParams: {
apiKey: "endpoint-header-key"
}
});if the nested value looks for the canonical name, would it find
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the current logic using canonicalEndpointParamKey. It would look for I think this should be |
||
| } else { | ||
| // For built-in parameters and other config properties | ||
| configValue = config[configKey] ?? config[canonicalEndpointParamKey]; | ||
| } | ||
|
|
||
| if (typeof configValue === "function") { | ||
| return configValue(); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.