-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clients): remove retry headers for several services (#1789)
* fix(clients-*): remove retry headers for serveral services ConnectParticipant, IoT Data Plane, IoT, Pinpoint SMS Voice, QLDB doesn't support retry headers per their CORS config. So remove the support for these service to unblock the browser usage * feat(middleware-retry): move omitRetryHeadersMiddleware before signing
- Loading branch information
1 parent
d4cb977
commit fc98d2d
Showing
12 changed files
with
200 additions
and
8 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
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
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
53 changes: 53 additions & 0 deletions
53
...ain/java/software/amazon/smithy/aws/typescript/codegen/AddOmitRetryHeadersDependency.java
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,53 @@ | ||
/* | ||
* Copyright 2019 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 static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_MIDDLEWARE; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import software.amazon.smithy.aws.traits.ServiceTrait; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptDependency; | ||
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin; | ||
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; | ||
import software.amazon.smithy.utils.ListUtils; | ||
import software.amazon.smithy.utils.SetUtils; | ||
|
||
|
||
public class AddOmitRetryHeadersDependency implements TypeScriptIntegration { | ||
private static final Set<String> SERVICE_IDS = SetUtils.of( | ||
"ConnectParticipant", | ||
"IoT Data Plane", | ||
"IoT", | ||
"Pinpoint SMS Voice", | ||
"QLDB" | ||
); | ||
|
||
@Override | ||
public List<RuntimeClientPlugin> getClientPlugins() { | ||
return ListUtils.of( | ||
RuntimeClientPlugin.builder() | ||
.withConventions(TypeScriptDependency.MIDDLEWARE_RETRY.dependency, "OmitRetryHeaders", | ||
HAS_MIDDLEWARE) | ||
.servicePredicate((m, s) -> { | ||
String sdkId = s.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse(""); | ||
return SERVICE_IDS.contains(sdkId); | ||
}) | ||
.build() | ||
); | ||
} | ||
} |
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
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
49 changes: 49 additions & 0 deletions
49
packages/middleware-retry/src/omitRetryHeadersMiddleware.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,49 @@ | ||
import { HttpRequest } from "@aws-sdk/protocol-http"; | ||
import { FinalizeHandlerArguments, MiddlewareStack } from "@aws-sdk/types"; | ||
|
||
import { INVOCATION_ID_HEADER, REQUEST_HEADER } from "./constants"; | ||
import { | ||
getOmitRetryHeadersPlugin, | ||
omitRetryHeadersMiddleware, | ||
omitRetryHeadersMiddlewareOptions, | ||
} from "./omitRetryHeadersMiddleware"; | ||
|
||
describe("getOmitRetryHeadersPlugin", () => { | ||
const mockClientStack = { | ||
add: jest.fn(), | ||
addRelativeTo: jest.fn(), | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it(`adds omitRetryHeadersMiddleware`, () => { | ||
getOmitRetryHeadersPlugin({}).applyToStack((mockClientStack as unknown) as MiddlewareStack<any, any>); | ||
expect(mockClientStack.addRelativeTo).toHaveBeenCalledTimes(1); | ||
expect(mockClientStack.addRelativeTo.mock.calls[0][1]).toEqual(omitRetryHeadersMiddlewareOptions); | ||
}); | ||
}); | ||
|
||
describe("omitRetryHeadersMiddleware", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("remove retry headers", async () => { | ||
const next = jest.fn(); | ||
const args = { | ||
request: new HttpRequest({ | ||
headers: { | ||
[INVOCATION_ID_HEADER]: "12345", | ||
[REQUEST_HEADER]: "maxAttempts=30", | ||
}, | ||
}), | ||
}; | ||
|
||
await omitRetryHeadersMiddleware()(next)(args as FinalizeHandlerArguments<any>); | ||
expect(next).toHaveBeenCalledTimes(1); | ||
expect(next.mock.calls[0][0].request.headers[INVOCATION_ID_HEADER]).toBeUndefined(); | ||
expect(next.mock.calls[0][0].request.headers[REQUEST_HEADER]).toBeUndefined(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/middleware-retry/src/omitRetryHeadersMiddleware.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,37 @@ | ||
import { HttpRequest } from "@aws-sdk/protocol-http"; | ||
import { | ||
FinalizeHandler, | ||
FinalizeHandlerArguments, | ||
FinalizeHandlerOutput, | ||
MetadataBearer, | ||
Pluggable, | ||
RelativeMiddlewareOptions, | ||
} from "@aws-sdk/types"; | ||
|
||
import { INVOCATION_ID_HEADER, REQUEST_HEADER } from "./constants"; | ||
|
||
export const omitRetryHeadersMiddleware = () => <Output extends MetadataBearer = MetadataBearer>( | ||
next: FinalizeHandler<any, Output> | ||
): FinalizeHandler<any, Output> => async ( | ||
args: FinalizeHandlerArguments<any> | ||
): Promise<FinalizeHandlerOutput<Output>> => { | ||
const { request } = args; | ||
if (HttpRequest.isInstance(request)) { | ||
delete request.headers[INVOCATION_ID_HEADER]; | ||
delete request.headers[REQUEST_HEADER]; | ||
} | ||
return next(args); | ||
}; | ||
|
||
export const omitRetryHeadersMiddlewareOptions: RelativeMiddlewareOptions = { | ||
name: "omitRetryHeadersMiddleware", | ||
tags: ["RETRY", "HEADERS", "OMIT_RETRY_HEADERS"], | ||
relation: "before", | ||
toMiddleware: "awsAuthMiddleware", | ||
}; | ||
|
||
export const getOmitRetryHeadersPlugin = (options: unknown): Pluggable<any, any> => ({ | ||
applyToStack: (clientStack) => { | ||
clientStack.addRelativeTo(omitRetryHeadersMiddleware(), omitRetryHeadersMiddlewareOptions); | ||
}, | ||
}); |