@@ -23,6 +23,7 @@ import (
23
23
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning"
24
24
securityBean "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/bean"
25
25
security2 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/repository"
26
+ "github.com/devtron-labs/devtron/util/sliceUtil"
26
27
"net/http"
27
28
"strconv"
28
29
@@ -104,6 +105,45 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
104
105
return
105
106
}
106
107
token := r .Header .Get ("token" )
108
+ isSuperAdmin := false
109
+ if ok := impl .enforcer .Enforce (token , casbin .ResourceGlobal , casbin .ActionGet , "*" ); ok {
110
+ isSuperAdmin = true
111
+ }
112
+ var ids []int
113
+ if isSuperAdmin {
114
+ ids = sliceUtil .NewSliceFromFuncExec (filteredDeployInfoList , func (item * security2.ImageScanDeployInfo ) int {
115
+ return item .Id
116
+ })
117
+ } else {
118
+ ids , err = impl .getAuthorisedImageScanDeployInfoIds (token , filteredDeployInfoList )
119
+ if err != nil {
120
+ impl .logger .Errorw ("error in getting authorised image scan deploy info ids" , "err" , err )
121
+ common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
122
+ return
123
+ }
124
+ }
125
+
126
+ if len (ids ) == 0 {
127
+ responseList := make ([]* securityBean.ImageScanHistoryResponse , 0 )
128
+ common .WriteJsonResp (w , nil , & securityBean.ImageScanHistoryListingResponse {ImageScanHistoryResponse : responseList }, http .StatusOK )
129
+ return
130
+ }
131
+
132
+ results , err := impl .imageScanService .FetchScanExecutionListing (request , ids )
133
+ if err != nil {
134
+ impl .logger .Errorw ("service err, ScanExecutionList" , "err" , err , "payload" , request )
135
+ if util .IsErrNoRows (err ) {
136
+ responseList := make ([]* securityBean.ImageScanHistoryResponse , 0 )
137
+ common .WriteJsonResp (w , nil , & securityBean.ImageScanHistoryListingResponse {ImageScanHistoryResponse : responseList }, http .StatusOK )
138
+ } else {
139
+ common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
140
+ }
141
+ return
142
+ }
143
+ common .WriteJsonResp (w , err , results , http .StatusOK )
144
+ }
145
+
146
+ func (impl ImageScanRestHandlerImpl ) getAuthorisedImageScanDeployInfoIds (token string , filteredDeployInfoList []* security2.ImageScanDeployInfo ) ([]int , error ) {
107
147
var ids []int
108
148
var appRBACObjects []string
109
149
var envRBACObjects []string
@@ -119,8 +159,8 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
119
159
120
160
appObjects , envObjects , appIdtoApp , envIdToEnv , err := impl .enforcerUtil .GetAppAndEnvRBACNamesByAppAndEnvIds (IdToAppEnvPairs )
121
161
if err != nil {
122
- common . WriteJsonResp ( w , err , nil , http . StatusInternalServerError )
123
- return
162
+ impl . logger . Errorw ( "error in getting app and env rbac objects" , " err" , err )
163
+ return nil , err
124
164
}
125
165
126
166
for _ , item := range filteredDeployInfoList {
@@ -136,8 +176,8 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
136
176
} else if item .ScanObjectMetaId > 0 && (item .ObjectType == ObjectTypePod ) {
137
177
environments , err := impl .environmentService .GetByClusterId (item .ClusterId )
138
178
if err != nil {
139
- common . WriteJsonResp ( w , err , nil , http . StatusInternalServerError )
140
- return
179
+ impl . logger . Errorw ( "error in getting environments for cluster" , "clusterId" , item . ClusterId , "err" , err )
180
+ return nil , err
141
181
}
142
182
for _ , environment := range environments {
143
183
podObject := environment .EnvironmentIdentifier
@@ -163,25 +203,7 @@ func (impl ImageScanRestHandlerImpl) ScanExecutionList(w http.ResponseWriter, r
163
203
}
164
204
}
165
205
}
166
-
167
- if ids == nil || len (ids ) == 0 {
168
- responseList := make ([]* securityBean.ImageScanHistoryResponse , 0 )
169
- common .WriteJsonResp (w , nil , & securityBean.ImageScanHistoryListingResponse {ImageScanHistoryResponse : responseList }, http .StatusOK )
170
- return
171
- }
172
-
173
- results , err := impl .imageScanService .FetchScanExecutionListing (request , ids )
174
- if err != nil {
175
- impl .logger .Errorw ("service err, ScanExecutionList" , "err" , err , "payload" , request )
176
- if util .IsErrNoRows (err ) {
177
- responseList := make ([]* securityBean.ImageScanHistoryResponse , 0 )
178
- common .WriteJsonResp (w , nil , & securityBean.ImageScanHistoryListingResponse {ImageScanHistoryResponse : responseList }, http .StatusOK )
179
- } else {
180
- common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
181
- }
182
- return
183
- }
184
- common .WriteJsonResp (w , err , results , http .StatusOK )
206
+ return ids , nil
185
207
}
186
208
187
209
func (impl ImageScanRestHandlerImpl ) FetchExecutionDetail (w http.ResponseWriter , r * http.Request ) {
0 commit comments