mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 20:59:10 +01:00
fix(scan): dump nil slice of vulnerabilities as empty slice in report
Closes #11131 Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
parent
8ddfe2d0a5
commit
e1ab30dadf
@ -15,6 +15,8 @@
|
|||||||
package vuln
|
package vuln
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
v1 "github.com/goharbor/harbor/src/pkg/scan/rest/v1"
|
v1 "github.com/goharbor/harbor/src/pkg/scan/rest/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,6 +32,24 @@ type Report struct {
|
|||||||
Vulnerabilities []*VulnerabilityItem `json:"vulnerabilities"`
|
Vulnerabilities []*VulnerabilityItem `json:"vulnerabilities"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON custom function to dump nil slice of Vulnerabilities as empty slice
|
||||||
|
// See https://github.com/goharbor/harbor/issues/11131 to get more details
|
||||||
|
func (report *Report) MarshalJSON() ([]byte, error) {
|
||||||
|
type Alias Report
|
||||||
|
|
||||||
|
aux := &struct {
|
||||||
|
*Alias
|
||||||
|
}{
|
||||||
|
Alias: (*Alias)(report),
|
||||||
|
}
|
||||||
|
|
||||||
|
if aux.Vulnerabilities == nil {
|
||||||
|
aux.Vulnerabilities = []*VulnerabilityItem{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Marshal(aux)
|
||||||
|
}
|
||||||
|
|
||||||
// Merge ...
|
// Merge ...
|
||||||
func (report *Report) Merge(another *Report) *Report {
|
func (report *Report) Merge(another *Report) *Report {
|
||||||
generatedAt := report.GeneratedAt
|
generatedAt := report.GeneratedAt
|
||||||
|
Loading…
Reference in New Issue
Block a user