-
Notifications
You must be signed in to change notification settings - Fork 2
/
snyk-ignores.mjs
53 lines (41 loc) · 1.29 KB
/
snyk-ignores.mjs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import axios from 'axios';
import minimist from 'minimist';
import { writeFile } from 'fs';
// Get arguments
var args = minimist(process.argv.slice(2));
// Config for Axios
const config = {
baseURL: 'https://snyk.io/api/v1',
headers: {'Authorization': 'token '+process.env.SNYK_TOKEN}
}
// Make GET request to Snyk API
const ignores = (await axios.get(`/org/${args['org']}/project/${args['project']}/ignores`, config)).data
// Create a list of the issue ID's
const issues = Object.keys(ignores)
// Create header of .snyk file
var snykIgnore = `# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.14.0
ignore:
`
issues.forEach(issue => {
// Get Path
var path = Object.keys(ignores[issue][0])
if (path == '*') {var pathString = `'*'`}
else {pathString = path}
// Get Reason
var reason = ignores[issue][0][path].reason
if(reason == '') {reason = 'None given'}
// Get Expires
var expires = ignores[issue][0][path].expires
// Create entry for current issue
snykIgnore += ` ${issue}:
- ${pathString} :
reason: '${reason}'
expires: '${expires}'
`
})
console.log(snykIgnore);
writeFile('.snyk', snykIgnore, (err) => {
if (err) throw err;
console.log('The Snyk policy file has been saved!');
});