Allow to configure the minimum package age

This commit is contained in:
Sander Declerck 2025-11-26 16:42:51 +01:00
parent 5c3c3399d9
commit 13892efa70
No known key found for this signature in database
8 changed files with 449 additions and 3 deletions

View file

@ -9,7 +9,8 @@ import { getEcoSystem } from "./settings.js";
*
* This should be a number, but can be anything because it is user-input.
* We cannot trust the input and should add the necessary validations.
* @property {any} scanTimeout
* @property {unknown} scanTimeout
* @property {unknown} minimumPackageAgeHours
*/
/**
@ -48,6 +49,35 @@ function validateTimeout(value) {
return null;
}
/**
* @param {any} value
* @returns {number | undefined}
*/
function validateMinimumPackageAgeHours(value) {
const hours = Number(value);
if (!Number.isNaN(hours)) {
return hours;
}
return undefined;
}
/**
* Gets the minimum package age in hours from config file only
* @returns {number | undefined}
*/
export function getMinimumPackageAgeHours() {
const config = readConfigFile();
if (config.minimumPackageAgeHours) {
const validated = validateMinimumPackageAgeHours(
config.minimumPackageAgeHours
);
if (validated !== undefined) {
return validated;
}
}
return undefined;
}
/**
* @param {import("../api/aikido.js").MalwarePackage[]} data
* @param {string | number} version
@ -111,6 +141,7 @@ function readConfigFile() {
if (!fs.existsSync(configFilePath)) {
return {
scanTimeout: undefined,
minimumPackageAgeHours: undefined,
};
}
@ -120,6 +151,7 @@ function readConfigFile() {
} catch {
return {
scanTimeout: undefined,
minimumPackageAgeHours: undefined,
};
}
}