Skip to content

Commit

Permalink
Fix post v0.11.0 bugs - 500 error on missing local collection, 400 …
Browse files Browse the repository at this point in the history
…error from proxied v2 paginated requests (#114)

* fix iteration on missing local collections

* fix upstream forced pagination

* add changelog fragment
  • Loading branch information
briantist authored Oct 9, 2023
1 parent 41fd9b0 commit d5822c6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/114-bugfixes.yml
Original file line number Diff line number Diff line change
@@ -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).
32 changes: 16 additions & 16 deletions galactory/api/v2/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
40 changes: 20 additions & 20 deletions galactory/api/v3/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
6 changes: 4 additions & 2 deletions galactory/upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, */*'
Expand Down

0 comments on commit d5822c6

Please sign in to comment.