validations.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:deckhand 作者: att-comdev 项目源码 文件源码
def on_post(self, req, resp, revision_id, validation_name):
        validation_data = req.stream.read(req.content_length or 0)
        try:
            validation_data = yaml.safe_load(validation_data)
        except yaml.YAMLError as e:
            error_msg = ("Could not parse the validation into YAML data. "
                         "Details: %s." % e)
            LOG.error(error_msg)
            raise falcon.HTTPBadRequest(description=six.text_type(e))

        if not validation_data:
            error_msg = 'Validation payload must be provided.'
            LOG.error(error_msg)
            raise falcon.HTTPBadRequest(description=error_msg)

        if not all([validation_data.get(x) for x in ('status', 'validator')]):
            error_msg = 'Validation payload must contain keys: %s.' % (
                ', '.join(['"status"', '"validator"']))
            LOG.error(error_msg)
            raise falcon.HTTPBadRequest(description=error_msg)

        try:
            resp_body = db_api.validation_create(
                revision_id, validation_name, validation_data)
        except errors.RevisionNotFound as e:
            raise falcon.HTTPNotFound(description=e.format_message())

        resp.status = falcon.HTTP_201
        resp.append_header('Content-Type', 'application/x-yaml')
        resp.body = self.view_builder.show(resp_body)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号