From b3ec1967fa73f2caafc8e51bad674993cde132b0 Mon Sep 17 00:00:00 2001 From: Brian Scholer <1260690+briantist@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:13:48 -0400 Subject: [PATCH 1/3] fix iteration on missing local collections --- galactory/api/v2/collections.py | 32 +++++++++++++------------- galactory/api/v3/collections.py | 40 ++++++++++++++++----------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/galactory/api/v2/collections.py b/galactory/api/v2/collections.py index e6afe64..2111c31 100644 --- a/galactory/api/v2/collections.py +++ b/galactory/api/v2/collections.py @@ -178,23 +178,23 @@ def versions(namespace, collection): if len(collections) > 1: abort(C.HTTP_INTERNAL_SERVER_ERROR) - col = next(iter(collections.values())) vers = set() - for i in col.values(): - results.append( - { - 'href': url_for( - ".version", - namespace=i.namespace, - collection=i.name, - version=i.version, - _external=True, - _scheme=scheme, - ), - 'version': i.version, - } - ) - vers.add(i.version) + for col in collections.values(): + for i in col.values(): + results.append( + { + 'href': url_for( + ".version", + namespace=i.namespace, + collection=i.name, + version=i.version, + _external=True, + _scheme=scheme, + ), + 'version': i.version, + } + ) + vers.add(i.version) if upstream_result: for item in upstream_result['results']: diff --git a/galactory/api/v3/collections.py b/galactory/api/v3/collections.py index 524a717..83315ec 100644 --- a/galactory/api/v3/collections.py +++ b/galactory/api/v3/collections.py @@ -190,27 +190,27 @@ def versions(namespace, collection): if len(collections) > 1: abort(C.HTTP_INTERNAL_SERVER_ERROR) - col = next(iter(collections.values())) vers = set() - for i in col.values(): - results.append( - { - 'href': url_for( - ".version", - namespace=i.namespace, - collection=i.name, - version=i.version, - _external=False, - _scheme=scheme, - ), - 'version': i.version, - 'created_at': i.created, - 'updated_at': i.modified, - 'marks': [], - 'requires_ansible': None, # FIXME - } - ) - vers.add(i.version) + for col in collections.values(): + for i in col.values(): + results.append( + { + 'href': url_for( + ".version", + namespace=i.namespace, + collection=i.name, + version=i.version, + _external=False, + _scheme=scheme, + ), + 'version': i.version, + 'created_at': i.created, + 'updated_at': i.modified, + 'marks': [], + 'requires_ansible': None, # FIXME + } + ) + vers.add(i.version) if upstream_result: for item in upstream_result['data']: From 858fa66ed470f67683b592a435ea86464a650f2d Mon Sep 17 00:00:00 2001 From: Brian Scholer <1260690+briantist@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:14:14 -0400 Subject: [PATCH 2/3] fix upstream forced pagination --- galactory/upstream.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/galactory/upstream.py b/galactory/upstream.py index 2b6e1fe..3abd0a4 100644 --- a/galactory/upstream.py +++ b/galactory/upstream.py @@ -258,8 +258,10 @@ def _rewrite_to_upstream(self, request, upstream_url, *, prepared=True, no_rewri current_app.logger.info(f"Rewriting '{this_url}' to '{rewritten}'") params = request.args.copy() if not no_paginate: - # FIXME: use the correct parameter for the galaxy API version - params['page_size'] = params['limit'] = 100 + if 'v2' in this_url: + params['page_size'] = 100 + else: + params['limit'] = 100 headers = {k: v for k, v in request.headers.items() if k not in ['Authorization', 'Host']} headers['Accept'] = 'application/json, */*' From d476a4d3e5cfea80b774145c311f9ff6b236cea2 Mon Sep 17 00:00:00 2001 From: Brian Scholer <1260690+briantist@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:17:56 -0400 Subject: [PATCH 3/3] add changelog fragment --- changelogs/fragments/114-bugfixes.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelogs/fragments/114-bugfixes.yml diff --git a/changelogs/fragments/114-bugfixes.yml b/changelogs/fragments/114-bugfixes.yml new file mode 100644 index 0000000..07b31d8 --- /dev/null +++ b/changelogs/fragments/114-bugfixes.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - Requests for collections that were not already present in artifactory resulted in a 500 internal server error (https://github.com/briantist/galactory/issues/112). + - Requests proxied to a v2 upstream endpoint that supports pagination caused a 400 error from the upstream due to the inclusion of the v3 ``limit`` query string parameter (https://github.com/briantist/galactory/issues/113).