mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 02:05:41 +01:00
Response an error message when there is incomplete sbom generate job (#20526)
Response an error message when there is uncomplete sbom generate job Signed-off-by: stonezdj <stone.zhang@broadcom.com> Co-authored-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
7645ec7ccc
commit
30767f6612
@ -244,6 +244,14 @@ func (h *scanHandler) delete(ctx context.Context, art *artifact.Artifact, mimeTy
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// check if any report has running task associate with it
|
||||
taskMgr := h.TaskMgrFunc()
|
||||
for _, rpt := range sbomReports {
|
||||
if !taskMgr.IsTaskFinished(ctx, rpt.UUID) {
|
||||
return errors.ConflictError(nil).WithMessage("a previous sbom generate process is running")
|
||||
}
|
||||
}
|
||||
|
||||
for _, rpt := range sbomReports {
|
||||
if rpt.MimeType != v1.MimeTypeSBOMReport {
|
||||
continue
|
||||
|
@ -219,6 +219,7 @@ func (suite *SBOMTestSuite) TestMakeReportPlaceHolder() {
|
||||
mock.OnAnything(suite.sbomManager, "Create").Return("uuid", nil).Once()
|
||||
mock.OnAnything(suite.sbomManager, "Delete").Return(nil).Once()
|
||||
mock.OnAnything(suite.taskMgr, "ListScanTasksByReportUUID").Return([]*task.Task{{Status: "Success"}}, nil)
|
||||
mock.OnAnything(suite.taskMgr, "IsTaskFinished").Return(true).Once()
|
||||
mock.OnAnything(suite.artifactCtl, "Get").Return(art, nil)
|
||||
mock.OnAnything(suite.artifactCtl, "Delete").Return(nil)
|
||||
rps, err := suite.handler.MakePlaceHolder(ctx, art, r)
|
||||
|
@ -197,6 +197,24 @@ func (_m *mockTaskManager) GetLogByJobID(ctx context.Context, jobID string) ([]b
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// IsTaskFinished provides a mock function with given fields: ctx, reportID
|
||||
func (_m *mockTaskManager) IsTaskFinished(ctx context.Context, reportID string) bool {
|
||||
ret := _m.Called(ctx, reportID)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for IsTaskFinished")
|
||||
}
|
||||
|
||||
var r0 bool
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok {
|
||||
r0 = rf(ctx, reportID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(bool)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// List provides a mock function with given fields: ctx, query
|
||||
func (_m *mockTaskManager) List(ctx context.Context, query *q.Query) ([]*Task, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
@ -69,6 +69,8 @@ type Manager interface {
|
||||
ListScanTasksByReportUUID(ctx context.Context, uuid string) (tasks []*Task, err error)
|
||||
// RetrieveStatusFromTask retrieve status from task
|
||||
RetrieveStatusFromTask(ctx context.Context, reportID string) string
|
||||
// IsTaskFinished checks if the scan task is finished by report UUID
|
||||
IsTaskFinished(ctx context.Context, reportID string) bool
|
||||
}
|
||||
|
||||
// NewManager creates an instance of the default task manager
|
||||
@ -299,3 +301,11 @@ func (m *manager) RetrieveStatusFromTask(ctx context.Context, reportID string) s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *manager) IsTaskFinished(ctx context.Context, reportID string) bool {
|
||||
status := m.RetrieveStatusFromTask(ctx, reportID)
|
||||
if len(status) == 0 {
|
||||
return true
|
||||
}
|
||||
return job.Status(status).Final()
|
||||
}
|
||||
|
@ -199,6 +199,24 @@ func (_m *Manager) GetLogByJobID(ctx context.Context, jobID string) ([]byte, err
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// IsTaskFinished provides a mock function with given fields: ctx, reportID
|
||||
func (_m *Manager) IsTaskFinished(ctx context.Context, reportID string) bool {
|
||||
ret := _m.Called(ctx, reportID)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for IsTaskFinished")
|
||||
}
|
||||
|
||||
var r0 bool
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string) bool); ok {
|
||||
r0 = rf(ctx, reportID)
|
||||
} else {
|
||||
r0 = ret.Get(0).(bool)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// List provides a mock function with given fields: ctx, query
|
||||
func (_m *Manager) List(ctx context.Context, query *q.Query) ([]*task.Task, error) {
|
||||
ret := _m.Called(ctx, query)
|
||||
|
Loading…
Reference in New Issue
Block a user