Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/sql/repository/RegistryIndexMappingRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ type RegistryIndexMappingRepository interface {
}

func (repo *RegistryIndexMappingRepositoryImpl) GetStartingIndexForARegistryAndATool(scanToolid int, registry common.RegistryType) (*RegistryIndexMapping, error) {
if registry == "" {
return &RegistryIndexMapping{
Index: 5,
}, nil
}
var model RegistryIndexMapping
err := repo.dbConnection.Model(&model).Where("scan_tool_id = ?", scanToolid).Where("registry_type = ?", registry).Select()
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ type ScanToolExecutionHistoryMapping struct {
ExecutionFinishTime time.Time `sql:"execution_finish_time,notnull"`
State bean.ScanExecutionProcessState `sql:"state"`
TryCount int `sql:"try_count"`
ErrorMessage string `sql:"error_message"`
AuditLog
}

type ScanToolExecutionHistoryMappingRepository interface {
Save(model *ScanToolExecutionHistoryMapping) error
SaveInBatch(models []*ScanToolExecutionHistoryMapping) error
UpdateStateByToolAndExecutionHistoryId(executionHistoryId, toolId int, state bean.ScanExecutionProcessState, executionFinishTime time.Time) error
UpdateStateByToolAndExecutionHistoryId(executionHistoryId, toolId int, state bean.ScanExecutionProcessState, executionFinishTime time.Time, errorMessage string) error
MarkAllRunningStateAsFailedHavingTryCountReachedLimit(tryCount int) error
GetAllScanHistoriesByState(state bean.ScanExecutionProcessState) ([]*ScanToolExecutionHistoryMapping, error)
GetAllScanHistoriesByExecutionHistoryIdAndStates(executionHistoryId int, states []bean.ScanExecutionProcessState) ([]*ScanToolExecutionHistoryMapping, error)
Expand Down Expand Up @@ -60,9 +61,11 @@ func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) SaveInBatch(models []
}

func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) UpdateStateByToolAndExecutionHistoryId(executionHistoryId, toolId int,
state bean.ScanExecutionProcessState, executionFinishTime time.Time) error {
state bean.ScanExecutionProcessState, executionFinishTime time.Time, errorMessage string) error {
model := &ScanToolExecutionHistoryMapping{}
_, err := repo.dbConnection.Model(model).Set("state = ?", state).
_, err := repo.dbConnection.Model(model).
Set("state = ?", state).
Set("error_message = ?", errorMessage).
Set("execution_finish_time = ?", executionFinishTime).
Where("image_scan_execution_history_id = ?", executionHistoryId).
Where("scan_tool_id = ?", toolId).Update()
Expand Down
10 changes: 8 additions & 2 deletions pkg/security/ImageScanService.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ func (impl *ImageScanServiceImpl) ScanImage(scanEvent *common.ImageScanEvent, to
}

func (impl *ImageScanServiceImpl) getImageScanRenderDto(registryId string, image string) (*common.ImageScanRenderDto, error) {

dockerRegistry, err := impl.dockerArtifactStoreRepository.FindById(registryId)
if err != nil {
if err == pg.ErrNoRows {
dockerRegistry = &repository.DockerArtifactStore{}
} else if err != nil {
impl.logger.Errorw("error in getting docker registry by id", "err", err, "id", registryId)
return nil, err
}
Expand All @@ -144,13 +147,16 @@ func (impl *ImageScanServiceImpl) scanImageForTool(tool *repository.ScanToolMeta
toolCopy := *tool
var processedState bean.ScanExecutionProcessState
err := impl.ProcessScanForTool(toolCopy, executionHistoryDirPathCopy, executionHistoryId, userId, ctx, imageScanRenderDto)
var errorMessage string
if err != nil {
impl.logger.Errorw("error in processing scan for tool:", toolCopy.Name, "err", err)
processedState = bean.ScanExecutionProcessStateFailed
errorMessage = err.Error()
} else {
processedState = bean.ScanExecutionProcessStateCompleted
}
updateErr := impl.scanToolExecutionHistoryMappingRepository.UpdateStateByToolAndExecutionHistoryId(executionHistoryId, toolCopy.Id, processedState, time.Now())

updateErr := impl.scanToolExecutionHistoryMappingRepository.UpdateStateByToolAndExecutionHistoryId(executionHistoryId, toolCopy.Id, processedState, time.Now(), errorMessage)
if updateErr != nil {
impl.logger.Errorw("error in UpdateStateByToolAndExecutionHistoryId", "err", err)
err = updateErr
Expand Down