Skip to content

Commit 88656c0

Browse files
AaronMoat72636csamchungy
authored
Make things work (#58)
* HookStack: Implement version prune in AfterAllowTraffic * This might help * Allow logs to exist * Bundling * Revert "Bundling" This reverts commit 4d27363. * Take 2 * Take 3 * Getting there... * Lazily mitigate self-DOS * Alarm * Lazy fix * Apply suggestions from code review Co-authored-by: Ryan Ling <[email protected]> * Update packages/infra/package.json Co-authored-by: Sam Chung <[email protected]> * Lockfile * Always create alarm * wow * wow2 * getting there * Tests * Roll back alarms * Changesets etc * Roll back more stuff * Back to fn name in user agent --------- Co-authored-by: Ryan Ling <[email protected]> Co-authored-by: Sam Chung <[email protected]>
1 parent 39bbb7d commit 88656c0

16 files changed

+138
-58
lines changed

.changeset/cool-sheep-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@seek/aws-codedeploy-infra': patch
3+
---
4+
5+
HookStack: fix `clientContext` structure mistake which was preventing `isLambdaHook` from ever returning `true`

.changeset/happy-plants-run.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@seek/aws-codedeploy-hooks': patch
3+
'@seek/aws-codedeploy-infra': patch
4+
---
5+
6+
Fix discrepancies with user-agent values vs. expectations

.changeset/little-ducks-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@seek/aws-codedeploy-hooks': minor
3+
---
4+
5+
containsSkipDirective: Add function

packages/hooks/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const smokeTest = (req: Request) => {
2929

3030
Checks for a `user-agent` header that starts with either:
3131

32-
- `aws-codedeploy-hook-`
32+
- `aws-codedeploy-hook-BeforeAllowTraffic/`
3333
- `gantry-codedeploy-hook-BeforeAllowTraffic-`
3434

3535
Compatible with Gantry v2.3.7 and newer.
@@ -63,7 +63,7 @@ const handler = (event: Event, ctx: Context) => {
6363
Checks for:
6464

6565
- An empty event object
66-
- A custom `user-agent` in context that starts with `aws-codedeploy-hook-`
66+
- A custom `user-agent` in context that starts with `aws-codedeploy-hook-BeforeAllowTraffic/`
6767

6868
### `smokeTest.koaMiddleware`
6969

packages/hooks/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
},
1414
"license": "MIT",
1515
"sideEffects": false,
16-
"main": "./lib/index.js",
17-
"module": "./lib/index.js",
18-
"types": "./lib/index.d.ts",
16+
"main": "./src/index.ts",
1917
"files": [
2018
"lib*/**/*.d.ts",
2119
"lib*/**/*.js",
@@ -39,7 +37,10 @@
3937
"node": ">=18.12"
4038
},
4139
"publishConfig": {
42-
"provenance": true
40+
"main": "./lib/index.js",
41+
"module": "./lib/index.js",
42+
"provenance": true,
43+
"types": "./lib/index.d.ts"
4344
},
4445
"skuba": {
4546
"build": "esbuild"

packages/hooks/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export const GANTRY_HOOK_PREFIX = 'gantry-codedeploy-hook-BeforeAllowTraffic-';
22

3-
export const USER_AGENT_PREFIX = 'aws-codedeploy-hook-';
3+
export const USER_AGENT_PREFIX = 'aws-codedeploy-hook-BeforeAllowTraffic/';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { containsSkipDirective } from './containsSkipDirective';
2+
3+
describe('containsSkipDirective', () => {
4+
it.each([
5+
null,
6+
undefined,
7+
'',
8+
'[skip]',
9+
'[skip] scopename',
10+
'[skip ci] scopename',
11+
'scopename [skip ci]',
12+
'[skip ci]',
13+
'[skip ciscopename]',
14+
'[skip ci,scopename]',
15+
])('returns false for %s', (s) =>
16+
expect(containsSkipDirective(s, 'scopename')).toBe(false),
17+
);
18+
19+
it.each([
20+
'[skip scopename]',
21+
'[skip scopename other]',
22+
'[skip other scopename]',
23+
'[skip other1 other2] [skip scopename]',
24+
'[skip scopename][skip other1 other2]',
25+
])('returns true for %s', (s) =>
26+
expect(containsSkipDirective(s, 'scopename')).toBe(true),
27+
);
28+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const skipDirective = /\[skip([^\]]+)\]/gi;
2+
3+
/**
4+
* Check if a message contains a skip directive for a given scope.
5+
* @param message - The message to check.
6+
* @param scope - The scope to check for.
7+
* @returns Whether the message contains a skip directive for the given scope.
8+
*
9+
* @example
10+
* containsSkipDirective('This is a message with a [skip ci] directive.', 'ci');
11+
* // true
12+
*
13+
* containsSkipDirective('This is a message with a [skip ci smoke] directive.', 'ci');
14+
* // true
15+
*
16+
* containsSkipDirective('This is a message with a [skip smoke] directive.', 'ci');
17+
* // false
18+
*/
19+
export const containsSkipDirective = (
20+
message: string | undefined | null,
21+
scope: string,
22+
) =>
23+
Array.from(
24+
message
25+
// limit the message to 1000 characters to avoid regex performance issues
26+
?.slice(0, 1000)
27+
.matchAll(skipDirective) ?? [],
28+
).some((match) =>
29+
match[1]
30+
?.split(' ')
31+
.map((part) => part.toLowerCase())
32+
.includes(scope),
33+
);

packages/hooks/src/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const isHeadersClass = (
3434
*
3535
* Checks for a `user-agent` header that starts with either:
3636
*
37-
* - `aws-codedeploy-hook-`
37+
* - `aws-codedeploy-hook-BeforeAllowTraffic/`
3838
* - `gantry-codedeploy-hook-BeforeAllowTraffic-`
3939
*
4040
* Compatible with Gantry v2.3.7 and newer.

packages/hooks/src/index.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import * as rootModule from '.';
33
describe('rootModule', () => {
44
it('exports runtime helpers', () =>
55
expect(rootModule).toMatchInlineSnapshot(`
6-
{
7-
"isHttpHook": [Function],
8-
"isLambdaHook": [Function],
9-
"smokeTest": {
10-
"koaMiddleware": [Function],
11-
},
12-
}
13-
`));
6+
{
7+
"containsSkipDirective": [Function],
8+
"isHttpHook": [Function],
9+
"isLambdaHook": [Function],
10+
"smokeTest": {
11+
"koaMiddleware": [Function],
12+
},
13+
}
14+
`));
1415
});

0 commit comments

Comments
 (0)