From 80435d9c0b8aff6393c4061a0881d0e70cc8b3e0 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 22 Aug 2014 19:41:22 -0400 Subject: [PATCH] Add support for docker search, now that auth is fixed --- endpoints/index.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/endpoints/index.py b/endpoints/index.py index 39327e6a8..bf37e14b5 100644 --- a/endpoints/index.py +++ b/endpoints/index.py @@ -413,8 +413,35 @@ def put_repository_auth(namespace, repository): @index.route('/search', methods=['GET']) +@process_auth def get_search(): - abort(501, 'Not Implemented', issue='not-implemented') + def result_view(repo): + return { + "name": repo.namespace + '/' + repo.name, + "description": repo.description + } + + query = request.args.get('q') + + username = None + user = get_authenticated_user() + if user is not None: + username = user.username + + matching = model.get_matching_repositories(query, username) + results = [result_view(repo) for repo in matching + if (repo.visibility.name == 'public' or + ReadRepositoryPermission(repo.namespace, repo.name).can())] + + data = { + "query": query, + "num_results": len(results), + "results" : results + } + + resp = make_response(json.dumps(data), 200) + resp.mimetype = 'application/json' + return resp @index.route('/_ping')