Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : master
commit 05bdd3e7f6d71e9285be1fd798b33fa88187d0d1 Author: Valentin Gologuzov vgologuz@redhat.com Date: Thu Sep 3 20:27:43 2015 +0200
[frontend][API docs] added docs for ProjectChroot
frontend/coprs_frontend/coprs/models.py | 7 + .../coprs/rest_api/resources/project.py | 4 +- .../coprs/rest_api/resources/project_chroot.py | 2 +- frontend/docs/api_2/source/Resources/project.rst | 22 +- .../docs/api_2/source/Resources/project_chroot.rst | 237 ++++++++++++++++++++ 5 files changed, 257 insertions(+), 15 deletions(-)
diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py index 79fd77e..a8844f4 100644 --- a/frontend/coprs_frontend/coprs/models.py +++ b/frontend/coprs_frontend/coprs/models.py @@ -190,6 +190,13 @@ class Copr(db.Model, helpers.Serializer): return filter(lambda x: x.is_active, self.mock_chroots)
@property + def active_copr_chroots(self): + """ + :rtype: list of CoprChroot + """ + return [c for c in self.copr_chroots if c.is_active] + + @property def active_chroots_sorted(self): """ Return list of active mock_chroots of this copr diff --git a/frontend/coprs_frontend/coprs/rest_api/resources/project.py b/frontend/coprs_frontend/coprs/rest_api/resources/project.py index cee7bf7..48ace15 100644 --- a/frontend/coprs_frontend/coprs/rest_api/resources/project.py +++ b/frontend/coprs_frontend/coprs/rest_api/resources/project.py @@ -158,7 +158,5 @@ class ProjectR(Resource): except InsufficientRightsException as err: raise AccessForbidden(str(err))
- resp = make_response("", 201) - resp.headers["Location"] = url_for(".projectr", project_id=project.id) - return resp + return "", 204
diff --git a/frontend/coprs_frontend/coprs/rest_api/resources/project_chroot.py b/frontend/coprs_frontend/coprs/rest_api/resources/project_chroot.py index 294114c..f5ec11d 100644 --- a/frontend/coprs_frontend/coprs/rest_api/resources/project_chroot.py +++ b/frontend/coprs_frontend/coprs/rest_api/resources/project_chroot.py @@ -29,7 +29,7 @@ class ProjectChrootListR(Resource): return { "chroots": [ render_copr_chroot(chroot) - for chroot in copr.copr_chroots + for chroot in copr.active_copr_chroots ], "_links": { "self": {"href": url_for(".projectchrootlistr", project_id=project_id)} diff --git a/frontend/docs/api_2/source/Resources/project.rst b/frontend/docs/api_2/source/Resources/project.rst index 450e8f6..a28e882 100644 --- a/frontend/docs/api_2/source/Resources/project.rst +++ b/frontend/docs/api_2/source/Resources/project.rst @@ -108,6 +108,13 @@ Create new project Additionally to described before `Project fields`_ the user could specify field `chroots` which contains list of chroots to be enabled. Available `chroot` names could be obtained from MockChrootResource_
+ :resheader Location: contains URL to the newly created project entity + + :statuscode 201: project was successfully created + :statuscode 400: given data for project creation doesn't satisfy some requirements + :statuscode 401: the user already has project with the same name + :statuscode 403: authorization failed + **Example request**:
.. sourcecode:: http @@ -135,12 +142,6 @@ Create new project HTTP/1.1 201 CREATED Location: /api_2/projects/<new project id>
- :resheader Location: contains URL to the newly created project entity - - :statuscode 201: project was successfully created - :statuscode 400: given data for project creation doesn't satisfy some requirements - :statuscode 401: the user already has project with the same name - :statuscode 403: authorization failed
Get project details ------------------- @@ -148,7 +149,7 @@ Get project details
Returns details about Copr project
- :param project_id: a unique identifier of the Copr project. + :param int project_id: a unique identifier of the Copr project.
:query bool show_builds: embed Build_ entities owned by this project into the result, default is False :query bool show_chroots: embed ProjectChroot_ sub-resources into the result, default is False @@ -160,7 +161,7 @@ Get project details
.. sourcecode:: http
- GET /api_2/projects/2482 HTTP/1.1 + GET /api_2/projects/2482?show_chroots=True&show_builds=True HTTP/1.1 Host: copr.fedoraproject.org Accept: application/json
@@ -267,7 +268,7 @@ Modify project
Updates Copr project.
- .. note:: You couldn't add or remove project chroots here, use ProjectChroots_ resource. + .. note:: You couldn't enabled or disable project chroots here, use ProjectChroots_ resource.
:param project_id: a unique identifier of the Copr project.
@@ -295,5 +296,4 @@ Modify project
.. sourcecode:: http
- HTTP/1.1 201 NO CONTENT - Location: /api_2/projects/1 + HTTP/1.1 204 NO CONTENT diff --git a/frontend/docs/api_2/source/Resources/project_chroot.rst b/frontend/docs/api_2/source/Resources/project_chroot.rst index 59da2f8..d63dec7 100644 --- a/frontend/docs/api_2/source/Resources/project_chroot.rst +++ b/frontend/docs/api_2/source/Resources/project_chroot.rst @@ -1,4 +1,241 @@ Project Chroot ==============
+Projects Chroots allows to view and modify project settings dedicated for different chroots.
+Structure if the project chroot entity +-------------------------------------- + +.. code-block:: javascript + + { + "comps": null, + "comps_len": 0, + "buildroot_pkgs": [ + "scl-build-utils", + "foobar" + ], + "name": "fedora-22-i386", + "comps_name": null + } + +Project Chroot fields +~~~~~~~~~~~~~~~~~~~~~ +================== ==================== ========= =============== +Field Type Can edit? Description +================== ==================== ========= =============== +name string no chroot name +buildroot_pkgs list of strings yes packages to be installed into the buildroot +comps string yes content of the `comps.xml`_ +comps_name string yes name of the uploaded comps file +comps_len int no size of the uploaded comps file (bytes) +================== ==================== ========= =============== + +List project chroots +-------------------- +.. http:get:: /api_2/projects/(int:project_id)/chroots + + Returns a list of project chroots + + :param int project_id: a unique identifier of the Copr project. + + :statuscode 200: no error + :statuscode 404: project not found + + **Example request** + + .. sourcecode:: http + + GET /api_2/projects/2482/chroots HTTP/1.1 + Host: copr.fedoraproject.org + Accept: application/json + + **Response** + + .. sourcecode:: http + + HTTP/1.1 200 OK + Content-Type: application/json + + { + "chroots": [ + { + "chroot": { + "comps": null, + "comps_len": 0, + "buildroot_pkgs": [], + "name": "fedora-21-x86_64", + "comps_name": null + }, + "_links": { + "project": { + "href": "/api_2/projects/2482" + }, + "self": { + "href": "/api_2/projects/2482/chroots/fedora-21-x86_64" + } + } + }, + { } + ], + "_links": { + "self": { + "href": "/api_2/projects/2482/chroots" + } + } + } + +Enable chroot for project +------------------------- +.. http:post:: /api_2/projects/(int:project_id)/chroots + + **REQUIRE AUTH** + + Enables chroot for the Copr project. + Available `chroot` names could be obtained from MockChrootResource_ + + :param int project_id: a unique identifier of the Copr project. + + :resheader Location: contains URL to the enabled project chroot + + :statuscode 201: project was successfully created + :statuscode 400: given data doesn't satisfy some requirements + :statuscode 401: this chroot is already enabled + :statuscode 403: authorization failed + + + **Example request**: + + .. sourcecode:: http + + POST HTTP/1.1 + Host: copr.fedoraproject.org + Authorization: Basic base64=encoded=string + Accept: application/json + + { + "buildroot_pkgs": ["foo", "bar"], + "name": "fedora-22-x86_64" + } + + **Response**: + + .. sourcecode:: http + + HTTP/1.1 201 CREATED + Location: /api_2/projects/2482/chroots/fedora-22-x86_64 + +Get project chroot details +-------------------------- +.. http:get:: /api_2/projects/(int:project_id)/chroots/(str:chroot_name) + + Returns details about Copr project + + :param int project_id: a unique identifier of the Copr project. + :param str chroot_name: name of the project chroot + + :statuscode 200: no error + :statuscode 404: project not found or chroot isn't enabled for the project + + **Example request** + + .. sourcecode:: http + + GET /api_2/projects/2482/chroots/fedora-22-x86_64 HTTP/1.1 + Host: copr.fedoraproject.org + Accept: application/json + + **Response** + + .. sourcecode:: http + + HTTP/1.1 200 OK + Content-Type: application/json + + { + "chroot": { + "comps": null, + "comps_len": 0, + "buildroot_pkgs": [ + "foo", + "bar" + ], + "name": "fedora-22-x86_64", + "comps_name": null + }, + "_links": { + "project": { + "href": "/api_2/projects/2482" + }, + "self": { + "href": "/api_2/projects/2482/chroots/fedora-22-x86_64" + } + } + } + +Disable chroot for project +-------------------------- +.. http:delete:: /api_2/projects/(int:project_id)/chroots/(str:chroot_name) + + **REQUIRE AUTH** + + Disables chroot for the Copr project + + :param int project_id: a unique identifier of the Copr project. + :param str chroot_name: name of the project chroot + + :statuscode 204: project was removed + :statuscode 403: authorization failed + :statuscode 404: project not found or chroot isn't enabled for the project + + **Example request**: + + .. sourcecode:: http + + DELETE /api_2/projects/2482/chroots/fedora-22-x86_64 HTTP/1.1 + Host: copr.fedoraproject.org + Authorization: Basic base64=encoded=string + + **Response** + + .. sourcecode:: http + + HTTP/1.1 204 NO CONTENT + +Modify project chroot +--------------------- +.. http:put:: /api_2/projects/(int:project_id)/chroots/(str:chroot_name) + + + **REQUIRE AUTH** + + Updated project chroot settings + + :param int project_id: a unique identifier of the Copr project. + :param str chroot_name: name of the project chroot + + :statuscode 201: project chroot was updated + :statuscode 400: malformed request, see response content for details + :statuscode 403: authorization failed + :statuscode 404: project not found or chroot isn't enabled for the project + + **Example request**: + + .. sourcecode:: http + + PUT /api_2/projects/2482/chroots/fedora-22-x86_64 HTTP/1.1 + Host: copr.fedoraproject.org + Authorization: Basic base64=encoded=string + + { + "buildroot_pkgs": [] + } + + **Response** + + .. sourcecode:: http + + HTTP/1.1 204 NO CONTENT + + +.. _comps.xml: https://fedorahosted.org/comps/
copr-commits@lists.fedorahosted.org