Add explicit type information to checks

Types can be used to:
* Determine which check logic to run
* Determine the correct persistence option to use
* Choose correct ser/deser logic for the check
* Determine correct components to render on the frontend

Modify router API to be post for better usability. The API might end up doing writes if caching etc. is added in later as well.

Modify CheckRegistry & FactChecker to return persisted check when it is registered.

Signed-off-by: Jussi Hallila <jussi@hallila.com>
This commit is contained in:
Jussi Hallila
2021-10-21 09:25:26 +02:00
parent 75fc6ac85b
commit b2363f3e3b
11 changed files with 91 additions and 17 deletions
@@ -83,11 +83,16 @@ export async function createRouter<
return res.send(await factChecker.getChecks());
});
router.get('/checks/:namespace/:kind/:name', async (req, res) => {
router.post('/checks/run/:namespace/:kind/:name', async (req, res) => {
const { namespace, kind, name } = req.params;
const checks = req.query.checks as string[];
const entityTriplet = `${namespace.toLowerCase()}/${kind.toLowerCase()}/${name.toLowerCase()}`;
try {
if (!('checks' in req.body)) {
return res.status(422).send({
message: 'Failed to get checks from request.',
});
}
const { checks }: { checks: string[] } = req.body;
const entityTriplet = `${namespace.toLowerCase()}/${kind.toLowerCase()}/${name.toLowerCase()}`;
const checkResult = await factChecker.runChecks(entityTriplet, checks);
return res.send(checkResult);
} catch (e) {
@@ -120,7 +125,11 @@ export async function createRouter<
const startDatetime = DateTime.fromISO(req.query.startDatetime as string);
const endDatetime = DateTime.fromISO(req.query.endDatetime as string);
if (!startDatetime.isValid || !endDatetime.isValid) {
return res.status(422).send('Failed to parse datetime from request');
return res.status(422).send({
message: 'Failed to parse datetime from request',
field: !startDatetime.isValid ? 'startDateTime' : 'endDateTime',
value: !startDatetime.isValid ? startDatetime : endDatetime,
});
}
const entityTriplet = `${namespace.toLowerCase()}/${kind.toLowerCase()}/${name.toLowerCase()}`;
return res.send(