mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 02:05:41 +01:00
fix 20518 (#20521)
fixes #20518 Since there is no report for the replicated artifact, update to use the artifact id to remove accessories. Signed-off-by: wang yan <wangyan@vmware.com> Co-authored-by: Shengwen YU <yshengwen@vmware.com>
This commit is contained in:
parent
1a36a95a2b
commit
d8475906ba
@ -198,19 +198,15 @@ func retrieveSBOMContent(rawReport string) ([]byte, *v1.Scanner, error) {
|
||||
}
|
||||
|
||||
func (h *scanHandler) MakePlaceHolder(ctx context.Context, art *artifact.Artifact, r *scanner.Registration) (rps []*scanModel.Report, err error) {
|
||||
var reports []*scanModel.Report
|
||||
mgr := h.SBOMMgrFunc()
|
||||
mimeTypes := r.GetProducesMimeTypes(art.ManifestMediaType, v1.ScanTypeSbom)
|
||||
if len(mimeTypes) == 0 {
|
||||
return nil, errors.New("no mime types to make report placeholders")
|
||||
}
|
||||
sbomReports, err := mgr.GetBy(h.cloneCtx(ctx), art.ID, r.UUID, mimeTypes[0], sbomMediaTypeSpdx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := h.deleteSBOMAccessories(ctx, sbomReports); err != nil {
|
||||
if err := h.delete(ctx, art, mimeTypes[0], r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var reports []*scanModel.Report
|
||||
for _, mt := range mimeTypes {
|
||||
report := &sbom.Report{
|
||||
ArtifactID: art.ID,
|
||||
@ -241,20 +237,24 @@ func (h *scanHandler) MakePlaceHolder(ctx context.Context, art *artifact.Artifac
|
||||
return reports, nil
|
||||
}
|
||||
|
||||
// deleteSBOMAccessories delete the sbom accessory in reports
|
||||
func (h *scanHandler) deleteSBOMAccessories(ctx context.Context, reports []*sbom.Report) error {
|
||||
// delete deletes the sbom report and accessory
|
||||
func (h *scanHandler) delete(ctx context.Context, art *artifact.Artifact, mimeTypes string, r *scanner.Registration) error {
|
||||
mgr := h.SBOMMgrFunc()
|
||||
for _, rpt := range reports {
|
||||
sbomReports, err := mgr.GetBy(h.cloneCtx(ctx), art.ID, r.UUID, mimeTypes, sbomMediaTypeSpdx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, rpt := range sbomReports {
|
||||
if rpt.MimeType != v1.MimeTypeSBOMReport {
|
||||
continue
|
||||
}
|
||||
if err := h.deleteSBOMAccessory(ctx, rpt.ArtifactID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := mgr.Delete(ctx, rpt.UUID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := h.deleteSBOMAccessory(ctx, art.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user