Add repo purge callbacks and register TUF metadata deletion as one
This commit is contained in:
parent
883692345b
commit
ec63e495fc
5 changed files with 23 additions and 4 deletions
2
app.py
2
app.py
|
@ -210,6 +210,8 @@ database.configure(app.config)
|
||||||
model.config.app_config = app.config
|
model.config.app_config = app.config
|
||||||
model.config.store = storage
|
model.config.store = storage
|
||||||
model.config.register_image_cleanup_callback(secscan_api.cleanup_layers)
|
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
|
@login_manager.user_loader
|
||||||
def load_user(user_uuid):
|
def load_user(user_uuid):
|
||||||
|
|
|
@ -111,10 +111,14 @@ class Config(object):
|
||||||
self.app_config = None
|
self.app_config = None
|
||||||
self.store = None
|
self.store = None
|
||||||
self.image_cleanup_callbacks = []
|
self.image_cleanup_callbacks = []
|
||||||
|
self.repo_cleanup_callbacks = []
|
||||||
|
|
||||||
def register_image_cleanup_callback(self, callback):
|
def register_image_cleanup_callback(self, callback):
|
||||||
self.image_cleanup_callbacks.append(callback)
|
self.image_cleanup_callbacks.append(callback)
|
||||||
|
|
||||||
|
def register_repo_cleanup_callback(self, callback):
|
||||||
|
self.repo_cleanup_callbacks.append(callback)
|
||||||
|
|
||||||
|
|
||||||
config = Config()
|
config = Config()
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,10 @@ def purge_repository(namespace_name, repository_name):
|
||||||
|
|
||||||
fetched.delete_instance(recursive=True, delete_nullable=False)
|
fetched.delete_instance(recursive=True, delete_nullable=False)
|
||||||
|
|
||||||
|
# Run callbacks
|
||||||
|
for callback in config.repo_cleanup_callbacks:
|
||||||
|
callback(namespace_name, repository_name)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -420,9 +420,6 @@ class Repository(RepositoryParamResource):
|
||||||
# Remove any builds from the queue.
|
# Remove any builds from the queue.
|
||||||
dockerfile_build_queue.delete_namespaced_items(namespace, repository)
|
dockerfile_build_queue.delete_namespaced_items(namespace, repository)
|
||||||
|
|
||||||
if features.SIGNING:
|
|
||||||
tuf_metadata_api.delete_metadata(namespace, repository)
|
|
||||||
|
|
||||||
log_action('delete_repo', namespace,
|
log_action('delete_repo', namespace,
|
||||||
{'repo': repository, 'namespace': namespace})
|
{'repo': repository, 'namespace': namespace})
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
from mock import mock
|
from mock import mock,patch
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
from test import testconfig
|
from test import testconfig
|
||||||
|
from test.fixtures import init_db_path
|
||||||
from util.tufmetadata import api
|
from util.tufmetadata import api
|
||||||
|
from data import model
|
||||||
|
|
||||||
|
|
||||||
valid_response = {
|
valid_response = {
|
||||||
'signed' : {
|
'signed' : {
|
||||||
|
@ -121,3 +124,12 @@ def test_delete_metadata_exception(response_code, exception):
|
||||||
tuf_api = api.TUFMetadataAPI(app, app.config, client=client)
|
tuf_api = api.TUFMetadataAPI(app, app.config, client=client)
|
||||||
response = tuf_api.delete_metadata('quay', 'quay')
|
response = tuf_api.delete_metadata('quay', 'quay')
|
||||||
assert response == False
|
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")
|
Reference in a new issue