Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit eba2a33

Browse files
committed
Adding test-read-write-hook Hook
1 parent f7a7048 commit eba2a33

File tree

13 files changed

+192
-0
lines changed

13 files changed

+192
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ jobs:
231231
repository: scbexperimental/hook-imperative-subsequent-scans
232232
path: ./hooks/imperative-subsequent-scans/
233233
tag_with_ref: true
234+
- uses: docker/build-push-action@v1
235+
name: "Build & Push TestReadWriteHook Hook Image"
236+
with:
237+
username: ${{ secrets.DOCKER_USERNAME }}
238+
password: ${{ secrets.DOCKER_PASSWORD }}
239+
repository: scbexperimental/test-read-write-hook
240+
path: ./hooks/test-read-write-hook/
241+
tag_with_ref: true
234242
scannerImages:
235243
# Note we only build images for scanner that don't provider official public container images
236244
name: "Build / Scanner"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
.vscode/
23+
# Node.js files
24+
node_modules/*
25+
package.json
26+
package-lock.json
27+
src/*
28+
config/*
29+
Dockerfile
30+
.dockerignore
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies: []
2+
digest: sha256:643d5437104296e21d906ecb15b2c96ad278f20cfc4af53b12bb6069bd853726
3+
generated: "2020-05-26T16:56:03.119255+02:00"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v2
2+
name: test-read-write-hook-hook
3+
description: This hook is for integration testing only!
4+
5+
type: application
6+
7+
version: 0.1.0
8+
9+
appVersion: latest
10+
11+
dependencies: []
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM scbexperimental/hook-sdk-nodejs:latest
2+
WORKDIR /home/app/hook-wrapper/hook/
3+
COPY --chown=app:app ./hook.js ./hook.js

hooks/test-read-write-hook/hook.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
async function handle({
2+
getFindings,
3+
updateFindings,
4+
attributeName = process.env["ATTRIBUTE_NAME"],
5+
attributeValue = process.env["ATTRIBUTE_VALUE"],
6+
}) {
7+
const findings = await getFindings();
8+
9+
const newFindings = findings.map((finding) => {
10+
finding.attributes[attributeName] = attributeValue;
11+
return finding;
12+
});
13+
14+
console.log(`Updated attributes on ${findings.length} findings`);
15+
16+
await updateFindings(newFindings);
17+
}
18+
module.exports.handle = handle;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const { handle } = require("./hook");
2+
3+
test("should send a post request to the url when fired", async () => {
4+
const findings = [
5+
{
6+
name: "Open Port",
7+
attributes: {
8+
hostname: "foobar.com",
9+
},
10+
},
11+
];
12+
13+
const getFindings = async () => findings;
14+
15+
const updateFindings = jest.fn();
16+
17+
await handle({
18+
getFindings,
19+
updateFindings,
20+
attributeName: "cluster",
21+
attributeValue: "gke-internal",
22+
});
23+
24+
expect(updateFindings).toBeCalledWith([
25+
{
26+
name: "Open Port",
27+
attributes: {
28+
hostname: "foobar.com",
29+
cluster: "gke-internal",
30+
},
31+
},
32+
]);
33+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
TestReadWrite Hook deployed.
2+
This Hook is for testing only!
3+
This will add a attribute "{{ .Values.attribute.name }}: {{ .Values.attribute.value }}" on every finding in this namespace.

0 commit comments

Comments
 (0)