Exemple #1
0
    def put(self, request, *args, **kwargs):
        """
        修改插件配置信息
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: plugin_id
              description: 插件ID
              required: true
              type: string
              paramType: path
            - name: build_version
              description: 版本
              required: true
              type: string
              paramType: path
            - name: body
              description: 配置组内容
              required: true
              type: string
              paramType: body
        """
        config = request.data

        injection = config.get("injection")
        service_meta_type = config.get("service_meta_type")
        config_name = config.get("config_name")
        config_group_pk = config.get("ID")

        config_groups = plugin_config_service.get_config_group(
            self.plugin_version.plugin_id,
            self.plugin_version.build_version).exclude(pk=config_group_pk)
        is_pass, msg = plugin_config_service.check_group_config(
            service_meta_type, injection, config_groups)

        if not is_pass:
            return Response(general_message(400, "param error", msg),
                            status=400)
        config_group = plugin_config_service.get_config_group_by_pk(
            config_group_pk)
        old_meta_type = config_group.service_meta_type
        plugin_config_service.update_config_group_by_pk(
            config_group_pk, config_name, service_meta_type, injection)

        # 删除原有配置项
        plugin_config_service.delet_config_items(
            self.plugin_version.plugin_id, self.plugin_version.build_version,
            old_meta_type)
        options = config.get("options")
        plugin_config_service.create_config_items(
            self.plugin_version.plugin_id, self.plugin_version.build_version,
            service_meta_type, *options)

        result = general_message(200, "success", "修改成功")
        return Response(result, status=result["code"])
Exemple #2
0
    def delete(self, request, *args, **kwargs):
        """
        删除插件配置信息
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: plugin_id
              description: 插件ID
              required: true
              type: string
              paramType: path
            - name: build_version
              description: 版本
              required: true
              type: string
              paramType: path
            - name: config_group_id
              description: 配置组ID
              required: true
              type: string
              paramType: form
        """
        try:
            config_group_id = request.data.get("config_group_id")
            if not config_group_id:
                return Response(general_message(400, "param error", "参数错误"),
                                status=400)

            config_group = plugin_config_service.get_config_group_by_pk(
                config_group_id)
            if not config_group:
                return Response(general_message(404, "config group not exist",
                                                "配置组不存在"),
                                status=404)
            plugin_config_service.delete_config_group_by_meta_type(
                config_group.plugin_id, config_group.build_version,
                config_group.service_meta_type)

            result = general_message(200, "success", "删除成功")

        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])