Add repo purge callbacks and register TUF metadata deletion as one

This commit is contained in:
Evan Cordell 2017-04-12 15:47:24 -04:00
parent 883692345b
commit ec63e495fc
5 changed files with 23 additions and 4 deletions

2
app.py
View file

@ -210,6 +210,8 @@ database.configure(app.config)
model.config.app_config = app.config
model.config.store = storage
model.config.register_image_cleanup_callback(secscan_api.cleanup_layers)
model.config.register_repo_cleanup_callback(tuf_metadata_api.delete_metadata)
@login_manager.user_loader
def load_user(user_uuid):

View file

@ -111,10 +111,14 @@ class Config(object):
self.app_config = None
self.store = None
self.image_cleanup_callbacks = []
self.repo_cleanup_callbacks = []
def register_image_cleanup_callback(self, callback):
self.image_cleanup_callbacks.append(callback)
def register_repo_cleanup_callback(self, callback):
self.repo_cleanup_callbacks.append(callback)
config = Config()

View file

@ -106,6 +106,10 @@ def purge_repository(namespace_name, repository_name):
fetched.delete_instance(recursive=True, delete_nullable=False)
# Run callbacks
for callback in config.repo_cleanup_callbacks:
callback(namespace_name, repository_name)
return True

View file

@ -420,9 +420,6 @@ class Repository(RepositoryParamResource):
# Remove any builds from the queue.
dockerfile_build_queue.delete_namespaced_items(namespace, repository)
if features.SIGNING:
tuf_metadata_api.delete_metadata(namespace, repository)
log_action('delete_repo', namespace,
{'repo': repository, 'namespace': namespace})
return '', 204

View file

@ -1,11 +1,14 @@
import pytest
import requests
from mock import mock
from mock import mock,patch
from flask import Flask
from test import testconfig
from test.fixtures import init_db_path
from util.tufmetadata import api
from data import model
valid_response = {
'signed' : {
@ -121,3 +124,12 @@ def test_delete_metadata_exception(response_code, exception):
tuf_api = api.TUFMetadataAPI(app, app.config, client=client)
response = tuf_api.delete_metadata('quay', 'quay')
assert response == False
def test_purge_repo(init_db_path):
app = Flask(__name__)
app.config.from_object(testconfig.TestConfig())
app.config["DB_URI"] = init_db_path
with patch('app.tuf_metadata_api') as mock_tuf:
model.repository.purge_repository("ns", "repo")
assert mock_tuf.delete_metadata.called_with("ns", "repo")