-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(faas): implemented property forwarder
- Loading branch information
Showing
8 changed files
with
6,323 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.eslintrc | ||
.git | ||
.gitignore | ||
Dockerfile | ||
node_modules | ||
README.md | ||
test_output.json | ||
bom.json |
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,18 @@ | ||
{ | ||
"plugins": ["prettier"], | ||
"extends": ["airbnb-base", "eslint:recommended", "prettier"], | ||
"parser": "@babel/eslint-parser", | ||
"parserOptions": { | ||
"ecmaVersion": 2022, | ||
"requireConfigFile": false, | ||
"babelOptions": { | ||
"plugins": [ | ||
"@babel/plugin-syntax-import-assertions" | ||
] | ||
} | ||
}, | ||
"rules": { | ||
"no-console": 1, // Means warning | ||
"prettier/prettier": 2 // Means error | ||
} | ||
} |
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,2 @@ | ||
node_modules | ||
test_output.json |
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,13 @@ | ||
FROM node:19.4.0-alpine | ||
LABEL org.opencontainers.image.source=https://github.com/fraunhoferisst/diva | ||
|
||
RUN mkdir -p /usr/src/app | ||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
RUN npm config set update-notifier false | ||
RUN npm install --production | ||
|
||
COPY . . | ||
|
||
CMD ["npm", "run", "start"] |
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,90 @@ | ||
/* eslint-disable no-console */ | ||
import urljoin from "url-join"; | ||
import axios from "axios"; | ||
import packageJson from "./package.json" assert { type: "json" }; | ||
|
||
const { serviceId } = packageJson; | ||
|
||
const { ENTITY_ID, PATCHED_PROPERTY } = process.env; | ||
|
||
const ENTITY_MANAGEMENT_URL = | ||
process.env.ENTITY_MANAGEMENT_URL || "http://localhost:3000"; | ||
|
||
const forwardGdprRelevancy = async () => { | ||
try { | ||
const { data: entity } = await axios.get( | ||
urljoin( | ||
ENTITY_MANAGEMENT_URL, | ||
`${ENTITY_ID.substr(0, ENTITY_ID.indexOf(":"))}s`, | ||
ENTITY_ID | ||
), | ||
{ | ||
headers: { | ||
"x-diva": JSON.stringify({ | ||
actorId: serviceId, | ||
}), | ||
}, | ||
} | ||
); | ||
|
||
const { data } = await axios.get(urljoin(ENTITY_MANAGEMENT_URL, "edges"), { | ||
params: { | ||
from: ENTITY_ID, | ||
edgeTypes: "isPartOf", | ||
toNodeType: "asset", | ||
}, | ||
headers: { | ||
"x-diva": JSON.stringify({ | ||
actorId: serviceId, | ||
}), | ||
}, | ||
}); | ||
|
||
if (entity.gdprRelevancy) { | ||
await Promise.all( | ||
data.collection.map(async (edge) => | ||
axios.patch( | ||
urljoin( | ||
ENTITY_MANAGEMENT_URL, | ||
`${edge.to.entityId.substr(0, edge.to.entityId.indexOf(":"))}s`, | ||
edge.to.entityId | ||
), | ||
{ | ||
gdprRelevancy: true, | ||
}, | ||
{ | ||
headers: { | ||
"x-diva": JSON.stringify({ | ||
actorId: serviceId, | ||
}), | ||
}, | ||
} | ||
) | ||
) | ||
); | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}; | ||
|
||
const analyze = async () => { | ||
try { | ||
if (PATCHED_PROPERTY === "gdprRelevancy") { | ||
await forwardGdprRelevancy(); | ||
} | ||
return true; | ||
} catch (err) { | ||
throw new Error(err); | ||
} | ||
}; | ||
|
||
analyze() | ||
.then(() => { | ||
console.log("success"); | ||
process.exit(0); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.