-
Notifications
You must be signed in to change notification settings - Fork 468
/
ImageScanResultRepository.go
130 lines (113 loc) · 5.27 KB
/
ImageScanResultRepository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright (c) 2020 Devtron Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package security
import (
"github.com/go-pg/pg"
"go.uber.org/zap"
)
type ImageScanExecutionResult struct {
tableName struct{} `sql:"image_scan_execution_result" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
CveStoreName string `sql:"cve_store_name,notnull"`
ImageScanExecutionHistoryId int `sql:"image_scan_execution_history_id"`
ScanToolId int `sql:"scan_tool_id"`
CveStore CveStore
ImageScanExecutionHistory ImageScanExecutionHistory
}
type ImageScanResultRepository interface {
Save(model *ImageScanExecutionResult) error
FindAll() ([]*ImageScanExecutionResult, error)
FindOne(id int) (*ImageScanExecutionResult, error)
FindByCveName(name string) ([]*ImageScanExecutionResult, error)
Update(model *ImageScanExecutionResult) error
FetchByScanExecutionId(id int) ([]*ImageScanExecutionResult, error)
FetchByScanExecutionIds(ids []int) ([]*ImageScanExecutionResult, error)
FindByImageDigest(imageDigest string) ([]*ImageScanExecutionResult, error)
FindByImageDigests(digest []string) ([]*ImageScanExecutionResult, error)
FindByImage(image string) ([]*ImageScanExecutionResult, error)
}
type ImageScanResultRepositoryImpl struct {
dbConnection *pg.DB
logger *zap.SugaredLogger
}
func NewImageScanResultRepositoryImpl(dbConnection *pg.DB, logger *zap.SugaredLogger) *ImageScanResultRepositoryImpl {
return &ImageScanResultRepositoryImpl{
dbConnection: dbConnection,
logger: logger,
}
}
func (impl ImageScanResultRepositoryImpl) Save(model *ImageScanExecutionResult) error {
err := impl.dbConnection.Insert(model)
return err
}
func (impl ImageScanResultRepositoryImpl) FindAll() ([]*ImageScanExecutionResult, error) {
var models []*ImageScanExecutionResult
err := impl.dbConnection.Model(&models).Select()
return models, err
}
func (impl ImageScanResultRepositoryImpl) FindOne(id int) (*ImageScanExecutionResult, error) {
var model *ImageScanExecutionResult
err := impl.dbConnection.Model(&model).
Where("id = ?", id).Select()
return model, err
}
func (impl ImageScanResultRepositoryImpl) FindByCveName(name string) ([]*ImageScanExecutionResult, error) {
var model []*ImageScanExecutionResult
err := impl.dbConnection.Model(&model).
Where("cve_store_name = ?", name).Select()
return model, err
}
func (impl ImageScanResultRepositoryImpl) Update(team *ImageScanExecutionResult) error {
err := impl.dbConnection.Update(team)
return err
}
func (impl ImageScanResultRepositoryImpl) FetchByScanExecutionId(scanExecutionId int) ([]*ImageScanExecutionResult, error) {
var models []*ImageScanExecutionResult
/*err := impl.dbConnection.Model(&models).Column("image_scan_execution_result.*", "cs.*").
Join("inner join cve_store cs on cs.name=image_scan_execution_result.cve_name").
Where("image_scan_execution_result.scan_execution_id = ?", id).Select()
*/
err := impl.dbConnection.Model(&models).Column("image_scan_execution_result.*", "CveStore").
Where("image_scan_execution_result.image_scan_execution_history_id = ?", scanExecutionId).
Select()
return models, err
}
func (impl ImageScanResultRepositoryImpl) FetchByScanExecutionIds(ids []int) ([]*ImageScanExecutionResult, error) {
var models []*ImageScanExecutionResult
err := impl.dbConnection.Model(&models).Column("image_scan_execution_result.*", "ImageScanExecutionHistory", "CveStore").
Where("image_scan_execution_result.image_scan_execution_history_id in(?)", pg.In(ids)).
Select()
return models, err
}
func (impl ImageScanResultRepositoryImpl) FindByImageDigest(imageDigest string) ([]*ImageScanExecutionResult, error) {
var model []*ImageScanExecutionResult
err := impl.dbConnection.Model(&model).Column("image_scan_execution_result.*", "ImageScanExecutionHistory", "CveStore").
Where("image_scan_execution_history.image_hash = ?", imageDigest).Order("image_scan_execution_history.execution_time desc").Select()
return model, err
}
func (impl ImageScanResultRepositoryImpl) FindByImageDigests(digest []string) ([]*ImageScanExecutionResult, error) {
var models []*ImageScanExecutionResult
err := impl.dbConnection.Model(&models).Column("image_scan_execution_result.*", "ImageScanExecutionHistory", "CveStore").
Where("image_hash in (?)", pg.In(digest)).Order("execution_time desc").Select()
return models, err
}
func (impl ImageScanResultRepositoryImpl) FindByImage(image string) ([]*ImageScanExecutionResult, error) {
var model []*ImageScanExecutionResult
err := impl.dbConnection.Model(&model).Column("image_scan_execution_result.*", "ImageScanExecutionHistory", "CveStore").
Where("image_scan_execution_history.image = ?", image).Order("image_scan_execution_history.execution_time desc").Select()
return model, err
}