6
6
"errors"
7
7
"fmt"
8
8
"net/url"
9
+ "strconv"
9
10
"strings"
10
11
"time"
11
12
@@ -63,6 +64,8 @@ func getAPScanURL(config config.IConfig) *url.URL {
63
64
}
64
65
}
65
66
67
+ const noImagesToScanError = "no images to scan"
68
+
66
69
func getVulnScanURL (config config.IConfig ) * url.URL {
67
70
return & url.URL {
68
71
Scheme : "http" ,
@@ -184,6 +187,10 @@ func (actionHandler *ActionHandler) scanRegistriesV2AndUpdateStatus(ctx context.
184
187
185
188
err = actionHandler .scanRegistriesV2 (ctx , sessionObj , imageRegistry )
186
189
if err != nil {
190
+ if err .Error () == noImagesToScanError { // nothing to scan
191
+ actionHandler .exporter .SendRegistryStatus (imageRegistry .GetBase ().GUID , apitypes .Completed , "" , scanTime )
192
+ return nil
193
+ }
187
194
actionHandler .exporter .SendRegistryStatus (imageRegistry .GetBase ().GUID , apitypes .Failed , err .Error (), scanTime )
188
195
return err
189
196
}
@@ -205,6 +212,8 @@ func (actionHandler *ActionHandler) scanRegistriesV2(ctx context.Context, sessio
205
212
images , err := client .GetImagesToScan (ctx )
206
213
if err != nil {
207
214
return fmt .Errorf ("failed to get registry images to scan with err %v" , err )
215
+ } else if len (images ) == 0 {
216
+ return errors .New (noImagesToScanError )
208
217
}
209
218
210
219
registryScanCMDList , err := actionHandler .getRegistryImageScanCommands (sessionObj , client , imageRegistry , images )
@@ -253,7 +262,8 @@ func (actionHandler *ActionHandler) loadRegistryFromSessionObj(sessionObj *utils
253
262
254
263
func (actionHandler * ActionHandler ) getRegistryImageScanCommands (sessionObj * utils.SessionObj , client interfaces.RegistryClient , imageRegistry apitypes.ContainerImageRegistry , images map [string ]string ) ([]* apis.RegistryScanCommand , error ) {
255
264
scanID := uuid .NewString ()
256
- registryScanCMDList := make ([]* apis.RegistryScanCommand , 0 , len (images ))
265
+ imagesCount := len (images )
266
+ registryScanCMDList := make ([]* apis.RegistryScanCommand , 0 , imagesCount )
257
267
for image , tag := range images {
258
268
repository := image
259
269
parts := strings .SplitN (image , "/" , 2 )
@@ -266,14 +276,15 @@ func (actionHandler *ActionHandler) getRegistryImageScanCommands(sessionObj *uti
266
276
ImageTag : image + ":" + tag ,
267
277
Session : apis.SessionChain {ActionTitle : "vulnerability-scan" , JobIDs : make ([]string , 0 ), Timestamp : sessionObj .Reporter .GetTimestamp ()},
268
278
Args : map [string ]interface {}{
269
- identifiers .AttributeRegistryName : imageRegistry .GetDisplayName (),
270
- identifiers .AttributeRepository : repository ,
271
- identifiers .AttributeTag : tag ,
272
- identifiers .AttributeUseHTTP : false ,
273
- identifiers .AttributeSkipTLSVerify : false ,
274
- identifiers .AttributeSensor : imageRegistry .GetBase ().ClusterName ,
275
- identifiers .AttributeRegistryID : imageRegistry .GetBase ().GUID ,
276
- identifiers .AttributeRegistryScanID : scanID ,
279
+ identifiers .AttributeRegistryName : imageRegistry .GetDisplayName (),
280
+ identifiers .AttributeRepository : repository ,
281
+ identifiers .AttributeTag : tag ,
282
+ identifiers .AttributeUseHTTP : false ,
283
+ identifiers .AttributeSkipTLSVerify : false ,
284
+ identifiers .AttributeSensor : imageRegistry .GetBase ().ClusterName ,
285
+ identifiers .AttributeRegistryID : imageRegistry .GetBase ().GUID ,
286
+ identifiers .AttributeRegistryScanID : scanID ,
287
+ identifiers .AttributeRegistryScanImagesCount : strconv .Itoa (imagesCount ),
277
288
},
278
289
}
279
290
auth , err := client .GetDockerAuth ()
0 commit comments