Skip to content

Commit 8611ed3

Browse files
authored
feat: Add download_cve_report_csv method to download the csv report (#161)
This method takes a while in environments where the amount of images is very high, please use it carefully.
1 parent 80c41ec commit 8611ed3

File tree

6 files changed

+81
-1
lines changed

6 files changed

+81
-1
lines changed

sdcclient/_scanning.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,4 +1186,43 @@ def update_vulnerability_exception(self, bundle, id, cve, enabled, note, expirat
11861186

11871187
res_json = res.json()
11881188
res_json["trigger_id"] = str(res_json["trigger_id"]).rstrip("+*")
1189-
return [True, res_json]
1189+
return [True, res_json]
1190+
1191+
def download_cve_report_csv(self, vuln_type="os", scope_type="static"):
1192+
"""
1193+
Downloads a CVE report in CSV format
1194+
1195+
Args:
1196+
vuln_type (str): Vulnerability type, can be either "os" or "non-os".
1197+
scope_type (str): Scope type. Can be either "static" or "runtime".
1198+
1199+
Returns:
1200+
A tuple of (bool, str).
1201+
The first parameter, if true, means that the result is correct, while
1202+
if false, means that there's been an error. The second parameter
1203+
will hold the response of the API call.
1204+
"""
1205+
url = f"{self.url}/api/scanning/v1/reports/csv"
1206+
1207+
params = {
1208+
"queryType": "vuln",
1209+
"scopeType": scope_type,
1210+
"staticScope":
1211+
{
1212+
"registry": "",
1213+
"repository": "",
1214+
"tag": ""
1215+
},
1216+
"runtimeScope": {},
1217+
"imageQueryFilter": {
1218+
"vType": vuln_type
1219+
},
1220+
"offset": 0,
1221+
"limit": 100000
1222+
}
1223+
1224+
res = self.http.post(url, data=json.dumps(params), headers=self.hdrs, verify=self.ssl_verify)
1225+
if not self._checkResponse(res):
1226+
return [False, self.lasterr]
1227+
1228+
return [True, res.content.decode("utf-8")]

specs/secure/__init__.py

Whitespace-only changes.

specs/secure/scanning/__init__.py

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
3+
from expects import *
4+
from mamba import *
5+
6+
from sdcclient import SdScanningClient
7+
from specs import be_successful_api_call
8+
9+
with description("CVE Reports", "integration") as self:
10+
with before.all:
11+
self.client = SdScanningClient(sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"),
12+
token=os.getenv("SDC_SECURE_TOKEN"))
13+
with context("when the CSV of static can be downloaded"):
14+
with it("is able to download it for OS vulnerabilities"):
15+
ok, csv = self.client.download_cve_report_csv(vuln_type="os", scope_type="static")
16+
17+
expect((ok, csv)).to(be_successful_api_call)
18+
expect(csv).to(start_with("Image Name,Tag,Package Name,Package Version,Package Path,Severity,Fixed In,"
19+
"Vulnerability ID,Links,Image Digest,Runtime Metadata"))
20+
21+
with it("is able to download it for non-OS vulnerabilities"):
22+
ok, csv = self.client.download_cve_report_csv(vuln_type="non-os", scope_type="static")
23+
24+
expect((ok, csv)).to(be_successful_api_call)
25+
expect(csv).to(start_with("Image Name,Tag,Package Name,Package Version,Package Path,Severity,Fixed In,"
26+
"Vulnerability ID,Links,Image Digest,Runtime Metadata"))
27+
28+
with context("when the CSV of runtime can be downloaded"):
29+
with it("is able to download it for OS vulnerabilities"):
30+
ok, csv = self.client.download_cve_report_csv(vuln_type="os", scope_type="runtime")
31+
32+
expect((ok, csv)).to(be_successful_api_call)
33+
expect(csv).to(start_with("Image Name,Tag,Package Name,Package Version,Package Path,Severity,Fixed In,"
34+
"Vulnerability ID,Links,Image Digest,Runtime Metadata"))
35+
36+
with it("is able to download it for non-OS vulnerabilities"):
37+
ok, csv = self.client.download_cve_report_csv(vuln_type="non-os", scope_type="runtime")
38+
39+
expect((ok, csv)).to(be_successful_api_call)
40+
expect(csv).to(start_with("Image Name,Tag,Package Name,Package Version,Package Path,Severity,Fixed In,"
41+
"Vulnerability ID,Links,Image Digest,Runtime Metadata"))

0 commit comments

Comments
 (0)