3161b60522
Also adds a test for the tags endpoint
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
import features
|
|
|
|
from flask import jsonify
|
|
|
|
from auth.auth_context import get_authenticated_user
|
|
from auth.registry_jwt_auth import process_registry_jwt_auth
|
|
from endpoints.decorators import anon_protect
|
|
from endpoints.v2 import v2_bp, paginate
|
|
from endpoints.v2.models_pre_oci import data_model as model
|
|
|
|
|
|
@v2_bp.route('/_catalog', methods=['GET'])
|
|
@process_registry_jwt_auth()
|
|
@anon_protect
|
|
@paginate()
|
|
def catalog_search(start_id, limit, pagination_callback):
|
|
include_public = bool(features.PUBLIC_CATALOG)
|
|
if not include_public and not get_authenticated_user():
|
|
return jsonify({'repositories': []})
|
|
|
|
username = get_authenticated_user().username if get_authenticated_user() else None
|
|
if username and not get_authenticated_user().enabled:
|
|
return jsonify({'repositories': []})
|
|
|
|
visible_repositories = model.get_visible_repositories(username, start_id, limit,
|
|
include_public=include_public)
|
|
response = jsonify({
|
|
'repositories': ['%s/%s' % (repo.namespace_name, repo.name)
|
|
for repo in visible_repositories][0:limit],
|
|
})
|
|
|
|
pagination_callback(visible_repositories, response)
|
|
return response
|