Add support for Quay's vulnerability tool
This commit is contained in:
parent
3d0bcbaaeb
commit
f59e35cc81
11 changed files with 409 additions and 0 deletions
49
util/migrate/backfill_parent_id.py
Normal file
49
util/migrate/backfill_parent_id.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import logging
|
||||
from data.database import Image, ImageStorage, db
|
||||
from app import app
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def backfill_parent_id():
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
logger.debug('backfill_parent_id: Starting')
|
||||
logger.debug('backfill_parent_id: This can be a LONG RUNNING OPERATION. Please wait!')
|
||||
|
||||
# Check for any images without parent
|
||||
has_images = bool(list(Image
|
||||
.select(Image.id)
|
||||
.join(ImageStorage)
|
||||
.where(Image.parent >> None, Image.ancestors != '/', ImageStorage.uploading == False)
|
||||
.limit(1)))
|
||||
|
||||
if not has_images:
|
||||
logger.debug('backfill_parent_id: No migration needed')
|
||||
return
|
||||
|
||||
while True:
|
||||
# Load the record from the DB.
|
||||
batch_images_ids = list(Image
|
||||
.select(Image.id)
|
||||
.join(ImageStorage)
|
||||
.where(Image.parent >> None, Image.ancestors != '/', ImageStorage.uploading == False)
|
||||
.limit(100))
|
||||
|
||||
if len(batch_images_ids) == 0:
|
||||
logger.debug('backfill_parent_id: Completed')
|
||||
return
|
||||
|
||||
for image_id in batch_images_ids:
|
||||
with app.config['DB_TRANSACTION_FACTORY'](db):
|
||||
try:
|
||||
image = Image.select(Image.id, Image.ancestors).where(Image.id == image_id).get()
|
||||
image.parent = image.ancestors.split('/')[-2]
|
||||
image.save()
|
||||
except Image.DoesNotExist:
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.getLogger('peewee').setLevel(logging.CRITICAL)
|
||||
|
||||
backfill_parent_id()
|
Reference in a new issue