@@ -6588,14 +6588,15 @@ function run() {
6588
6588
};
6589
6589
const downloader = new trivy_1.Downloader();
6590
6590
const trivyCmdPath = yield downloader.download(trivyVersion);
6591
- const result = trivy_1.Trivy.scan(trivyCmdPath, image, trivyOption);
6591
+ const trivy = new trivy_1.Trivy();
6592
+ const result = trivy.scan(trivyCmdPath, image, trivyOption);
6592
6593
if (!issueFlag) {
6593
6594
core.info(`Not create a issue because issue parameter is false.
6594
6595
Vulnerabilities:
6595
6596
${result}`);
6596
6597
return;
6597
6598
}
6598
- const issueContent = trivy_1.Trivy .parse(result);
6599
+ const issueContent = trivy .parse(result);
6599
6600
if (issueContent === '') {
6600
6601
core.info('Vulnerabilities were not found.\nYour maintenance looks good 👍');
6601
6602
return;
@@ -13315,8 +13316,8 @@ Downloader.trivyRepository = {
13315
13316
repo: 'trivy',
13316
13317
};
13317
13318
class Trivy {
13318
- static scan(trivyPath, image, option) {
13319
- Trivy .validateOption(option);
13319
+ scan(trivyPath, image, option) {
13320
+ this .validateOption(option);
13320
13321
const args = [
13321
13322
'--severity',
13322
13323
option.severity,
@@ -13345,7 +13346,7 @@ class Trivy {
13345
13346
erorr: ${result.error}
13346
13347
`);
13347
13348
}
13348
- static parse(vulnerabilities) {
13349
+ parse(vulnerabilities) {
13349
13350
let issueContent = '';
13350
13351
for (const vuln of vulnerabilities) {
13351
13352
if (vuln.Vulnerabilities === null)
@@ -13368,23 +13369,36 @@ class Trivy {
13368
13369
}
13369
13370
return issueContent;
13370
13371
}
13371
- static validateOption(option) {
13372
+ validateOption(option) {
13373
+ this.validateSeverity(option.severity.split(','));
13374
+ this.validateVulnType(option.vulnType.split(','));
13375
+ }
13376
+ validateSeverity(severities) {
13372
13377
const allowedSeverities = /UNKNOWN|LOW|MEDIUM|HIGH|CRITICAL/;
13373
- const allowedVulnTypes = /os|library/;
13374
- for (const severity of option.severity.split(',')) {
13375
- if (!allowedSeverities.test(severity)) {
13376
- throw new Error(`severity option error: ${severity} is unknown severity`);
13377
- }
13378
+ if (!validateArrayOption(allowedSeverities, severities)) {
13379
+ throw new Error(`Trivy option error: ${severities.join(',')} is unknown severity.
13380
+ Trivy supports UNKNOWN, LOW, MEDIUM, HIGH and CRITICAL.`);
13378
13381
}
13379
- for (const vulnType of option.vulnType.split(',')) {
13380
- if (!allowedVulnTypes.test(vulnType)) {
13381
- throw new Error(`vuln-type option error: ${vulnType} is unknown vuln-type`);
13382
- }
13382
+ return true;
13383
+ }
13384
+ validateVulnType(vulnTypes) {
13385
+ const allowedVulnTypes = /os|library/;
13386
+ if (!validateArrayOption(allowedVulnTypes, vulnTypes)) {
13387
+ throw new Error(`Trivy option error: ${vulnTypes.join(',')} is unknown vuln-type.
13388
+ Trivy supports os and library.`);
13383
13389
}
13384
13390
return true;
13385
13391
}
13386
13392
}
13387
13393
exports.Trivy = Trivy;
13394
+ function validateArrayOption(allowedValue, options) {
13395
+ for (const option of options) {
13396
+ if (!allowedValue.test(option)) {
13397
+ return false;
13398
+ }
13399
+ }
13400
+ return true;
13401
+ }
13388
13402
13389
13403
13390
13404
/***/ }),
0 commit comments