Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/origin_save.py
# Copyright (C) 2018-2021 The Software Heritage developers | # Copyright (C) 2018-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from swh.web.api.apidoc import api_doc, format_docstring | from swh.web.api.apidoc import api_doc, format_docstring | ||||
from swh.web.api.apiurls import api_route | from swh.web.api.apiurls import api_route | ||||
from swh.web.auth.utils import privileged_user | from swh.web.auth.utils import privileged_user | ||||
from swh.web.common.origin_save import ( | from swh.web.common.origin_save import ( | ||||
create_save_origin_request, | create_save_origin_request, | ||||
get_savable_visit_types, | |||||
get_save_origin_requests, | get_save_origin_requests, | ||||
) | ) | ||||
def _savable_visit_types(): | |||||
visit_types = sorted(get_savable_visit_types()) | |||||
docstring = "" | |||||
for visit_type in visit_types[:-1]: | |||||
docstring += f"**{visit_type}**, " | |||||
docstring += f"and **{visit_types[-1]}**" | |||||
return docstring | |||||
@api_route( | @api_route( | ||||
r"/origin/save/(?P<visit_type>.+)/url/(?P<origin_url>.+)/", | r"/origin/save/(?P<visit_type>.+)/url/(?P<origin_url>.+)/", | ||||
"api-1-save-origin", | "api-1-save-origin", | ||||
methods=["GET", "POST"], | methods=["GET", "POST"], | ||||
throttle_scope="swh_save_origin", | throttle_scope="swh_save_origin", | ||||
never_cache=True, | never_cache=True, | ||||
) | ) | ||||
@api_doc("/origin/save/") | @api_doc("/origin/save/") | ||||
@format_docstring() | @format_docstring(visit_types=_savable_visit_types()) | ||||
def api_save_origin(request, visit_type, origin_url): | def api_save_origin(request, visit_type, origin_url): | ||||
""" | """ | ||||
.. http:get:: /api/1/origin/save/(visit_type)/url/(origin_url)/ | .. http:get:: /api/1/origin/save/(visit_type)/url/(origin_url)/ | ||||
.. http:post:: /api/1/origin/save/(visit_type)/url/(origin_url)/ | .. http:post:: /api/1/origin/save/(visit_type)/url/(origin_url)/ | ||||
Request the saving of a software origin into the archive | Request the saving of a software origin into the archive | ||||
or check the status of previously created save requests. | or check the status of previously created save requests. | ||||
Show All 19 Lines | .. http:post:: /api/1/origin/save/(visit_type)/url/(origin_url)/ | ||||
* **succeeded**: the saving task has been successfully executed | * **succeeded**: the saving task has been successfully executed | ||||
* **failed**: the saving task has been executed but it failed | * **failed**: the saving task has been executed but it failed | ||||
When issuing a POST request an object will be returned while a GET | When issuing a POST request an object will be returned while a GET | ||||
request will return an array of objects (as multiple save requests | request will return an array of objects (as multiple save requests | ||||
might have been submitted for the same origin). | might have been submitted for the same origin). | ||||
:param string visit_type: the type of visit to perform | :param string visit_type: the type of visit to perform | ||||
(currently the supported types are ``git``, ``hg`` and ``svn``) | (currently the supported types are {visit_types}) | ||||
:param string origin_url: the url of the origin to save | :param string origin_url: the url of the origin to save | ||||
{common_headers} | {common_headers} | ||||
:>json string origin_url: the url of the origin to save | :>json string origin_url: the url of the origin to save | ||||
:>json string visit_type: the type of visit to perform | :>json string visit_type: the type of visit to perform | ||||
:>json string save_request_date: the date (in iso format) the save | :>json string save_request_date: the date (in iso format) the save | ||||
request was issued | request was issued | ||||
Show All 34 Lines |