Merge pull request #2803 from coreos-inc/joseph.schorr/QUAY-627/signing-data-interface
Change signing API to use a data model interface
This commit is contained in:
commit
009ca829e8
3 changed files with 34 additions and 3 deletions
|
@ -4,10 +4,10 @@ import logging
|
|||
import features
|
||||
|
||||
from app import tuf_metadata_api
|
||||
from data import model
|
||||
from endpoints.api import (require_repo_read, path_param,
|
||||
RepositoryParamResource, resource, nickname, show_if,
|
||||
disallow_for_app_repositories, NotFound)
|
||||
from endpoints.api.signing_models_pre_oci import pre_oci_model as model
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -23,8 +23,7 @@ class RepositorySignatures(RepositoryParamResource):
|
|||
@disallow_for_app_repositories
|
||||
def get(self, namespace, repository):
|
||||
""" Fetches the list of signed tags for the repository. """
|
||||
repo = model.repository.get_repository(namespace, repository)
|
||||
if repo is None or not repo.trust_enabled:
|
||||
if not model.is_trust_enabled(namespace, repository):
|
||||
raise NotFound()
|
||||
|
||||
return {'delegations': tuf_metadata_api.get_all_tags_with_expiration(namespace, repository)}
|
||||
|
|
14
endpoints/api/signing_models_interface.py
Normal file
14
endpoints/api/signing_models_interface.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
from six import add_metaclass
|
||||
|
||||
@add_metaclass(ABCMeta)
|
||||
class SigningInterface(object):
|
||||
"""
|
||||
Interface that represents all data store interactions required by the signing API endpoint.
|
||||
"""
|
||||
@abstractmethod
|
||||
def is_trust_enabled(self, namespace_name, repo_name):
|
||||
"""
|
||||
Returns whether the repository with the given namespace name and repository name exists and
|
||||
has trust enabled.
|
||||
"""
|
18
endpoints/api/signing_models_pre_oci.py
Normal file
18
endpoints/api/signing_models_pre_oci.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
from data import model
|
||||
from endpoints.api.signing_models_interface import SigningInterface
|
||||
|
||||
|
||||
class PreOCIModel(SigningInterface):
|
||||
"""
|
||||
PreOCIModel implements the data model for signing using a database schema
|
||||
before it was changed to support the OCI specification.
|
||||
"""
|
||||
def is_trust_enabled(self, namespace_name, repo_name):
|
||||
repo = model.repository.get_repository(namespace_name, repo_name)
|
||||
if repo is None:
|
||||
return False
|
||||
|
||||
return repo.trust_enabled
|
||||
|
||||
|
||||
pre_oci_model = PreOCIModel()
|
Reference in a new issue