1
2
3 import logging
4
5 log = logging.getLogger(__name__)
6
7 import flask
8 from flask import url_for, make_response
9 from flask_restful import Resource
10
11 from sqlalchemy.exc import IntegrityError
12
13 from ... import db
14 from ...logic.coprs_logic import MockChrootsLogic, CoprChrootsLogic
15 from ...exceptions import InsufficientRightsException, MalformedArgumentException
16
17 from ..exceptions import AccessForbidden, MalformedRequest, \
18 ObjectAlreadyExists, ObjectNotFoundError
19 from ..common import rest_api_auth_required, render_copr_chroot, get_project_safe
20 from ..schemas import CoprChrootSchema, CoprChrootCreateSchema
21 from ..util import get_one_safe, mm_deserialize
25
26 @classmethod
27 - def get(cls, project_id):
39
40 @classmethod
41 @rest_api_auth_required
42 - def post(cls, project_id):
43 project = get_project_safe(project_id)
44
45 req = mm_deserialize(CoprChrootCreateSchema(),
46 flask.request.data.decode("utf-8"))
47 name = req.pop("name")
48
49 try:
50 mock_chroot = get_one_safe(MockChrootsLogic.get_from_name(name))
51 except (MalformedArgumentException, ObjectNotFoundError) as err:
52 raise MalformedRequest("Bad mock chroot name: {}. Error: {}".format(name, err))
53
54 try:
55 CoprChrootsLogic.create_chroot(flask.g.user, project, mock_chroot, **req)
56 db.session.commit()
57 except IntegrityError as err:
58
59 db.session.rollback()
60 if get_one_safe(CoprChrootsLogic.get_by_name(project, name)) is not None:
61 raise ObjectAlreadyExists("Copr {} already has chroot {} enabled"
62 .format(project.full_name, name))
63
64 resp = make_response("", 201)
65 resp.headers["Location"] = url_for(".projectchrootr",
66 project_id=project.id, name=name)
67 return resp
68
71
72 @staticmethod
79
80 - def get(self, project_id, name):
85
86 @classmethod
87 @rest_api_auth_required
88 - def delete(cls, project_id, name):
101
102 @rest_api_auth_required
103 - def put(self, project_id, name):
119