Skip to content

Commit 82301e6

Browse files
committed
[trivy.ts] Replace to N/A if vulnerability info is undefined
1 parent c482731 commit 82301e6

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

dist/index.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13224,16 +13224,15 @@ class Downloader {
1322413224
});
1322513225
}
1322613226
checkPlatform(platform) {
13227-
if (platform === 'linux') {
13228-
return 'Linux';
13229-
}
13230-
else if (platform === 'darwin') {
13231-
return 'macOS';
13232-
}
13233-
else {
13234-
throw new Error(`Sorry, ${platform} is not supported.
13235-
Trivy support Linux, MacOS, FreeBSD and OpenBSD.
13236-
`);
13227+
switch (platform) {
13228+
case 'linux':
13229+
return 'Linux';
13230+
case 'darwin':
13231+
return 'macOS';
13232+
default:
13233+
throw new Error(`Sorry, ${platform} is not supported.
13234+
Trivy support Linux, MacOS, FreeBSD and OpenBSD.
13235+
`);
1323713236
}
1323813237
}
1323913238
getDownloadUrl(version, os) {
@@ -13291,7 +13290,6 @@ class Downloader {
1329113290
}
1329213291
trivyExists(baseDir) {
1329313292
const trivyCmdPaths = fs_1.default.readdirSync(baseDir).filter(f => f === 'trivy');
13294-
console.log(trivyCmdPaths);
1329513293
return trivyCmdPaths.length === 1;
1329613294
}
1329713295
}
@@ -13333,10 +13331,11 @@ class Trivy {
1333313331
vulnTable += 'Installed Version|Fixed Version|References|\n';
1333413332
vulnTable += '|:--:|:--:|:--:|:--:|:--:|:--:|:--|\n';
1333513333
for (const cve of vuln.Vulnerabilities) {
13336-
vulnTable += `|${cve.Title}|${cve.Severity}|${cve.VulnerabilityID}|${cve.PkgName}`;
13337-
vulnTable += `|${cve.InstalledVersion}|${cve.FixedVersion}|`;
13334+
vulnTable += `|${cve.Title || 'N/A'}|${cve.Severity || 'N/A'}`;
13335+
vulnTable += `|${cve.VulnerabilityID || 'N/A'}|${cve.PkgName || 'N/A'}`;
13336+
vulnTable += `|${cve.InstalledVersion || 'N/A'}|${cve.FixedVersion || 'N/A'}|`;
1333813337
for (const reference of cve.References) {
13339-
vulnTable += `${reference}<br>`;
13338+
vulnTable += `${reference || 'N/A'}<br>`;
1334013339
}
1334113340
vulnTable.replace(/<br>$/, '|\n');
1334213341
}

src/trivy.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ export class Downloader {
3838
}
3939

4040
private checkPlatform(platform: string): string {
41-
if (platform === 'linux') {
42-
return 'Linux'
43-
} else if (platform === 'darwin') {
44-
return 'macOS'
45-
} else {
46-
throw new Error(`Sorry, ${platform} is not supported.
47-
Trivy support Linux, MacOS, FreeBSD and OpenBSD.
48-
`)
41+
switch (platform) {
42+
case 'linux':
43+
return 'Linux'
44+
case 'darwin':
45+
return 'macOS'
46+
default:
47+
throw new Error(`Sorry, ${platform} is not supported.
48+
Trivy support Linux, MacOS, FreeBSD and OpenBSD.
49+
`)
4950
}
5051
}
5152

@@ -102,7 +103,6 @@ export class Downloader {
102103

103104
public trivyExists(baseDir: string): boolean {
104105
const trivyCmdPaths: string[] = fs.readdirSync(baseDir).filter(f => f === 'trivy')
105-
console.log(trivyCmdPaths)
106106
return trivyCmdPaths.length === 1
107107
}
108108
}
@@ -147,11 +147,12 @@ export class Trivy {
147147
vulnTable += '|:--:|:--:|:--:|:--:|:--:|:--:|:--|\n'
148148

149149
for (const cve of vuln.Vulnerabilities) {
150-
vulnTable += `|${cve.Title}|${cve.Severity}|${cve.VulnerabilityID}|${cve.PkgName}`
151-
vulnTable += `|${cve.InstalledVersion}|${cve.FixedVersion}|`
150+
vulnTable += `|${cve.Title || 'N/A'}|${cve.Severity || 'N/A'}`
151+
vulnTable += `|${cve.VulnerabilityID || 'N/A'}|${cve.PkgName || 'N/A'}`
152+
vulnTable += `|${cve.InstalledVersion || 'N/A'}|${cve.FixedVersion || 'N/A'}|`
152153

153154
for (const reference of cve.References) {
154-
vulnTable += `${reference}<br>`
155+
vulnTable += `${reference || 'N/A'}<br>`
155156
}
156157

157158
vulnTable.replace(/<br>$/, '|\n')

0 commit comments

Comments
 (0)