@@ -1,7 +1,7 @@
|
||||
---
|
||||
'@backstage/plugin-tech-insights': minor
|
||||
'@backstage/plugin-tech-insights-backend': minor
|
||||
'@backstage/plugin-tech-insights-common': minor
|
||||
'@backstage/plugin-tech-insights': patch
|
||||
'@backstage/plugin-tech-insights-backend': patch
|
||||
'@backstage/plugin-tech-insights-common': patch
|
||||
'@backstage/plugin-tech-insights-backend-module-jsonfc': patch
|
||||
---
|
||||
|
||||
|
||||
+6
-2
@@ -35,6 +35,7 @@ import { pick } from 'lodash';
|
||||
import Ajv, { SchemaObject } from 'ajv';
|
||||
import * as validationSchema from './validation-schema.json';
|
||||
import { JSON_RULE_ENGINE_CHECK_TYPE } from '../constants';
|
||||
import { isError } from '@backstage/errors';
|
||||
|
||||
const noopEvent = {
|
||||
type: 'noop',
|
||||
@@ -138,8 +139,11 @@ export class JsonRulesEngineFactChecker
|
||||
techInsightChecks,
|
||||
Object.values(facts),
|
||||
);
|
||||
} catch (e: any) {
|
||||
throw new Error(`Failed to run rules engine, ${e.message}`);
|
||||
} catch (e) {
|
||||
if (isError(e)) {
|
||||
throw new Error(`Failed to run rules engine, ${e.message}`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
parseEntityName,
|
||||
stringifyEntityRef,
|
||||
} from '@backstage/catalog-model';
|
||||
import { errorHandler } from '@backstage/backend-common';
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -92,36 +93,26 @@ export async function createRouter<
|
||||
|
||||
router.post('/checks/run/:namespace/:kind/:name', async (req, res) => {
|
||||
const { namespace, kind, name } = req.params;
|
||||
try {
|
||||
const { checks }: { checks: string[] } = req.body;
|
||||
const entityTriplet = stringifyEntityRef({ namespace, kind, name });
|
||||
const checkResult = await factChecker.runChecks(entityTriplet, checks);
|
||||
return res.send(checkResult);
|
||||
} catch (e: any) {
|
||||
return res.status(500).json({ message: e.message }).send();
|
||||
}
|
||||
const { checks }: { checks: string[] } = req.body;
|
||||
const entityTriplet = stringifyEntityRef({ namespace, kind, name });
|
||||
const checkResult = await factChecker.runChecks(entityTriplet, checks);
|
||||
return res.send(checkResult);
|
||||
});
|
||||
|
||||
router.post('/checks/run', async (req, res) => {
|
||||
try {
|
||||
const {
|
||||
checks,
|
||||
entities,
|
||||
}: { checks: string[]; entities: EntityName[] } = req.body;
|
||||
const tasks = entities.map(async entity => {
|
||||
const entityTriplet =
|
||||
typeof entity === 'string' ? entity : stringifyEntityRef(entity);
|
||||
const results = await factChecker.runChecks(entityTriplet, checks);
|
||||
return {
|
||||
entity: entityTriplet,
|
||||
results,
|
||||
};
|
||||
});
|
||||
const results = await Promise.all(tasks);
|
||||
return res.send(results);
|
||||
} catch (e: any) {
|
||||
return res.status(500).json({ message: e.message }).send();
|
||||
}
|
||||
const { checks, entities }: { checks: string[]; entities: EntityName[] } =
|
||||
req.body;
|
||||
const tasks = entities.map(async entity => {
|
||||
const entityTriplet =
|
||||
typeof entity === 'string' ? entity : stringifyEntityRef(entity);
|
||||
const results = await factChecker.runChecks(entityTriplet, checks);
|
||||
return {
|
||||
entity: entityTriplet,
|
||||
results,
|
||||
};
|
||||
});
|
||||
const results = await Promise.all(tasks);
|
||||
return res.send(results);
|
||||
});
|
||||
} else {
|
||||
logger.info(
|
||||
@@ -176,5 +167,7 @@ export async function createRouter<
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
router.use(errorHandler());
|
||||
return router;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user