yapf
This commit is contained in:
parent
1ddb09ac11
commit
27ed3bedcc
5 changed files with 9 additions and 7 deletions
|
@ -10,6 +10,7 @@ logger = logging.getLogger(__name__)
|
|||
unscanned_images_gauge = prometheus.create_gauge('unscanned_images',
|
||||
'Number of images that clair needs to scan.')
|
||||
|
||||
|
||||
def index_images(target_version, analyzer, token=None):
|
||||
""" Performs security indexing of all images in the database not scanned at the target version.
|
||||
If a token is provided, scanning will begin where the token indicates it previously completed.
|
||||
|
|
|
@ -3,6 +3,7 @@ from collections import namedtuple
|
|||
|
||||
from six import add_metaclass
|
||||
|
||||
|
||||
class ScanToken(namedtuple('NextScanToken', ['min_id'])):
|
||||
"""
|
||||
ScanToken represents an opaque token that can be passed between runs of the security worker
|
||||
|
@ -11,6 +12,7 @@ class ScanToken(namedtuple('NextScanToken', ['min_id'])):
|
|||
the token in any way.
|
||||
"""
|
||||
|
||||
|
||||
@add_metaclass(ABCMeta)
|
||||
class SecurityWorkerDataInterface(object):
|
||||
"""
|
||||
|
|
|
@ -5,10 +5,8 @@ from data.model.image import (get_images_eligible_for_scan, get_image_pk_field,
|
|||
get_max_id_for_sec_scan, get_min_id_for_sec_scan)
|
||||
from util.migrate.allocator import yield_random_entries
|
||||
|
||||
from workers.securityworker.models_interface import (
|
||||
ScanToken,
|
||||
SecurityWorkerDataInterface
|
||||
)
|
||||
from workers.securityworker.models_interface import (ScanToken, SecurityWorkerDataInterface)
|
||||
|
||||
|
||||
class PreOCIModel(SecurityWorkerDataInterface):
|
||||
def candidates_to_scan(self, target_version, start_token=None):
|
||||
|
@ -34,7 +32,7 @@ class PreOCIModel(SecurityWorkerDataInterface):
|
|||
return (None, None)
|
||||
|
||||
# 4^log10(total) gives us a scalable batch size into the billions.
|
||||
batch_size = int(4 ** log10(max(10, max_id - min_id)))
|
||||
batch_size = int(4**log10(max(10, max_id - min_id)))
|
||||
|
||||
# TODO: Once we have a clean shared NamedTuple for Images, send that to the secscan analyzer
|
||||
# rather than the database Image itself.
|
||||
|
@ -43,8 +41,7 @@ class PreOCIModel(SecurityWorkerDataInterface):
|
|||
get_image_pk_field(),
|
||||
batch_size,
|
||||
max_id,
|
||||
min_id,
|
||||
)
|
||||
min_id,)
|
||||
|
||||
return (iterator, ScanToken(max_id + 1))
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
DEFAULT_INDEXING_INTERVAL = 30
|
||||
|
||||
|
||||
class SecurityWorker(Worker):
|
||||
def __init__(self):
|
||||
super(SecurityWorker, self).__init__()
|
||||
|
|
|
@ -3,6 +3,7 @@ from mock import patch, Mock
|
|||
from test.fixtures import *
|
||||
from workers.securityworker import index_images
|
||||
|
||||
|
||||
def test_securityworker_realdb(initialized_db):
|
||||
mock_analyzer = Mock()
|
||||
assert index_images(1, mock_analyzer) is not None
|
||||
|
|
Reference in a new issue