-
Notifications
You must be signed in to change notification settings - Fork 554
feat: Trivy Image Scanning #3373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 44 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
84c6e85
wip
kartik-579 0b337f9
Merge branch 'main' into generic-image-scanning-sql
Shivam-nagar23 dac4483
Sql script fix
Shivam-nagar23 8b1ea10
Sql Fix
Shivam-nagar23 2f980c5
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 27d732e
Trivy and generic image scanning sql
Shivam-nagar23 6b6b6ce
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 150817b
script number change
Shivam-nagar23 d7457d7
Module Integration Changes
Shivam-nagar23 ea65353
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 7bfce10
Module Integration Changes
Shivam-nagar23 ed18d1c
wire changes
Shivam-nagar23 4bb9829
script renaming
Shivam-nagar23 c41aa70
Handling default value false
Shivam-nagar23 f3b5887
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 dbf1524
Script Number change
Shivam-nagar23 8eb86e7
Inclusion of module-type and enabled state for all modules
Shivam-nagar23 cb16866
Adding enabled
Shivam-nagar23 e5c8ee4
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 39fa8dd
Handling Version of Clair
Shivam-nagar23 c039790
Distinct condition
Shivam-nagar23 fafb34a
Distinct condition change
Shivam-nagar23 920223c
Testing changes
Shivam-nagar23 952f660
Testing changes
Shivam-nagar23 85e65f4
Update devtron.yaml
Shivam-nagar23 7c2eba1
Update installation-script
Shivam-nagar23 bd2054c
Final changes
Shivam-nagar23 aa5e6e8
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 61d89e3
Final changes
Shivam-nagar23 0688791
--Final changes--
Shivam-nagar23 f530f34
--Finalchanges--
Shivam-nagar23 e162295
Helm Command Handling
Shivam-nagar23 b930a3f
Helm Command Handling
Shivam-nagar23 cdc64d6
minor changes
Shivam-nagar23 c111f16
Pushing scantoolid in execution result
Shivam-nagar23 b545e5e
main merge
Shivam-nagar23 bef36e1
Image scan Scan Tool Id handling
Shivam-nagar23 87e8c80
No vulnerability image scan tool id handling
Shivam-nagar23 7185233
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 d11804f
Script number change
Shivam-nagar23 d156459
handling latest image scan deploy info
Shivam-nagar23 c74b969
main merge
Shivam-nagar23 7f8f7ef
script no change
Shivam-nagar23 180cd75
Handling For CICD enabling state
Shivam-nagar23 42dd226
review changes
Shivam-nagar23 ca32ad5
final changes
Shivam-nagar23 5c98330
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 7a926a5
fixes minor
Shivam-nagar23 2271c62
fixes minor
Shivam-nagar23 24cabee
fixes minor
Shivam-nagar23 42c7249
review changes
Shivam-nagar23 22d8cc2
changes for empty module type handling
Shivam-nagar23 57a0fc8
Merge branch 'main' into sql-fix-image-scanning
Shivam-nagar23 fba77b7
review changes and main sync script
Shivam-nagar23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
internal/sql/repository/security/ScanToolExecutionHistoryMapping.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package security | ||
|
|
||
| import ( | ||
| serverBean "github.com/devtron-labs/devtron/pkg/server/bean" | ||
| "github.com/devtron-labs/devtron/pkg/sql" | ||
| "github.com/go-pg/pg" | ||
| "go.uber.org/zap" | ||
| "time" | ||
| ) | ||
|
|
||
| type ScanToolExecutionHistoryMapping struct { | ||
| tableName struct{} `sql:"scan_tool_execution_history_mapping" pg:",discard_unknown_columns"` | ||
| Id int `sql:"id,pk"` | ||
| ImageScanExecutionHistoryId int `sql:"image_scan_execution_history_id"` | ||
| ScanToolId int `sql:"scan_tool_id"` | ||
| ExecutionStartTime time.Time `sql:"execution_start_time,notnull"` | ||
| ExecutionFinishTime time.Time `sql:"execution_finish_time,notnull"` | ||
| State serverBean.ScanExecutionProcessState `sql:"state"` | ||
| TryCount int `sql:"try_count"` | ||
| sql.AuditLog | ||
| } | ||
|
|
||
| type ScanToolExecutionHistoryMappingRepository interface { | ||
| Save(model *ScanToolExecutionHistoryMapping) error | ||
| SaveInBatch(models []*ScanToolExecutionHistoryMapping) error | ||
| UpdateStateByToolAndExecutionHistoryId(executionHistoryId, toolId int, state serverBean.ScanExecutionProcessState, executionFinishTime time.Time) error | ||
| MarkAllRunningStateAsFailedHavingTryCountReachedLimit(tryCount int) error | ||
| GetAllScanHistoriesByState(state serverBean.ScanExecutionProcessState) ([]*ScanToolExecutionHistoryMapping, error) | ||
| GetAllScanHistoriesByExecutionHistoryIdAndStates(executionHistoryId int, states []serverBean.ScanExecutionProcessState) ([]*ScanToolExecutionHistoryMapping, error) | ||
| GetAllScanHistoriesByExecutionHistoryIds(ids []int) ([]*ScanToolExecutionHistoryMapping, error) | ||
| } | ||
|
|
||
| type ScanToolExecutionHistoryMappingRepositoryImpl struct { | ||
| dbConnection *pg.DB | ||
| logger *zap.SugaredLogger | ||
| } | ||
|
|
||
| func NewScanToolExecutionHistoryMappingRepositoryImpl(dbConnection *pg.DB, | ||
| logger *zap.SugaredLogger) *ScanToolExecutionHistoryMappingRepositoryImpl { | ||
| return &ScanToolExecutionHistoryMappingRepositoryImpl{ | ||
| dbConnection: dbConnection, | ||
| logger: logger, | ||
| } | ||
| } | ||
|
|
||
| func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) Save(model *ScanToolExecutionHistoryMapping) error { | ||
| err := repo.dbConnection.Insert(model) | ||
| if err != nil { | ||
| repo.logger.Errorw("error in ScanToolExecutionHistoryMappingRepository, Save", "model", model, "err", err) | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) SaveInBatch(models []*ScanToolExecutionHistoryMapping) error { | ||
| err := repo.dbConnection.Insert(&models) | ||
| if err != nil { | ||
| repo.logger.Errorw("error in ScanToolExecutionHistoryMappingRepository, SaveInBatch", "err", err, "models", models) | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) UpdateStateByToolAndExecutionHistoryId(executionHistoryId, toolId int, | ||
| state serverBean.ScanExecutionProcessState, executionFinishTime time.Time) error { | ||
| model := &ScanToolExecutionHistoryMapping{} | ||
| _, err := repo.dbConnection.Model(model).Set("state = ?", state). | ||
| Set("execution_finish_time = ?", executionFinishTime). | ||
| Where("image_scan_execution_history_id = ?", executionHistoryId). | ||
| Where("scan_tool_id = ?", toolId).Update() | ||
Shivam-nagar23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| repo.logger.Errorw("error in ScanToolExecutionHistoryMappingRepository, SaveInBatch", "err", err, "model", model) | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) MarkAllRunningStateAsFailedHavingTryCountReachedLimit(tryCount int) error { | ||
| var models []*ScanToolExecutionHistoryMapping | ||
| _, err := repo.dbConnection.Model(&models). | ||
| Set("state = ?", serverBean.ScanExecutionProcessStateFailed). | ||
Shivam-nagar23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Where("state = ?", serverBean.ScanExecutionProcessStateRunning). | ||
| Where("try_count > ?", tryCount).Update() | ||
| if err != nil { | ||
| repo.logger.Errorw("error in ScanToolExecutionHistoryMappingRepository, MarkAllRunningStateAsFailedHavingTryCountReachedLimit", "err", err) | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) GetAllScanHistoriesByState(state serverBean.ScanExecutionProcessState) ([]*ScanToolExecutionHistoryMapping, error) { | ||
| var models []*ScanToolExecutionHistoryMapping | ||
| err := repo.dbConnection.Model(&models).Column("scan_tool_execution_history_mapping.*"). | ||
| Where("state = ?", state).Select() | ||
| if err != nil { | ||
| repo.logger.Errorw("error in ScanToolExecutionHistoryMappingRepository, GetAllScanHistoriesByState", "err", err) | ||
| return nil, err | ||
| } | ||
| return models, nil | ||
| } | ||
|
|
||
| func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) GetAllScanHistoriesByExecutionHistoryIdAndStates(executionHistoryId int, states []serverBean.ScanExecutionProcessState) ([]*ScanToolExecutionHistoryMapping, error) { | ||
| var models []*ScanToolExecutionHistoryMapping | ||
| err := repo.dbConnection.Model(&models).Column("scan_tool_execution_history_mapping.*"). | ||
| Where("image_scan_execution_history_id = ?", executionHistoryId). | ||
| Where("state in (?)", pg.In(states)).Select() | ||
| if err != nil { | ||
| repo.logger.Errorw("error in ScanToolExecutionHistoryMappingRepository, GetAllScanHistoriesByState", "err", err) | ||
| return nil, err | ||
| } | ||
| return models, nil | ||
| } | ||
| func (repo *ScanToolExecutionHistoryMappingRepositoryImpl) GetAllScanHistoriesByExecutionHistoryIds(ids []int) ([]*ScanToolExecutionHistoryMapping, error) { | ||
| var models []*ScanToolExecutionHistoryMapping | ||
| err := repo.dbConnection.Model(&models).Column("scan_tool_execution_history_mapping.*"). | ||
| Where("image_scan_execution_history_id = ?", pg.In(ids)). | ||
| Select() | ||
| if err != nil { | ||
| repo.logger.Errorw("error in getting ScanToolExecutionHistoryMappingRepository, GetAllScanHistoriesByState", "err", err) | ||
| return nil, err | ||
| } | ||
| return models, nil | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.