1
0
mirror of https://github.com/quay/quay.git synced 2026-01-26 06:21:37 +03:00
Files
quay/endpoints/v2/catalog.py
Jordi Piriz 747d1694cd revert: tracing improving otlp handling (PROJQUAY-8902) (#4438)
Revert "tracing: improving otlp handling (PROJQUAY-8902) (#4198)"

This reverts commit 89e758846f.
2025-11-03 16:17:32 +01:00

74 lines
2.3 KiB
Python

from collections import namedtuple
from flask import jsonify
import features
from app import model_cache
from auth.auth_context import get_authenticated_context, get_authenticated_user
from auth.registry_jwt_auth import process_registry_jwt_auth
from data import model
from data.cache import cache_key
from endpoints.api import allow_if_any_superuser
from endpoints.decorators import (
anon_protect,
disallow_for_account_recovery_mode,
route_show_if,
)
from endpoints.v2 import paginate, v2_bp
class Repository(namedtuple("Repository", ["id", "namespace_name", "name"])):
pass
@v2_bp.route("/_catalog", methods=["GET"])
@disallow_for_account_recovery_mode
@process_registry_jwt_auth()
@anon_protect
@paginate()
def catalog_search(start_id, limit, pagination_callback):
def _load_catalog():
include_public = bool(features.PUBLIC_CATALOG)
if not include_public and not get_authenticated_user():
return []
username = get_authenticated_user().username if get_authenticated_user() else None
if username and not get_authenticated_user().enabled:
return []
query = model.repository.get_visible_repositories(
username,
kind_filter="image",
include_public=include_public,
start_id=start_id,
limit=limit + 1,
is_superuser=allow_if_any_superuser(),
return_all=True,
)
# 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, model_cache.cache_config
)
visible_repositories = [
Repository(**repo_dict)
for repo_dict in model_cache.retrieve(catalog_cache_key, _load_catalog)
]
response = jsonify(
{
"repositories": [
"%s/%s" % (repo.namespace_name, repo.name) for repo in visible_repositories
][0:limit],
}
)
pagination_callback(visible_repositories, response)
return response