예제 #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"])
예제 #2
0
    def post(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
        """
        try:
            config = request.data

            injection = config.get("injection")
            service_meta_type = config.get("service_meta_type")
            config_groups = plugin_config_service.get_config_group(
                self.plugin_version.plugin_id,
                self.plugin_version.build_version)
            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)
            create_data = [config]
            plugin_config_service.create_config_groups(
                self.plugin_version.plugin_id,
                self.plugin_version.build_version, create_data)

            result = general_message(200, "success", "添加成功")

        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
예제 #3
0
    def get(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
        """
        try:
            wordpress_alias = "wordpress_alias"
            mysql_alias = "mysql_alias"
            wp_ports = [80, 8081]
            mysql_port = [3306]
            wp_id = "wp_service_id"
            mysql_id = "mysql_service_id"

            config_groups = plugin_config_service.get_config_group(
                self.plugin_version.plugin_id,
                self.plugin_version.build_version)
            all_config_group = []
            base_ports = []
            base_services = []
            base_normal = {}
            for config_group in config_groups:
                config_items = plugin_config_service.get_config_items(
                    self.plugin_version.plugin_id,
                    self.plugin_version.build_version,
                    config_group.service_meta_type)
                items = []
                for item in config_items:
                    item_map = {}
                    item_map[item.attr_name] = item.attr_default_value
                    items.append(item_map)

                if config_group.service_meta_type == PluginMetaType.UPSTREAM_PORT:
                    for port in wp_ports:
                        base_port = {}
                        base_port["service_alias"] = wordpress_alias
                        base_port["service_id"] = wp_id
                        base_port["port"] = port
                        base_port["protocol"] = "http"
                        base_port["options"] = items
                        base_ports.append(base_port)
                if config_group.service_meta_type == PluginMetaType.DOWNSTREAM_PORT:
                    for port in mysql_port:
                        base_service = {}
                        base_service["service_alias"] = wordpress_alias
                        base_service["service_id"] = wp_id
                        base_service["port"] = port
                        #base_service["protocol"] = "stream"
                        base_service["protocol"] = "mysql"
                        base_service["options"] = items
                        base_service["depend_service_alias"] = mysql_alias
                        base_service["depend_service_id"] = mysql_id
                        base_services.append(base_service)
                if config_group.service_meta_type == PluginMetaType.UNDEFINE:
                    base_normal["options"] = items

            bean = {
                "base_ports": base_ports,
                "base_services": base_services,
                "base_normal": base_normal.get("options", None)
            }

            result = general_message(200,
                                     "success",
                                     "查询成功",
                                     bean=bean,
                                     list=all_config_group)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])