-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnyk_utils.js
73 lines (58 loc) · 1.58 KB
/
snyk_utils.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var exports = module.exports = {};
const axios = require('axios');
var fs = require('fs');
var snykToHtml = require('./snyk-to-html.js');
var orgID = '';
var tokenAPI = '';
exports.setCredentials = (organizationID, APIkey) => {
orgID = organizationID;
tokenAPI = APIkey;
}
exports.snykTestCoordinates = (coordinateList) => {
var config = {
headers: {'Authorization': tokenAPI}
};
console.log(coordinateList[0]);
axios.get('https://snyk.io/api/v1/test/maven/'+coordinateList[0][0]+'/'+coordinateList[0][1]+'/'+coordinateList[0][2]+'?org='+orgID, config)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.log(error);
});
}
exports.snykTestPomFiles = (pomList) => {
return new Promise((resolve,reject) => {
var file = fs.readFileSync(pomList[0],'utf8');
var files = [];
for(i=1;i<pomList.length;i++){
files.push({contents: fs.readFileSync(pomList[i],'utf8')})
}
var content = {
encoding: "plain",
files: {
target: {
contents: file
},
additional: files
}
}
var data = JSON.stringify(content);
axios({
method: 'post',
url: 'https://snyk.io/api/v1/test/maven/?org='+orgID,
data: data,
headers: {'Authorization': tokenAPI, 'Content-Type':'application/json'}
}).then(function (response) {
resolve(response.data)
})
.catch(function (error) {
reject(error);
});
});
}
exports.generateHtmlReport = (jsonData) => {
return new Promise((resolve, reject) => {
resolve(snykToHtml.run(jsonData))
});
}