Convert V2's catalog endpoint to use the new data model interface

This commit is contained in:
Joseph Schorr 2018-10-08 14:26:39 +01:00
parent e91ba98e1b
commit 3a8a913ad3
4 changed files with 17 additions and 641 deletions

View file

@ -1,15 +1,20 @@
import features
from collections import namedtuple
from flask import jsonify
import features
from app import model_cache
from auth.auth_context import get_authenticated_user, get_authenticated_context
from auth.registry_jwt_auth import process_registry_jwt_auth
from data import model
from data.cache import cache_key
from endpoints.decorators import anon_protect
from endpoints.v2 import v2_bp, paginate
from endpoints.v2.models_interface import Repository
from endpoints.v2.models_pre_oci import data_model as model
class Repository(namedtuple('Repository', ['id', 'namespace_name', 'name'])):
pass
@v2_bp.route('/_catalog', methods=['GET'])
@ -26,8 +31,15 @@ def catalog_search(start_id, limit, pagination_callback):
if username and not get_authenticated_user().enabled:
return []
repos = model.get_visible_repositories(username, start_id, limit, include_public=include_public)
return [repo._asdict() for repo in repos]
query = model.repository.get_visible_repositories(username,
kind_filter='image',
include_public=include_public,
start_id=start_id,
limit=limit + 1)
# NOTE: The repository ID is in `rid` (not `id`) here, as per the requirements of
# the `get_visible_repositories` call.
return [Repository(repo.rid, repo.namespace_user.username, repo.name)._asdict()
for repo in query]
context_key = get_authenticated_context().unique_key if get_authenticated_context() else None
catalog_cache_key = cache_key.for_catalog_page(context_key, start_id, limit)