Skip to content

Commit 391cedb

Browse files
committed
[a] Add support for POST to manifest endpoint (#5918)
1 parent c0d7449 commit 391cedb

File tree

4 files changed

+2868
-136
lines changed

4 files changed

+2868
-136
lines changed

lambdas/service/app.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
# changes and reset the minor version to zero. Otherwise, increment only
229229
# the minor version for backwards compatible changes. A backwards
230230
# compatible change is one that does not require updates to clients.
231-
'version': '4.0'
231+
'version': '4.1'
232232
},
233233
'tags': [
234234
{
@@ -1273,14 +1273,15 @@ def get_summary():
12731273
authentication=request.authentication)
12741274

12751275

1276-
def manifest_route(*, fetch: bool, initiate: bool):
1276+
def manifest_route(*, fetch: bool, method: str):
1277+
initiate = method in ['PUT', 'POST']
12771278
return app.route(
12781279
# The path parameter could be a token *or* an object key, but we don't
12791280
# want to complicate the API with this detail
12801281
('/fetch' if fetch else '')
12811282
+ ('/manifest/files' if initiate else '/manifest/files/{token}'),
12821283
# The initial PUT request is idempotent.
1283-
methods=['PUT' if initiate else 'GET'],
1284+
methods=[method],
12841285
content_types=['application/json', 'application/x-www-form-urlencoded'],
12851286
interactive=fetch,
12861287
cors=True,
@@ -1301,17 +1302,17 @@ def manifest_route(*, fetch: bool, initiate: bool):
13011302
) + (
13021303
' via XHR' if fetch else ''
13031304
),
1304-
'description': fd('''
1305+
'description': fd(f'''
13051306
Create a manifest preparation job, returning either
13061307
13071308
- a 301 redirect to the URL of the status of that job or
13081309
13091310
- a 302 redirect to the URL of an already prepared manifest.
13101311
13111312
This endpoint is not suitable for interactive use via the
1312-
Swagger UI. Please use [PUT /fetch/manifest/files][1] instead.
1313+
Swagger UI. Please use [{method} /fetch/manifest/files][1] instead.
13131314
1314-
[1]: #operations-Manifests-put_fetch_manifest_files
1315+
[1]: #operations-Manifests-{method.lower()}_fetch_manifest_files
13151316
''') + parameter_hoisting_note if initiate and not fetch else fd('''
13161317
Check on the status of an ongoing manifest preparation job,
13171318
returning either
@@ -1326,15 +1327,15 @@ def manifest_route(*, fetch: bool, initiate: bool):
13261327
instead.
13271328
13281329
[1]: #operations-Manifests-get_fetch_manifest_files__token_
1329-
''') if not initiate and not fetch else fd('''
1330+
''') if not initiate and not fetch else fd(f'''
13301331
Create a manifest preparation job, returning a 200 status
13311332
response whose JSON body emulates the HTTP headers that would be
1332-
found in a response to an equivalent request to the [PUT
1333+
found in a response to an equivalent request to the [{method}
13331334
/manifest/files][1] endpoint.
13341335
13351336
Whenever client-side JavaScript code is used in a web
13361337
application to request the preparation of a manifest from Azul,
1337-
this endpoint should be used instead of [PUT
1338+
this endpoint should be used instead of [{method}
13381339
/manifest/files][1]. This way, the client can use XHR to make
13391340
the request, retaining full control over the handling of
13401341
redirects and enabling the client to bypass certain limitations
@@ -1344,7 +1345,7 @@ def manifest_route(*, fetch: bool, initiate: bool):
13441345
upper limit on the number of consecutive redirects, before the
13451346
manifest generation job is done.
13461347
1347-
[1]: #operations-Manifests-put_manifest_files
1348+
[1]: #operations-Manifests-{method.lower()}_manifest_files
13481349
''') + parameter_hoisting_note if initiate and fetch else fd('''
13491350
Check on the status of an ongoing manifest preparation job,
13501351
returning a 200 status response whose JSON body emulates the
@@ -1479,10 +1480,10 @@ def manifest_route(*, fetch: bool, initiate: bool):
14791480
14801481
For a detailed description of these properties see the
14811482
documentation for the respective response headers
1482-
documented under ''') + (fd('''
1483-
[PUT /manifest/files][1].
1483+
documented under ''') + (fd(f'''
1484+
[{method} /manifest/files][1].
14841485
1485-
[1]: #operations-Manifests-put_manifest_files
1486+
[1]: #operations-Manifests-{method.lower()}_manifest_files
14861487
''') if initiate else fd('''
14871488
[GET /manifest/files/{token}][1].
14881489
@@ -1524,28 +1525,32 @@ def manifest_route(*, fetch: bool, initiate: bool):
15241525
)
15251526

15261527

1527-
@manifest_route(fetch=False, initiate=True)
1528+
@manifest_route(fetch=False, method='PUT')
1529+
@manifest_route(fetch=False, method='POST')
15281530
def file_manifest():
15291531
return _file_manifest(fetch=False)
15301532

15311533

1532-
@manifest_route(fetch=False, initiate=False)
1534+
@manifest_route(fetch=False, method='GET')
15331535
def file_manifest_with_token(token: str):
15341536
return _file_manifest(fetch=False, token_or_key=token)
15351537

15361538

1537-
@manifest_route(fetch=True, initiate=True)
1539+
@manifest_route(fetch=True, method='PUT')
1540+
@manifest_route(fetch=True, method='POST')
15381541
def fetch_file_manifest():
15391542
return _file_manifest(fetch=True)
15401543

15411544

1542-
@manifest_route(fetch=True, initiate=False)
1545+
@manifest_route(fetch=True, method='GET')
15431546
def fetch_file_manifest_with_token(token: str):
15441547
return _file_manifest(fetch=True, token_or_key=token)
15451548

15461549

15471550
def _file_manifest(fetch: bool, token_or_key: Optional[str] = None):
15481551
request = app.current_request
1552+
require(request.method != 'POST' or request.raw_body.decode() == '',
1553+
'The body must be empty for a POST request to this endpoint.')
15491554
query_params = request.query_params or {}
15501555
_hoist_parameters(query_params, request)
15511556
if token_or_key is None:

0 commit comments

Comments
 (0)