Skip to content

Commit

Permalink
[a] Add support for POST to manifest endpoint (#5918)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsotirho-ucsc committed Apr 4, 2024
1 parent 754553b commit ff39020
Show file tree
Hide file tree
Showing 4 changed files with 2,870 additions and 136 deletions.
39 changes: 22 additions & 17 deletions lambdas/service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
# changes and reset the minor version to zero. Otherwise, increment only
# the minor version for backwards compatible changes. A backwards
# compatible change is one that does not require updates to clients.
'version': '7.2'
'version': '7.3'
},
'tags': [
{
Expand Down Expand Up @@ -1273,14 +1273,15 @@ def get_summary():
authentication=request.authentication)


def manifest_route(*, fetch: bool, initiate: bool):
def manifest_route(*, fetch: bool, method: str):
initiate = method in {'PUT', 'POST'}
return app.route(
# The path parameter could be a token *or* an object key, but we don't
# want to complicate the API with this detail
('/fetch' if fetch else '')
+ ('/manifest/files' if initiate else '/manifest/files/{token}'),
# The initial PUT request is idempotent.
methods=['PUT' if initiate else 'GET'],
methods=[method],
content_types=['application/json', 'application/x-www-form-urlencoded'],
interactive=fetch,
cors=True,
Expand All @@ -1301,17 +1302,17 @@ def manifest_route(*, fetch: bool, initiate: bool):
) + (
' via XHR' if fetch else ''
),
'description': fd('''
'description': fd(f'''
Create a manifest preparation job, returning either
- a 301 redirect to the URL of the status of that job or
- a 302 redirect to the URL of an already prepared manifest.
This endpoint is not suitable for interactive use via the
Swagger UI. Please use [PUT /fetch/manifest/files][1] instead.
Swagger UI. Please use [{method} /fetch/manifest/files][1] instead.
[1]: #operations-Manifests-put_fetch_manifest_files
[1]: #operations-Manifests-{method.lower()}_fetch_manifest_files
''') + parameter_hoisting_note if initiate and not fetch else fd('''
Check on the status of an ongoing manifest preparation job,
returning either
Expand All @@ -1326,15 +1327,15 @@ def manifest_route(*, fetch: bool, initiate: bool):
instead.
[1]: #operations-Manifests-get_fetch_manifest_files__token_
''') if not initiate and not fetch else fd('''
''') if not initiate and not fetch else fd(f'''
Create a manifest preparation job, returning a 200 status
response whose JSON body emulates the HTTP headers that would be
found in a response to an equivalent request to the [PUT
found in a response to an equivalent request to the [{method}
/manifest/files][1] endpoint.
Whenever client-side JavaScript code is used in a web
application to request the preparation of a manifest from Azul,
this endpoint should be used instead of [PUT
this endpoint should be used instead of [{method}
/manifest/files][1]. This way, the client can use XHR to make
the request, retaining full control over the handling of
redirects and enabling the client to bypass certain limitations
Expand All @@ -1344,7 +1345,7 @@ def manifest_route(*, fetch: bool, initiate: bool):
upper limit on the number of consecutive redirects, before the
manifest generation job is done.
[1]: #operations-Manifests-put_manifest_files
[1]: #operations-Manifests-{method.lower()}_manifest_files
''') + parameter_hoisting_note if initiate and fetch else fd('''
Check on the status of an ongoing manifest preparation job,
returning a 200 status response whose JSON body emulates the
Expand Down Expand Up @@ -1485,10 +1486,10 @@ def manifest_route(*, fetch: bool, initiate: bool):
For a detailed description of these properties see the
documentation for the respective response headers
documented under ''') + (fd('''
[PUT /manifest/files][1].
documented under ''') + (fd(f'''
[{method} /manifest/files][1].
[1]: #operations-Manifests-put_manifest_files
[1]: #operations-Manifests-{method.lower()}_manifest_files
''') if initiate else fd('''
[GET /manifest/files/{token}][1].
Expand Down Expand Up @@ -1530,28 +1531,32 @@ def manifest_route(*, fetch: bool, initiate: bool):
)


@manifest_route(fetch=False, initiate=True)
@manifest_route(fetch=False, method='PUT')
@manifest_route(fetch=False, method='POST')
def file_manifest():
return _file_manifest(fetch=False)


@manifest_route(fetch=False, initiate=False)
@manifest_route(fetch=False, method='GET')
def file_manifest_with_token(token: str):
return _file_manifest(fetch=False, token_or_key=token)


@manifest_route(fetch=True, initiate=True)
@manifest_route(fetch=True, method='PUT')
@manifest_route(fetch=True, method='POST')
def fetch_file_manifest():
return _file_manifest(fetch=True)


@manifest_route(fetch=True, initiate=False)
@manifest_route(fetch=True, method='GET')
def fetch_file_manifest_with_token(token: str):
return _file_manifest(fetch=True, token_or_key=token)


def _file_manifest(fetch: bool, token_or_key: Optional[str] = None):
request = app.current_request
require(request.method != 'POST' or request.raw_body == b'',
'The body must be empty for a POST request to this endpoint.')
query_params = request.query_params or {}
_hoist_parameters(query_params, request)
if token_or_key is None:
Expand Down
Loading

0 comments on commit ff39020

Please sign in to comment.