|
18 | 18 | package security
|
19 | 19 |
|
20 | 20 | import (
|
| 21 | + serverBean "github.com/devtron-labs/devtron/pkg/server/bean" |
21 | 22 | "github.com/go-pg/pg"
|
22 | 23 | "go.uber.org/zap"
|
23 | 24 | "time"
|
24 | 25 | )
|
25 | 26 |
|
26 | 27 | type ImageScanExecutionHistory struct {
|
27 |
| - tableName struct{} `sql:"image_scan_execution_history" pg:",discard_unknown_columns"` |
28 |
| - Id int `sql:"id,pk"` |
29 |
| - Image string `sql:"image,notnull"` |
30 |
| - ImageHash string `sql:"image_hash,notnull"` |
31 |
| - ExecutionTime time.Time `sql:"execution_time"` |
32 |
| - ExecutedBy int `sql:"executed_by,notnull"` |
| 28 | + tableName struct{} `sql:"image_scan_execution_history" pg:",discard_unknown_columns"` |
| 29 | + Id int `sql:"id,pk"` |
| 30 | + Image string `sql:"image,notnull"` |
| 31 | + ImageHash string `sql:"image_hash,notnull"` // TODO Migrate to request metadata |
| 32 | + ExecutionTime time.Time `sql:"execution_time"` |
| 33 | + ExecutedBy int `sql:"executed_by,notnull"` |
| 34 | + SourceMetadataJson string `sql:"source_metadata_json"` // to have relevant info to process a scan for a given source type and subtype |
| 35 | + ExecutionHistoryDirectoryPath string `sql:"execution_history_directory_path"` // Deprecated |
| 36 | + SourceType SourceType `sql:"source_type"` |
| 37 | + SourceSubType SourceSubType `sql:"source_sub_type"` |
| 38 | + ResourceScanExecutionResult *ResourceScanExecutionResult |
| 39 | + ScanToolExecutionHistoryMapping *ScanToolExecutionHistoryMapping |
33 | 40 | }
|
34 | 41 |
|
| 42 | +func (ed *ExecutionData) IsBuiltImage() bool { |
| 43 | + return ed.SourceType == SourceTypeImage && ed.SourceSubType == SourceSubTypeCi |
| 44 | +} |
| 45 | + |
| 46 | +func (ed *ExecutionData) IsManifestImage() bool { |
| 47 | + return ed.SourceType == SourceTypeImage && ed.SourceSubType == SourceSubTypeManifest |
| 48 | +} |
| 49 | + |
| 50 | +func (ed *ExecutionData) IsManifest() bool { |
| 51 | + return ed.SourceType == SourceTypeCode && ed.SourceSubType == SourceSubTypeManifest |
| 52 | +} |
| 53 | + |
| 54 | +func (ed *ExecutionData) IsCode() bool { |
| 55 | + return ed.SourceType == SourceTypeCode && ed.SourceSubType == SourceSubTypeCi |
| 56 | +} |
| 57 | + |
| 58 | +func (ed *ExecutionData) ContainsType(typeToCheck ResourceScanType) bool { |
| 59 | + for _, scanType := range ed.Types { |
| 60 | + if scanType == int(typeToCheck) { |
| 61 | + return true |
| 62 | + } |
| 63 | + } |
| 64 | + return false |
| 65 | +} |
| 66 | + |
| 67 | +type ExecutionData struct { |
| 68 | + Image string |
| 69 | + ScanDataJson string |
| 70 | + StartedOn time.Time |
| 71 | + ScanToolName string |
| 72 | + SourceType SourceType |
| 73 | + SourceSubType SourceSubType |
| 74 | + Types []int `sql:"types" pg:",array"` |
| 75 | + Status serverBean.ScanExecutionProcessState |
| 76 | +} |
| 77 | + |
| 78 | +// multiple history rows for one source event |
| 79 | +type SourceType int |
| 80 | + |
| 81 | +const ( |
| 82 | + SourceTypeImage SourceType = 1 |
| 83 | + SourceTypeCode SourceType = 2 |
| 84 | + SourceTypeSbom SourceType = 3 // can be used in future for direct sbom scanning |
| 85 | +) |
| 86 | + |
| 87 | +type SourceSubType int |
| 88 | + |
| 89 | +const ( |
| 90 | + SourceSubTypeCi SourceSubType = 1 // relevant for ci code(2,1) or ci built image(1,1) |
| 91 | + SourceSubTypeManifest SourceSubType = 2 // relevant for devtron app deployment manifest/helm app manifest(2,2) or images retrieved from manifest(1,2)) |
| 92 | +) |
| 93 | + |
35 | 94 | type ImageScanHistoryRepository interface {
|
36 | 95 | Save(model *ImageScanExecutionHistory) error
|
37 | 96 | FindAll() ([]*ImageScanExecutionHistory, error)
|
|
0 commit comments