forked from mi6/ic-ui-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-audit-expiry.js
34 lines (29 loc) · 974 Bytes
/
check-audit-expiry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require('fs');
function isDateFurtherThanAMonth(dateString) {
const currentDate = new Date();
const expiryDate = new Date(dateString);
const oneMonthFromNow = new Date();
oneMonthFromNow.setMonth(currentDate.getMonth() + 1);
return expiryDate > oneMonthFromNow;
}
fs.readFile('audit-ci.json', 'utf8', (err, data) => {
if (err) {
console.error('Error reading audit-ci.json:', err);
return;
}
try {
const jsonData = JSON.parse(data);
const allowlist = jsonData.allowlist;
for (const key in allowlist) {
const item = allowlist[key];
const advisoryId = Object.keys(item)[0];
const itemObj = item[advisoryId];
if (itemObj.active && isDateFurtherThanAMonth(itemObj.expiry)) {
console.error(`Expiry date for ${advisoryId} is further away than a month.`);
process.exit(1);
}
}
} catch (parseError) {
console.error('Error parsing JSON in audit-ci.json:', parseError);
}
});