(feat) adds error logging output for downloading reports from whitesource (#2928)

This commit is contained in:
ffeldmann
2021-06-21 13:36:08 +02:00
committed by GitHub
parent c0ae0df2f0
commit 6671afb909
2 changed files with 6 additions and 5 deletions
+5 -4
View File
@@ -8,6 +8,7 @@ import (
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/pkg/errors"
)
// ReportOptions defines options for downloading reports after scanning.
@@ -47,13 +48,13 @@ func (s *Scan) DownloadReports(options ReportOptions, utils scanUtils, sys white
func downloadVulnerabilityReport(options ReportOptions, project Project, utils scanUtils, sys whitesource) (*piperutils.Path, error) {
reportBytes, err := sys.GetProjectVulnerabilityReport(project.Token, options.VulnerabilityReportFormat)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "unable to download vulnerability report from url")
}
rptFileName := fmt.Sprintf("%s-vulnerability-report.%s", strings.ReplaceAll(project.Name, "/", "_"), options.VulnerabilityReportFormat)
rptFileName = filepath.Join(options.ReportDirectory, rptFileName)
if err := utils.FileWrite(rptFileName, reportBytes, 0644); err != nil {
return nil, err
return nil, errors.Wrapf(err, "unable to copy content from url to file %v", rptFileName)
}
log.Entry().Infof("Successfully downloaded vulnerability report to %s", rptFileName)
@@ -64,13 +65,13 @@ func downloadVulnerabilityReport(options ReportOptions, project Project, utils s
func downloadRiskReport(options ReportOptions, project Project, utils scanUtils, sys whitesource) (*piperutils.Path, error) {
reportBytes, err := sys.GetProjectRiskReport(project.Token)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "unable to download risk report from url")
}
rptFileName := fmt.Sprintf("%s-risk-report.pdf", strings.ReplaceAll(project.Name, "/", "_"))
rptFileName = filepath.Join(options.ReportDirectory, rptFileName)
if err := utils.FileWrite(rptFileName, reportBytes, 0644); err != nil {
return nil, err
return nil, errors.Wrapf(err, "unable to copy content from url to file %v", rptFileName)
}
log.Entry().Infof("Successfully downloaded risk report to %s", rptFileName)
+1 -1
View File
@@ -78,7 +78,7 @@ func TestDownloadReports(t *testing.T) {
// test
paths, err := scan.DownloadReports(options, utils, system)
// assert
assert.EqualError(t, err, "no project with token '' found in Whitesource")
assert.EqualError(t, err, "unable to download vulnerability report from url: no project with token '' found in Whitesource")
assert.Nil(t, paths)
})
t.Run("multiple scanned projects", func(t *testing.T) {