Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/vault.py
Show All 35 Lines | elif request.method == "POST": | ||||
obj_type, | obj_type, | ||||
obj_id, | obj_id, | ||||
email, | email, | ||||
notfound_msg=("{} '{}' not found.".format(object_name.title(), hex_id)), | notfound_msg=("{} '{}' not found.".format(object_name.title(), hex_id)), | ||||
request=request, | request=request, | ||||
) | ) | ||||
@never_cache | |||||
@api_route( | @api_route( | ||||
r"/vault/directory/(?P<dir_id>[0-9a-f]+)/", | r"/vault/directory/(?P<dir_id>[0-9a-f]+)/", | ||||
"api-1-vault-cook-directory", | "api-1-vault-cook-directory", | ||||
methods=["GET", "POST"], | methods=["GET", "POST"], | ||||
checksum_args=["dir_id"], | checksum_args=["dir_id"], | ||||
throttle_scope="swh_vault_cooking", | throttle_scope="swh_vault_cooking", | ||||
) | ) | ||||
@never_cache | |||||
@api_doc("/vault/directory/") | @api_doc("/vault/directory/") | ||||
@format_docstring() | @format_docstring() | ||||
def api_vault_cook_directory(request, dir_id): | def api_vault_cook_directory(request, dir_id): | ||||
""" | """ | ||||
.. http:get:: /api/1/vault/directory/(dir_id)/ | .. http:get:: /api/1/vault/directory/(dir_id)/ | ||||
.. http:post:: /api/1/vault/directory/(dir_id)/ | .. http:post:: /api/1/vault/directory/(dir_id)/ | ||||
Request the cooking of an archive for a directory or check | Request the cooking of an archive for a directory or check | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | def api_vault_cook_directory(request, dir_id): | ||||
return res | return res | ||||
@api_route( | @api_route( | ||||
r"/vault/directory/(?P<dir_id>[0-9a-f]+)/raw/", | r"/vault/directory/(?P<dir_id>[0-9a-f]+)/raw/", | ||||
"api-1-vault-fetch-directory", | "api-1-vault-fetch-directory", | ||||
checksum_args=["dir_id"], | checksum_args=["dir_id"], | ||||
) | ) | ||||
@api_doc("/vault/directory/raw/", handle_response=True) | @api_doc("/vault/directory/raw/") | ||||
def api_vault_fetch_directory(request, dir_id): | def api_vault_fetch_directory(request, dir_id): | ||||
""" | """ | ||||
.. http:get:: /api/1/vault/directory/(dir_id)/raw/ | .. http:get:: /api/1/vault/directory/(dir_id)/raw/ | ||||
Fetch the cooked archive for a directory. | Fetch the cooked archive for a directory. | ||||
See :http:get:`/api/1/vault/directory/(dir_id)/` to get more | See :http:get:`/api/1/vault/directory/(dir_id)/` to get more | ||||
details on directory cooking. | details on directory cooking. | ||||
Show All 19 Lines | res = api_lookup( | ||||
request=request, | request=request, | ||||
) | ) | ||||
fname = "{}.tar.gz".format(dir_id) | fname = "{}.tar.gz".format(dir_id) | ||||
response = HttpResponse(res, content_type="application/gzip") | response = HttpResponse(res, content_type="application/gzip") | ||||
response["Content-disposition"] = "attachment; filename={}".format(fname) | response["Content-disposition"] = "attachment; filename={}".format(fname) | ||||
return response | return response | ||||
@never_cache | |||||
@api_route( | @api_route( | ||||
r"/vault/revision/(?P<rev_id>[0-9a-f]+)/gitfast/", | r"/vault/revision/(?P<rev_id>[0-9a-f]+)/gitfast/", | ||||
"api-1-vault-cook-revision_gitfast", | "api-1-vault-cook-revision_gitfast", | ||||
methods=["GET", "POST"], | methods=["GET", "POST"], | ||||
checksum_args=["rev_id"], | checksum_args=["rev_id"], | ||||
throttle_scope="swh_vault_cooking", | throttle_scope="swh_vault_cooking", | ||||
) | ) | ||||
@never_cache | |||||
@api_doc("/vault/revision/gitfast/") | @api_doc("/vault/revision/gitfast/") | ||||
@format_docstring() | @format_docstring() | ||||
def api_vault_cook_revision_gitfast(request, rev_id): | def api_vault_cook_revision_gitfast(request, rev_id): | ||||
""" | """ | ||||
.. http:get:: /api/1/vault/revision/(rev_id)/gitfast/ | .. http:get:: /api/1/vault/revision/(rev_id)/gitfast/ | ||||
.. http:post:: /api/1/vault/revision/(rev_id)/gitfast/ | .. http:post:: /api/1/vault/revision/(rev_id)/gitfast/ | ||||
Request the cooking of a gitfast archive for a revision or check | Request the cooking of a gitfast archive for a revision or check | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | def api_vault_cook_revision_gitfast(request, rev_id): | ||||
return res | return res | ||||
@api_route( | @api_route( | ||||
r"/vault/revision/(?P<rev_id>[0-9a-f]+)/gitfast/raw/", | r"/vault/revision/(?P<rev_id>[0-9a-f]+)/gitfast/raw/", | ||||
"api-1-vault-fetch-revision_gitfast", | "api-1-vault-fetch-revision_gitfast", | ||||
checksum_args=["rev_id"], | checksum_args=["rev_id"], | ||||
) | ) | ||||
@api_doc("/vault/revision/gitfast/raw/", handle_response=True) | @api_doc("/vault/revision/gitfast/raw/") | ||||
def api_vault_fetch_revision_gitfast(request, rev_id): | def api_vault_fetch_revision_gitfast(request, rev_id): | ||||
""" | """ | ||||
.. http:get:: /api/1/vault/revision/(rev_id)/gitfast/raw/ | .. http:get:: /api/1/vault/revision/(rev_id)/gitfast/raw/ | ||||
Fetch the cooked gitfast archive for a revision. | Fetch the cooked gitfast archive for a revision. | ||||
See :http:get:`/api/1/vault/revision/(rev_id)/gitfast/` to get more | See :http:get:`/api/1/vault/revision/(rev_id)/gitfast/` to get more | ||||
details on directory cooking. | details on directory cooking. | ||||
Show All 24 Lines | def api_vault_fetch_revision_gitfast(request, rev_id): | ||||
return response | return response | ||||
@api_route( | @api_route( | ||||
r"/vault/revision_gitfast/(?P<rev_id>[0-9a-f]+)/raw/", | r"/vault/revision_gitfast/(?P<rev_id>[0-9a-f]+)/raw/", | ||||
"api-1-vault-revision_gitfast-raw", | "api-1-vault-revision_gitfast-raw", | ||||
checksum_args=["rev_id"], | checksum_args=["rev_id"], | ||||
) | ) | ||||
@api_doc("/vault/revision_gitfast/raw/", tags=["hidden"], handle_response=True) | @api_doc("/vault/revision_gitfast/raw/", tags=["hidden"]) | ||||
def _api_vault_revision_gitfast_raw(request, rev_id): | def _api_vault_revision_gitfast_raw(request, rev_id): | ||||
""" | """ | ||||
The vault backend sends an email containing an invalid url to fetch a | The vault backend sends an email containing an invalid url to fetch a | ||||
gitfast archive. So setup a redirection to the correct one as a temporary | gitfast archive. So setup a redirection to the correct one as a temporary | ||||
workaround. | workaround. | ||||
""" | """ | ||||
rev_gitfast_raw_url = reverse( | rev_gitfast_raw_url = reverse( | ||||
"api-1-vault-fetch-revision_gitfast", url_args={"rev_id": rev_id} | "api-1-vault-fetch-revision_gitfast", url_args={"rev_id": rev_id} | ||||
) | ) | ||||
return redirect(rev_gitfast_raw_url) | return redirect(rev_gitfast_raw_url) |