mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Allow to configure the minimum package age
This commit is contained in:
parent
5c3c3399d9
commit
13892efa70
8 changed files with 449 additions and 3 deletions
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue