2017-06-02 15:30:51 -07:00
|
|
|
import features
|
|
|
|
|
2018-06-05 17:31:11 -04:00
|
|
|
from flask import jsonify
|
2015-09-29 15:53:38 -04:00
|
|
|
|
2018-01-05 16:27:03 -05:00
|
|
|
from auth.auth_context import get_authenticated_user
|
|
|
|
from auth.registry_jwt_auth import process_registry_jwt_auth
|
2015-09-29 15:53:38 -04:00
|
|
|
from endpoints.decorators import anon_protect
|
2016-08-01 20:48:00 -04:00
|
|
|
from endpoints.v2 import v2_bp, paginate
|
2017-06-26 18:10:39 -04:00
|
|
|
from endpoints.v2.models_pre_oci import data_model as model
|
2015-09-29 15:53:38 -04:00
|
|
|
|
2017-06-26 18:16:15 -04:00
|
|
|
|
2015-09-29 15:53:38 -04:00
|
|
|
@v2_bp.route('/_catalog', methods=['GET'])
|
2016-03-09 18:09:20 -05:00
|
|
|
@process_registry_jwt_auth()
|
2015-09-29 15:53:38 -04:00
|
|
|
@anon_protect
|
2016-08-01 20:48:00 -04:00
|
|
|
@paginate()
|
2016-07-26 18:41:51 -04:00
|
|
|
def catalog_search(limit, offset, pagination_callback):
|
2017-06-02 15:30:51 -07:00
|
|
|
include_public = bool(features.PUBLIC_CATALOG)
|
2018-06-05 17:31:00 -04:00
|
|
|
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': []})
|
|
|
|
|
2017-06-26 18:16:15 -04:00
|
|
|
visible_repositories = model.get_visible_repositories(username, limit + 1, offset,
|
2017-06-02 15:30:51 -07:00
|
|
|
include_public=include_public)
|
2015-09-29 15:53:38 -04:00
|
|
|
response = jsonify({
|
2016-07-26 18:41:51 -04:00
|
|
|
'repositories': ['%s/%s' % (repo.namespace_name, repo.name)
|
2017-06-26 18:16:15 -04:00
|
|
|
for repo in visible_repositories][0:limit],})
|
2015-09-29 15:53:38 -04:00
|
|
|
|
2016-07-26 18:41:51 -04:00
|
|
|
pagination_callback(len(visible_repositories), response)
|
2015-09-29 15:53:38 -04:00
|
|
|
return response
|