Пример #1
0
    def post(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return {"message": "step not found"}, 404

        args = self.parser.parse_args()

        if args.implementation is not None:
            step.implementation = args.implementation

        if args.data is not None:
            data = json.loads(args.data)
            if not isinstance(data, dict):
                return {"message": "data must be a JSON mapping"}, 400

            impl_cls = step.get_implementation(load=False)
            if impl_cls is None:
                return {
                    "message": "unable to load build step implementation"
                }, 400

            try:
                # XXX(dcramer): It's important that we deepcopy data so any
                # mutations within the BuildStep don't propagate into the db
                impl_cls(**deepcopy(data))
            except Exception:
                return {
                    "message":
                    "unable to create build step mapping provided data"
                }, 400
            step.data = data

        if args.order is not None:
            step.order = args.order

        step.date_modified = datetime.utcnow()
        db.session.add(step)

        plan = step.plan
        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption,
                             where={
                                 'item_id': step.id,
                                 'name': name,
                             },
                             values={
                                 'value': value,
                             })

        db.session.commit()

        return self.serialize(step), 200
Пример #2
0
    def post(self, plan_id):
        plan = Plan.query.get(plan_id)
        if plan is None:
            return error("plan not found", http_code=404)

        args = self.parser.parse_args()

        step = Step(
            plan=plan,
            order=args.order,
            implementation=args.implementation,
        )

        try:
            data = json.loads(args.data)
        except ValueError as e:
            db.session.rollback()
            return error("invalid JSON: %s" % e)
        if not isinstance(data, dict):
            db.session.rollback()
            return error("data must be a JSON mapping")

        impl_cls = step.get_implementation(load=False)
        if impl_cls is None:
            db.session.rollback()
            return error("unable to load build step implementation")

        try:
            # XXX(dcramer): It's important that we deepcopy data so any
            # mutations within the BuildStep don't propagate into the db
            impl_cls(**deepcopy(data))
        except Exception as exc:
            db.session.rollback()
            return error("unable to create build step provided data: %s" % exc)

        step.data = data
        step.order = args.order
        db.session.add(step)

        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption,
                             where={
                                 'item_id': step.id,
                                 'name': name,
                             },
                             values={
                                 'value': value,
                             })

        return self.serialize(step), 201
Пример #3
0
    def post(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return error("step not found", http_code=404)

        args = self.parser.parse_args()

        if args.implementation is not None:
            step.implementation = args.implementation

        if args.data is not None:
            try:
                data = json.loads(args.data)
            except ValueError as e:
                return error("invalid JSON: %s" % e)

            if not isinstance(data, dict):
                return error("data must be a JSON mapping")

            impl_cls = step.get_implementation(load=False)
            if impl_cls is None:
                return error("unable to load build step implementation")

            try:
                # XXX(dcramer): It's important that we deepcopy data so any
                # mutations within the BuildStep don't propagate into the db
                impl_cls(**deepcopy(data))
            except Exception as exc:
                return error("unable to create build step mapping provided data: %s" % exc)
            step.data = data

        if args.order is not None:
            step.order = args.order

        step.date_modified = datetime.utcnow()
        db.session.add(step)

        plan = step.plan
        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption, where={
                'item_id': step.id,
                'name': name,
            }, values={
                'value': value,
            })

        db.session.commit()

        return self.serialize(step), 200
Пример #4
0
    def post(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return {"message": "step not found"}, 404

        args = self.parser.parse_args()

        if args.implementation is not None:
            step.implementation = args.implementation

        if args.data is not None:
            data = json.loads(args.data)
            if not isinstance(data, dict):
                return {"message": "data must be a JSON mapping"}, 400

            impl_cls = step.get_implementation(load=False)
            if impl_cls is None:
                return {"message": "unable to load build step implementation"}, 400

            try:
                impl_cls(**data)
            except Exception:
                return {"message": "unable to create build step mapping provided data"}, 400
            step.data = data

        if args.order is not None:
            step.order = args.order

        step.date_modified = datetime.utcnow()
        db.session.add(step)

        plan = step.plan
        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption, where={
                'item_id': step.id,
                'name': name,
            }, values={
                'value': value,
            })

        db.session.commit()

        return self.serialize(step), 200
Пример #5
0
    def post(self, plan_id):
        plan = Plan.query.get(plan_id)
        if plan is None:
            return {"message": "plan not found"}, 404

        args = self.parser.parse_args()

        step = Step(
            plan=plan,
            order=args.order,
            implementation=args.implementation,
        )

        data = json.loads(args.data)
        if not isinstance(data, dict):
            return {"message": "data must be a JSON mapping"}, 400

        impl_cls = step.get_implementation(load=False)
        if impl_cls is None:
            return {"message": "unable to load build step implementation"}, 400

        try:
            impl_cls(**data)
        except Exception:
            return {
                "message": "unable to create build step provided data"
            }, 400

        step.data = data
        step.order = args.order
        db.session.add(step)

        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption,
                             where={
                                 'item_id': step.id,
                                 'name': name,
                             },
                             values={
                                 'value': value,
                             })

        return self.serialize(step), 201
Пример #6
0
    def post(self, plan_id):
        plan = Plan.query.get(plan_id)
        if plan is None:
            return {"message": "plan not found"}, 404

        args = self.parser.parse_args()

        step = Step(
            plan=plan,
            order=args.order,
            implementation=args.implementation,
        )

        data = json.loads(args.data)
        if not isinstance(data, dict):
            return {"message": "data must be a JSON mapping"}, 400

        impl_cls = step.get_implementation(load=False)
        if impl_cls is None:
            return {"message": "unable to load build step implementation"}, 400

        try:
            # XXX(dcramer): It's important that we deepcopy data so any
            # mutations within the BuildStep don't propagate into the db
            impl_cls(**deepcopy(data))
        except Exception:
            return {"message": "unable to create build step provided data"}, 400

        step.data = data
        step.order = args.order
        db.session.add(step)

        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption, where={
                'item_id': step.id,
                'name': name,
            }, values={
                'value': value,
            })

        return self.serialize(step), 201
Пример #7
0
class StepDetailsAPIView(APIView):
    parser = reqparse.RequestParser()
    parser.add_argument('data')
    parser.add_argument('implementation', choices=IMPLEMENTATION_CHOICES)
    parser.add_argument('order', type=int, default=0)
    for name in STEP_OPTIONS.keys():
        parser.add_argument(name)

    def get(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return {"message": "step not found"}, 404

        return self.respond(step)

    @requires_admin
    def post(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return {"message": "step not found"}, 404

        args = self.parser.parse_args()

        if args.implementation is not None:
            step.implementation = args.implementation

        if args.data is not None:
            data = json.loads(args.data)
            if not isinstance(data, dict):
                return {"message": "data must be a JSON mapping"}, 400

            impl_cls = step.get_implementation(load=False)
            if impl_cls is None:
                return {
                    "message": "unable to load build step implementation"
                }, 400

            try:
                impl_cls(**data)
            except Exception:
                return {
                    "message":
                    "unable to create build step mapping provided data"
                }, 400
            step.data = data

        if args.order is not None:
            step.order = args.order

        step.date_modified = datetime.utcnow()
        db.session.add(step)

        plan = step.plan
        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption,
                             where={
                                 'item_id': step.id,
                                 'name': name,
                             },
                             values={
                                 'value': value,
                             })

        db.session.commit()

        return self.serialize(step), 200

    @requires_admin
    def delete(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return '', 404

        ItemOption.query.filter(ItemOption.item_id == step.id).delete(
            synchronize_session=False, )

        Step.query.filter(Step.id == step.id, ).delete(
            synchronize_session=False, )

        db.session.commit()

        return '', 200
Пример #8
0
class PlanStepIndexAPIView(APIView):
    parser = reqparse.RequestParser()
    parser.add_argument('data', default='{}')
    parser.add_argument('implementation',
                        choices=IMPLEMENTATION_CHOICES,
                        required=True)
    parser.add_argument('order', type=int, default=0)
    for name in STEP_OPTIONS.keys():
        parser.add_argument(name)

    def get(self, plan_id):
        plan = Plan.query.get(plan_id)
        if plan is None:
            return error("plan not found", http_code=404)

        return self.respond(list(plan.steps))

    @requires_admin
    def post(self, plan_id):
        plan = Plan.query.get(plan_id)
        if plan is None:
            return error("plan not found", http_code=404)

        args = self.parser.parse_args()

        step = Step(
            plan=plan,
            order=args.order,
            implementation=args.implementation,
        )

        try:
            data = json.loads(args.data)
        except ValueError as e:
            db.session.rollback()
            return error("invalid JSON: %s" % e)
        if not isinstance(data, dict):
            db.session.rollback()
            return error("data must be a JSON mapping")

        impl_cls = step.get_implementation(load=False)
        if impl_cls is None:
            db.session.rollback()
            return error("unable to load build step implementation")

        try:
            # XXX(dcramer): It's important that we deepcopy data so any
            # mutations within the BuildStep don't propagate into the db
            impl_cls(**deepcopy(data))
        except Exception as exc:
            db.session.rollback()
            return error("unable to create build step provided data: %s" % exc)

        step.data = data
        step.order = args.order
        db.session.add(step)

        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption,
                             where={
                                 'item_id': step.id,
                                 'name': name,
                             },
                             values={
                                 'value': value,
                             })

        return self.serialize(step), 201
Пример #9
0
class StepDetailsAPIView(APIView):
    parser = reqparse.RequestParser()
    parser.add_argument('data')
    parser.add_argument('implementation', choices=IMPLEMENTATION_CHOICES)
    parser.add_argument('order', type=int, default=0)
    for name in STEP_OPTIONS.keys():
        parser.add_argument(name)

    def get(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return error("step not found", http_code=404)

        return self.respond(step)

    @requires_admin
    def post(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return error("step not found", http_code=404)

        args = self.parser.parse_args()

        if args.implementation is not None:
            step.implementation = args.implementation

        if args.data is not None:
            try:
                data = json.loads(args.data)
            except ValueError as e:
                return error("invalid JSON: %s" % e)

            if not isinstance(data, dict):
                return error("data must be a JSON mapping")

            impl_cls = step.get_implementation(load=False)
            if impl_cls is None:
                return error("unable to load build step implementation")

            try:
                # XXX(dcramer): It's important that we deepcopy data so any
                # mutations within the BuildStep don't propagate into the db
                impl_cls(**deepcopy(data))
            except Exception as exc:
                return error("unable to create build step mapping provided data: %s" % exc)
            step.data = data

        if args.order is not None:
            step.order = args.order

        step.date_modified = datetime.utcnow()
        db.session.add(step)

        plan = step.plan
        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption, where={
                'item_id': step.id,
                'name': name,
            }, values={
                'value': value,
            })

        db.session.commit()

        return self.serialize(step), 200

    @requires_admin
    def delete(self, step_id):
        step = Step.query.get(step_id)
        if step is None:
            return '', 404

        ItemOption.query.filter(
            ItemOption.item_id == step.id
        ).delete(
            synchronize_session=False,
        )

        Step.query.filter(
            Step.id == step.id,
        ).delete(
            synchronize_session=False,
        )

        db.session.commit()

        return '', 200
Пример #10
0
class PlanStepIndexAPIView(APIView):
    parser = reqparse.RequestParser()
    parser.add_argument('data', default='{}')
    parser.add_argument('implementation',
                        choices=IMPLEMENTATION_CHOICES,
                        required=True)
    parser.add_argument('order', type=int, default=0)
    for name in STEP_OPTIONS.keys():
        parser.add_argument(name)

    def get(self, plan_id):
        plan = Plan.query.get(plan_id)
        if plan is None:
            return {"message": "plan not found"}, 404

        return self.respond(list(plan.steps))

    @requires_admin
    def post(self, plan_id):
        plan = Plan.query.get(plan_id)
        if plan is None:
            return {"message": "plan not found"}, 404

        args = self.parser.parse_args()

        step = Step(
            plan=plan,
            order=args.order,
            implementation=args.implementation,
        )

        data = json.loads(args.data)
        if not isinstance(data, dict):
            return {"message": "data must be a JSON mapping"}, 400

        impl_cls = step.get_implementation(load=False)
        if impl_cls is None:
            return {"message": "unable to load build step implementation"}, 400

        try:
            impl_cls(**data)
        except Exception:
            return {
                "message": "unable to create build step provided data"
            }, 400

        step.data = data
        step.order = args.order
        db.session.add(step)

        plan.date_modified = step.date_modified
        db.session.add(plan)

        for name in STEP_OPTIONS.keys():
            value = args.get(name)
            if value is None:
                continue

            create_or_update(ItemOption,
                             where={
                                 'item_id': step.id,
                                 'name': name,
                             },
                             values={
                                 'value': value,
                             })

        return self.serialize(step), 201