Merge pull request #917 from Quentin-M/fix_secwor
Fix security worker (again?)
This commit is contained in:
commit
04f2688944
2 changed files with 22 additions and 27 deletions
|
@ -468,13 +468,13 @@ def get_secscan_candidates(engine_version, batch_size):
|
|||
rimages = []
|
||||
|
||||
# Collect the images without parents
|
||||
candidates = (Image
|
||||
.select(Image.id)
|
||||
.join(ImageStorage)
|
||||
.where(Image.security_indexed_engine < engine_version,
|
||||
Image.parent >> None,
|
||||
ImageStorage.uploading == False)
|
||||
.limit(batch_size*10))
|
||||
candidates = list(Image
|
||||
.select(Image.id)
|
||||
.join(ImageStorage)
|
||||
.where(Image.security_indexed_engine < engine_version,
|
||||
Image.parent >> None,
|
||||
ImageStorage.uploading == False)
|
||||
.limit(batch_size*10))
|
||||
|
||||
images = (Image
|
||||
.select(Image, ImageStorage)
|
||||
|
@ -483,20 +483,19 @@ def get_secscan_candidates(engine_version, batch_size):
|
|||
.order_by(db_random_func())
|
||||
.limit(batch_size))
|
||||
|
||||
for image in images:
|
||||
rimages.append(image)
|
||||
rimages.extend(images)
|
||||
|
||||
# Collect the images with analyzed parents.
|
||||
candidates = (Image
|
||||
.select(Image.id)
|
||||
.join(Parent, on=(Image.parent == Parent.id))
|
||||
.switch(Image)
|
||||
.join(ImageStorage)
|
||||
.where(Image.security_indexed_engine < engine_version,
|
||||
Parent.security_indexed == True,
|
||||
Parent.security_indexed_engine >= engine_version,
|
||||
ImageStorage.uploading == False)
|
||||
.limit(batch_size*10))
|
||||
candidates = list(Image
|
||||
.select(Image.id)
|
||||
.join(Parent, on=(Image.parent == Parent.id))
|
||||
.switch(Image)
|
||||
.join(ImageStorage)
|
||||
.where(Image.security_indexed_engine < engine_version,
|
||||
Parent.security_indexed == True,
|
||||
Parent.security_indexed_engine >= engine_version,
|
||||
ImageStorage.uploading == False)
|
||||
.limit(batch_size*10))
|
||||
|
||||
images = (Image
|
||||
.select(Image, ImageStorage, Parent, ParentImageStorage)
|
||||
|
@ -508,8 +507,7 @@ def get_secscan_candidates(engine_version, batch_size):
|
|||
.order_by(db_random_func())
|
||||
.limit(batch_size))
|
||||
|
||||
for image in images:
|
||||
rimages.append(image)
|
||||
rimages.extend(images)
|
||||
|
||||
# Shuffle the images, otherwise the images without parents will always be on the top
|
||||
random.shuffle(rimages)
|
||||
|
|
|
@ -13,7 +13,7 @@ from data import model
|
|||
from data.model.tag import filter_tags_have_repository_event, get_tags_for_image
|
||||
from data.model.image import get_secscan_candidates, set_secscan_status
|
||||
from data.model.storage import get_storage_locations
|
||||
from data.database import (Image, UseThenDisconnect, ExternalNotificationEvent)
|
||||
from data.database import (UseThenDisconnect, ExternalNotificationEvent)
|
||||
from util.secscan.api import SecurityConfigValidator
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -154,11 +154,8 @@ class SecurityWorker(Worker):
|
|||
while True:
|
||||
# Lookup the images to index.
|
||||
images = []
|
||||
try:
|
||||
logger.debug('Looking up images to index')
|
||||
images = get_secscan_candidates(self._target_version, BATCH_SIZE)
|
||||
except Image.DoesNotExist:
|
||||
pass
|
||||
logger.debug('Looking up images to index')
|
||||
images = get_secscan_candidates(self._target_version, BATCH_SIZE)
|
||||
|
||||
if not images:
|
||||
logger.debug('No more images left to analyze')
|
||||
|
|
Reference in a new issue