Skip to content
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

feat: refactor middleware stack #1398

Merged
merged 4 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ describe("fromCognitoIdentity", () => {
expiration,
});

expect(send.mock.calls[0][0]).toEqual(
new GetCredentialsForIdentityCommand({
IdentityId: identityId,
CustomRoleArn: "myArn",
})
);
const sendParam = send.mock.calls[0][0];
expect(sendParam).toEqual(expect.any(GetCredentialsForIdentityCommand));
expect(sendParam.input).toEqual({
IdentityId: identityId,
CustomRoleArn: "myArn",
});
});

it("should resolve logins to string tokens and pass them to the service", async () => {
Expand All @@ -54,16 +54,16 @@ describe("fromCognitoIdentity", () => {
},
})();

expect(send.mock.calls[0][0]).toEqual(
new GetCredentialsForIdentityCommand({
IdentityId: identityId,
CustomRoleArn: "myArn",
Logins: {
myDomain: "token",
"www.amazon.com": "expiring nonce",
},
})
);
const sendParam = send.mock.calls[0][0];
expect(sendParam).toEqual(expect.any(GetCredentialsForIdentityCommand));
expect(sendParam.input).toMatchObject({
IdentityId: identityId,
CustomRoleArn: "myArn",
Logins: {
myDomain: "token",
"www.amazon.com": "expiring nonce",
},
});
});

it("should convert a GetCredentialsForIdentity response without credentials to a provider error", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ describe("fromCognitoIdentityPool", () => {
});

expect(send.mock.calls.length).toBe(1);
expect(send.mock.calls[0][0]).toEqual(new GetIdCommand({ IdentityPoolId: identityPoolId }));
expect(send.mock.calls[0][0]).toEqual(expect.any(GetIdCommand));
expect(send.mock.calls[0][0].input).toEqual({
IdentityPoolId: identityPoolId,
});

expect((fromCognitoIdentity as any).mock.calls.length).toBe(1);
expect((fromCognitoIdentity as any).mock.calls[0][0]).toEqual({
Expand All @@ -76,15 +79,14 @@ describe("fromCognitoIdentityPool", () => {
},
})();

expect(send.mock.calls[0][0]).toEqual(
new GetIdCommand({
IdentityPoolId: identityPoolId,
Logins: {
myDomain: "token",
"www.amazon.com": "expiring nonce",
},
})
);
expect(send.mock.calls[0][0]).toEqual(expect.any(GetIdCommand));
expect(send.mock.calls[0][0].input).toEqual({
IdentityPoolId: identityPoolId,
Logins: {
myDomain: "token",
"www.amazon.com": "expiring nonce",
},
});
});

it("should not invoke GetId a second time once an identityID has been fetched", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/eventstream-handler-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@aws-sdk/util-utf8-node": "1.0.0-gamma.3",
"@types/jest": "^26.0.4",
"jest": "^26.1.0",
"typescript": "~3.4.0"
"typescript": "~3.9.3"
},
"engines": {
"node": ">= 10.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareStack } from "@aws-sdk/middleware-stack";
import { constructStack } from "@aws-sdk/middleware-stack";
import { HttpRequest } from "@aws-sdk/protocol-http";

import { bucketEndpointMiddleware, bucketEndpointMiddlewareOptions } from "./bucketEndpointMiddleware";
Expand Down Expand Up @@ -130,7 +130,7 @@ describe("bucketEndpointMiddleware", () => {
});

it("should be inserted before 'hostheaderMiddleware' if exists", async () => {
const stack = new MiddlewareStack();
const stack = constructStack();
const mockHostheaderMiddleware = (next: any) => (args: any) => {
args.request.arr.push("two");
return next(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { HttpRequest } from "@aws-sdk/protocol-http";
import {
BuildHandler,
BuildHandlerArguments,
BuildHandlerOptions,
BuildHandlerOutput,
BuildMiddleware,
MetadataBearer,
Pluggable,
RelativeLocation,
RelativeMiddlewareOptions,
} from "@aws-sdk/types";

import { bucketHostname } from "./bucketHostname";
Expand Down Expand Up @@ -49,8 +48,7 @@ export function bucketEndpointMiddleware(options: BucketEndpointResolvedConfig):
};
}

export const bucketEndpointMiddlewareOptions: BuildHandlerOptions & RelativeLocation<any, any> = {
step: "build",
export const bucketEndpointMiddlewareOptions: RelativeMiddlewareOptions = {
tags: ["BUCKET_ENDPOINT"],
name: "bucketEndpointMiddleware",
relation: "before",
Expand Down
5 changes: 2 additions & 3 deletions packages/middleware-eventstream/src/handling-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpRequest } from "@aws-sdk/protocol-http";
import { FinalizeRequestHandlerOptions, FinalizeRequestMiddleware, RelativeLocation } from "@aws-sdk/types";
import { FinalizeRequestMiddleware, RelativeMiddlewareOptions } from "@aws-sdk/types";

import { EventStreamResolvedConfig } from "./configuration";

Expand All @@ -11,8 +11,7 @@ export const eventStreamHandlingMiddleware = (
return options.eventStreamPayloadHandler.handle(next, args, context);
};

export const eventStreamHandlingMiddlewareOptions: FinalizeRequestHandlerOptions & RelativeLocation<any, any> = {
step: "finalizeRequest",
export const eventStreamHandlingMiddlewareOptions: RelativeMiddlewareOptions = {
tags: ["EVENT_STREAM", "SIGNATURE", "HANDLE"],
name: "eventStreamHandlingMiddleware",
relation: "after",
Expand Down
6 changes: 2 additions & 4 deletions packages/middleware-sdk-s3-control/src/prepend-account-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { HttpRequest } from "@aws-sdk/protocol-http";
import {
BuildHandler,
BuildHandlerArguments,
BuildHandlerOptions,
BuildHandlerOutput,
BuildMiddleware,
MetadataBearer,
Pluggable,
RelativeLocation,
RelativeMiddlewareOptions,
} from "@aws-sdk/types";

export function prependAccountIdMiddleware(): BuildMiddleware<any, any> {
Expand Down Expand Up @@ -40,8 +39,7 @@ export function prependAccountIdMiddleware(): BuildMiddleware<any, any> {
};
}

export const prependAccountIdMiddlewareOptions: BuildHandlerOptions & RelativeLocation<any, any> = {
step: "build",
export const prependAccountIdMiddlewareOptions: RelativeMiddlewareOptions = {
tags: ["PREPEND_ACCOUNT_ID_MIDDLEWARE"],
name: "prependAccountIdMiddleware",
relation: "before",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { HttpRequest } from "@aws-sdk/protocol-http";
import {
BuildHandler,
BuildHandlerArguments,
BuildHandlerOptions,
BuildMiddleware,
RelativeLocation,
RelativeMiddlewareOptions,
RequestHandler,
} from "@aws-sdk/types";

Expand Down Expand Up @@ -54,8 +53,7 @@ export const websocketURLMiddleware = (options: {
return next(args);
};

export const websocketURLMiddlewareOptions: BuildHandlerOptions & RelativeLocation<any, any> = {
step: "build",
export const websocketURLMiddlewareOptions: RelativeMiddlewareOptions = {
name: "websocketURLMiddleware",
tags: ["WEBSOCKET", "EVENT_STREAM"],
relation: "after",
Expand Down
6 changes: 2 additions & 4 deletions packages/middleware-signing/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
FinalizeHandler,
FinalizeHandlerArguments,
FinalizeHandlerOutput,
FinalizeRequestHandlerOptions,
FinalizeRequestMiddleware,
Pluggable,
RelativeLocation,
RelativeMiddlewareOptions,
} from "@aws-sdk/types";

import { AwsAuthResolvedConfig } from "./configurations";
Expand Down Expand Up @@ -43,9 +42,8 @@ export function awsAuthMiddleware<Input extends object, Output extends object>(
};
}

export const awsAuthMiddlewareOptions: FinalizeRequestHandlerOptions & RelativeLocation<any, any> = {
export const awsAuthMiddlewareOptions: RelativeMiddlewareOptions = {
name: "awsAuthMiddleware",
step: "finalizeRequest",
tags: ["SIGNATURE", "AWSAUTH"],
relation: "after",
toMiddleware: "retryMiddleware",
Expand Down
Loading