def get(self, request, team_name, share_id, event_id, *args, **kwargs):
        share_record = share_service.get_service_share_record_by_ID(
            ID=share_id, team_name=team_name)
        if not share_record:
            result = general_message(404, "share record not found",
                                     "分享流程不存在,请退出重试")
            return Response(result, status=404)
        if share_record.is_success or share_record.step >= 3:
            result = general_message(400, "share record is complete",
                                     "分享流程已经完成,请重新进行分享")
            return Response(result, status=400)

        plugin_events = PluginShareRecordEvent.objects.filter(
            record_id=share_id, ID=event_id).order_by("ID")
        if not plugin_events:
            result = general_message(404, "not exist", "分享事件不存在")
            return Response(result, status=404)

        if plugin_events[0].event_status == "success":
            result = general_message(200,
                                     "get sync share event result",
                                     "查询成功",
                                     bean=plugin_events[0].to_dict())
            return Response(result, status=200)
        bean = share_service.get_sync_plugin_events(self.response_region,
                                                    team_name,
                                                    plugin_events[0])
        result = general_message(200,
                                 "get sync share event result",
                                 "查询成功",
                                 bean=bean.to_dict())
        return Response(result, status=200)
示例#2
0
 def post(self, request, team_name, share_id, *args, **kwargs):
     try:
         share_record = share_service.get_service_share_record_by_ID(
             ID=share_id, team_name=team_name)
         if not share_record:
             result = general_message(404, "share record not found",
                                      "分享流程不存在,请退出重试")
             return Response(result, status=404)
         if share_record.is_success or share_record.step >= 3:
             result = general_message(400, "share record is complete",
                                      "分享流程已经完成,请重新进行分享")
             return Response(result, status=400)
         # 验证是否所有同步事件已完成
         count = ServiceShareRecordEvent.objects.filter(
             Q(record_id=share_id) & ~Q(event_status="success")).count()
         plugin_count = PluginShareRecordEvent.objects.filter(
             Q(record_id=share_id) & ~Q(event_status="success")).count()
         if count > 0 or plugin_count > 0:
             result = general_message(415, "share complete can not do",
                                      "应用或插件同步未全部完成")
             return Response(result, status=415)
         app_market_url = share_service.complete(self.tenant, self.user,
                                                 share_record)
         result = general_message(200,
                                  "share complete",
                                  "应用分享完成",
                                  bean=share_record.to_dict(),
                                  app_market_url=app_market_url)
     except ServiceHandleException as e:
         raise e
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
     return Response(result, status=result["code"])
示例#3
0
 def get(self, request, team_name, share_id, *args, **kwargs):
     try:
         share_record = share_service.get_service_share_record_by_ID(ID=share_id, team_name=team_name)
         if not share_record:
             result = general_message(404, "share record not found", "分享流程不存在,请退出重试")
             return Response(result, status=404)
         if share_record.is_success or share_record.step >= 3:
             result = general_message(400, "share record is complete", "分享流程已经完成,请重新进行分享")
             return Response(result, status=400)
         events = ServiceShareRecordEvent.objects.filter(record_id=share_id)
         if not events:
             result = general_message(404, "not exist", "分享事件不存在")
             return Response(result, status=404)
         result = {}
         result["event_list"] = list()
         for event in events:
             if event.event_status != "success":
                 result["is_compelte"] = False
             result["event_list"].append(event.to_dict())
         result = general_message(200, "query success", "获取成功", bean=result)
         return Response(result, status=200)
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
         return Response(result, status=500)
示例#4
0
 def get(self, request, team_name, share_id, *args, **kwargs):
     """
     查询分享的所有应用信息和插件信息
     ---
     parameter:
         - name: team_name
           description: 团队名
           required: true
           type: string
           paramType: path
         - name: share_id
           description: 分享订单ID
           required: true
           type: string
           paramType: path
     """
     data = dict()
     scope = request.GET.get("scope")
     share_record = share_service.get_service_share_record_by_ID(ID=share_id, team_name=team_name)
     if not share_record:
         result = general_message(404, "share record not found", "分享流程不存在,请退出重试")
         return Response(result, status=404)
     if share_record.is_success or share_record.step >= 3:
         result = general_message(400, "share record is complete", "分享流程已经完成,请重新进行分享")
         return Response(result, status=400)
     if not scope:
         scope = share_record.scope
     service_info_list = share_service.query_share_service_info(team=self.team, group_id=share_record.group_id, scope=scope)
     data["share_service_list"] = service_info_list
     plugins = share_service.get_group_services_used_plugins(group_id=share_record.group_id)
     data["share_plugin_list"] = plugins
     result = general_message(200, "query success", "获取成功", bean=data)
     return Response(result, status=200)
示例#5
0
    def post(self, request, team_name, share_id, event_id, *args, **kwargs):
        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在,请退出重试")
                return Response(result, status=404)
            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,请重新进行分享")
                return Response(result, status=400)
            events = PluginShareRecordEvent.objects.filter(record_id=share_id,
                                                           ID=event_id)
            if not events:
                result = general_message(404, "not exist", "分享事件不存在")
                return Response(result, status=404)

            code, msg, bean = share_service.sync_service_plugin_event(
                self.user, self.response_region, self.tenant.tenant_name,
                share_id, events[0])
            result = general_message(code,
                                     "sync share event",
                                     msg,
                                     bean=bean.to_dict())
            return Response(result, status=code)
        except ServiceHandleException as e:
            raise e
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=result["code"])
示例#6
0
 def delete(self, request, team_name, share_id, *args, **kwargs):
     """
     放弃应用分享操作,放弃时删除分享记录
     ---
     parameter:
         - name: team_name
           description: 团队名
           required: true
           type: string
           paramType: path
         - name: share_id
           description: 分享订单ID
           required: true
           type: string
           paramType: path
     """
     try:
         share_record = share_service.get_service_share_record_by_ID(ID=share_id, team_name=team_name)
         if not share_record:
             result = general_message(404, "share record not found", "分享流程不存在,不能放弃")
             return Response(result, status=404)
         if share_record.is_success or share_record.step >= 3:
             result = general_message(400, "share record is complete", "分享流程已经完成,无法放弃")
             return Response(result, status=404)
         app = share_service.get_app_by_key(key=share_record.group_share_id)
         if app and not app.is_complete:
             share_service.delete_app(app)
         share_service.delete_record(share_record)
         result = general_message(200, "delete success", "放弃成功")
         return Response(result, status=200)
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
         return Response(result, status=500)
    def post(self, request, team_name, share_id, event_id, *args, **kwargs):
        share_record = share_service.get_service_share_record_by_ID(
            ID=share_id, team_name=team_name)
        if not share_record:
            result = general_message(404, "share record not found",
                                     "分享流程不存在,请退出重试")
            return Response(result, status=404)
        if share_record.is_success or share_record.step >= 3:
            result = general_message(400, "share record is complete",
                                     "分享流程已经完成,请重新进行分享")
            return Response(result, status=400)
        events = PluginShareRecordEvent.objects.filter(record_id=share_id,
                                                       ID=event_id)
        if not events:
            result = general_message(404, "not exist", "分享事件不存在")
            return Response(result, status=404)

        bean = share_service.sync_service_plugin_event(self.user,
                                                       self.response_region,
                                                       self.tenant.tenant_name,
                                                       share_id, events[0])
        if not bean:
            result = general_message(400, "sync share event", "插件不存在无需发布")
        else:
            result = general_message(200,
                                     "sync share event",
                                     "分享成功",
                                     bean=bean.to_dict())
        return Response(result, status=result["code"])
示例#8
0
 def get(self, request, team_name, share_id, event_id, *args, **kwargs):
     try:
         share_record = share_service.get_service_share_record_by_ID(ID=share_id, team_name=team_name)
         if not share_record:
             result = general_message(404, "share record not found", "分享流程不存在,请退出重试")
             return Response(result, status=404)
         if share_record.is_success or share_record.step >= 3:
             result = general_message(400, "share record is complete", "分享流程已经完成,请重新进行分享")
             return Response(result, status=400)
         events = ServiceShareRecordEvent.objects.filter(record_id=share_id, ID=event_id)
         if not events:
             result = general_message(404, "not exist", "分享事件不存在")
             return Response(result, status=404)
         if events[0].event_status == "success":
             result = general_message(200, "get sync share event result", "查询成功", bean=events[0].to_dict())
             return Response(result, status=200)
         bean = share_service.get_sync_event_result(self.response_region, team_name, events[0])
         result = general_message(200, "get sync share event result", "查询成功", bean=bean.to_dict())
         return Response(result, status=200)
     except ServiceHandleException as e:
         raise e
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
         return Response(result, status=500)
示例#9
0
 def post(self, request, team_name, share_id, event_id, *args, **kwargs):
     try:
         share_record = share_service.get_service_share_record_by_ID(ID=share_id, team_name=team_name)
         if not share_record:
             result = general_message(404, "share record not found", "分享流程不存在,请退出重试")
             return Response(result, status=404)
         if share_record.is_success or share_record.step >= 3:
             result = general_message(400, "share record is complete", "分享流程已经完成,请重新进行分享")
             return Response(result, status=400)
         events = ServiceShareRecordEvent.objects.filter(record_id=share_id, ID=event_id)
         if not events:
             result = general_message(404, "not exist", "分享事件不存在")
             return Response(result, status=404)
         record_event = share_service.sync_event(self.user, self.response_region, team_name, events[0])
         bean = record_event.to_dict() if record_event is not None else None
         result = general_message(200, "sync share event", "分享完成", bean=bean)
         return Response(result, status=200)
     except ServiceHandleException as e:
         raise e
     except RbdAppNotFound as e:
         result = general_message(404, "app not found", e.msg)
         return Response(result, status=result["code"])
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
         return Response(result, status=500)
示例#10
0
    def post(self, request, team_name, share_id, *args, **kwargs):
        """
        生成分享应用实体,向数据中心发送分享任务
        ---
        parameter:
            - name: team_name
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: share_id
              description: 分享流程ID
              required: true
              type: string
              paramType: path
        """
        use_force = parse_argument(request, 'use_force', default=False, value_type=bool)
        share_record = share_service.get_service_share_record_by_ID(ID=share_id, team_name=team_name)
        if not share_record:
            result = general_message(404, "share record not found", "分享流程不存在,请退出重试")
            return Response(result, status=404)
        if share_record.is_success or share_record.step >= 3:
            result = general_message(400, "share record is complete", "分享流程已经完成,请重新进行分享")
            return Response(result, status=400)

        if not request.data:
            result = general_message(400, "share info can not be empty", "分享信息不能为空")
            return Response(result, status=400)
        app_version_info = request.data.get("app_version_info", None)
        share_app_info = request.data.get("share_service_list", None)
        if not app_version_info or not share_app_info:
            result = general_message(400, "share info can not be empty", "分享应用基本信息或应用信息不能为空")
            return Response(result, status=400)
        if not app_version_info.get("app_model_id", None):
            result = general_message(400, "share app model id can not be empty", "分享应用信息不全")
            return Response(result, status=400)

        if share_app_info:
            for app in share_app_info:
                extend_method = app.get("extend_method", "")
                if is_singleton(extend_method):
                    extend_method_map = app.get("extend_method_map")
                    if extend_method_map and extend_method_map.get("max_node", 1) > 1:
                        result = general_message(400, "service type do not allow multiple node", "分享应用不支持多实例")
                        return Response(result, status=400)

        # 继续给app_template_incomplete赋值
        code, msg, bean = share_service.create_share_info(
            tenant=self.tenant,
            region_name=self.region_name,
            share_record=share_record,
            share_team=self.team,
            share_user=request.user,
            share_info=request.data,
            use_force=use_force)
        result = general_message(code, "create share info", msg, bean=bean)
        return Response(result, status=code)
示例#11
0
    def post(self, request, team_name, share_id, event_id, *args, **kwargs):
        """
        创建分享事件
        :param request:
        :param team_name:
        :param share_id:
        :param event_id:
        :param args:
        :param kwargs:
        :return:
        """
        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在,请退出重试")
                return Response(result, status=404)

            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,请重新进行分享")
                return Response(result, status=400)

            try:
                event = PluginShareRecordEvent.objects.get(record_id=share_id,
                                                           ID=event_id)

                status, msg, data = market_plugin_service.sync_event(
                    self.user.nick_name, self.response_region, team_name,
                    event)

                if status != 200:
                    result = general_message(status, "sync share event failed",
                                             msg)
                    return Response(result, status=status)

                result = general_message(status,
                                         "sync share event",
                                         msg,
                                         bean=data.to_dict())
                return Response(result, status=status)

            except PluginShareRecordEvent.DoesNotExist:
                result = general_message(404, "not exist", "分享事件不存在")
                return Response(result, status=404)

        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=500)
示例#12
0
    def post(self, request, team_name, share_id, *args, **kwargs):
        """
        生成分享应用实体,向数据中心发送分享任务
        ---
        parameter:
            - name: team_name
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: share_id
              description: 分享流程ID
              required: true
              type: string
              paramType: path
        """
        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在,请退出重试")
                return Response(result, status=404)
            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,请重新进行分享")
                return Response(result, status=400)

            if not request.data:
                result = general_message(400, "share info can not be empty",
                                         "分享信息不能为空")
                return Response(result, status=400)
            share_group_info = request.data.get("share_group_info", None)
            share_app_info = request.data.get("share_service_list", None)
            if not share_group_info or not share_app_info:
                result = general_message(400, "share info can not be empty",
                                         "分享应用基本信息或应用信息不能为空")
                return Response(result, status=400)
            # 继续给app_template_incomplete赋值
            code, msg, bean = share_service.create_share_info(
                share_record=share_record,
                share_team=self.team,
                share_user=request.user,
                share_info=request.data)
            result = general_message(code, "create share info", msg, bean=bean)
            return Response(result, status=code)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=500)
示例#13
0
    def get(self, request, team_name, share_id, event_id, *args, **kwargs):
        """
        获取插件分享事件列表
        :param request:
        :param team_name: 租户名
        :param share_id: 分享id
        :param event_id: 事件id
        :param args:
        :param kwargs:
        :return:
        """
        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在,请退出重试")
                return Response(result, status=404)

            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,请重新进行分享")
                return Response(result, status=400)

            try:
                event = PluginShareRecordEvent.objects.get(ID=event_id)
                if event.event_status == 'success':
                    result = general_message(200,
                                             "get sync share event result",
                                             "查询成功",
                                             bean=event.to_dict())
                    return Response(result, status=200)

                event_result = market_plugin_service.get_sync_event_result(
                    self.response_region, team_name, event)

                result = general_message(200,
                                         "get sync share event result",
                                         "查询成功",
                                         bean=event_result.to_dict())
                return Response(result, status=200)

            except PluginShareRecordEvent.DoesNotExist:
                result = general_message(404, "not exist", "分享事件不存在")
                return Response(result, status=404)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=500)
示例#14
0
    def post(self, request, team_name, share_id, *args, **kwargs):
        """
        创建插件分享
        ---
        parameter:
            - name: team_name
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: share_id
              description: 分享记录ID
              required: true
              type: string
              paramType: path
        """
        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在,请退出重试")
                return Response(result, status=404)

            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,请重新进行分享")
                return Response(result, status=400)

            if not request.data:
                result = general_message(400, "share info can not be empty",
                                         "分享信息不能为空")
                return Response(result, status=400)

            share_info = request.data

            status, msg, plugin = market_plugin_service.create_plugin_share_info(
                share_record, share_info, self.user.user_id, self.team,
                self.response_region)

            result = general_message(status,
                                     "create share info",
                                     msg,
                                     bean=plugin)
            return Response(result, status=status)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=500)
示例#15
0
    def delete(self, request, team_name, share_id, *args, **kwargs):
        """
        放弃插件分享
        ---
        parameter:
            - name: team_name
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: share_id
              description: 分享记录ID
              required: true
              type: string
              paramType: path
        """
        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在")
                return Response(result, status=404)

            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,无法放弃")
                return Response(result, status=404)

            share_plugin = share_repo.get_share_plugin(share_record.group_id)
            if share_plugin and share_plugin.is_complete:
                share_record.delete()
                PluginShareRecordEvent.objects.filter(
                    record_id=share_record.ID).delete()
                share_plugin.delete()
                return Response(general_message(200, msg='', msg_show=''), 200)

            PluginShareRecordEvent.objects.filter(
                record_id=share_record.ID).delete()
            share_record.delete()
            result = general_message(200, "delete success", "放弃成功")
            return Response(result, status=200)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=500)
示例#16
0
    def post(self, request, team_name, share_id, *args, **kwargs):
        """
        创建分享完成接口
        :param request:
        :param team_name:
        :param share_id:
        :param args:
        :param kwargs:
        :return:
        """
        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在,请退出重试")
                return Response(result, status=404)

            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,请重新进行分享")
                return Response(result, status=400)

            # 验证是否所有同步事件已完成
            count = PluginShareRecordEvent.objects. \
                filter(Q(record_id=share_id) & ~Q(event_status="success")).count()

            if count > 0:
                result = general_message(415, "share complete can not do",
                                         "插件同步未完成")
                return Response(result, status=415)

            app_market_url = market_plugin_service.plugin_share_completion(
                self.tenant, share_record, self.user.nick_name)
            result = general_message(200,
                                     "share complete",
                                     "插件分享完成",
                                     bean=share_record.to_dict(),
                                     app_market_url=app_market_url)
            return Response(result, status=200)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
示例#17
0
    def get(self, request, team_name, share_id, *args, **kwargs):
        """
        获取插件分享事件
        :param request:
        :param team_name:
        :param share_id:
        :param args:
        :param kwargs:
        :return:
        """
        share_record = share_service.get_service_share_record_by_ID(
            ID=share_id, team_name=team_name)
        if not share_record:
            result = general_message(404, "share record not found",
                                     "分享流程不存在,请退出重试")
            return Response(result, status=404)

        if share_record.is_success or share_record.step >= 3:
            result = general_message(400, "share record is complete",
                                     "分享流程已经完成,请重新进行分享")
            return Response(result, status=400)

        events = PluginShareRecordEvent.objects.filter(record_id=share_id)
        if not events:
            result = general_message(404, "not exist", "分享事件不存在")
            return Response(result, status=404)

        data = {"event_list": []}

        for event in events:
            if event.event_status != "success":
                data["is_compelte"] = False
            data["event_list"].append(event.to_dict())

        result = general_message(200, "query success", "获取成功", bean=data)
        return Response(result, status=200)
示例#18
0
 def post(self, request, team_name, share_id, *args, **kwargs):
     share_record = share_service.get_service_share_record_by_ID(
         ID=share_id, team_name=team_name)
     if not share_record:
         result = general_message(404, "share record not found",
                                  "分享流程不存在,请退出重试")
         return Response(result, status=404)
     if share_record.is_success or share_record.step >= 3:
         result = general_message(400, "share record is complete",
                                  "分享流程已经完成,请重新进行分享")
         return Response(result, status=400)
     # 验证是否所有同步事件已完成
     count = ServiceShareRecordEvent.objects.filter(
         Q(record_id=share_id) & ~Q(event_status="success")).count()
     if count > 0:
         result = general_message(415, "share complete can not do",
                                  "应用同步未全部完成")
         return Response(result, status=415)
     share_service.complete(share_record)
     result = general_message(200,
                              "share complete",
                              "应用分享完成",
                              bean=share_record.to_dict())
     return Response(result, status=200)
示例#19
0
    def post(self, request, team_name, share_id, *args, **kwargs):
        """
        生成分享应用实体,向数据中心发送分享任务
        ---
        parameter:
            - name: team_name
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: share_id
              description: 分享流程ID
              required: true
              type: string
              paramType: path
        """
        use_force = parse_argument(request,
                                   'use_force',
                                   default=False,
                                   value_type=bool)

        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在,请退出重试")
                return Response(result, status=404)
            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,请重新进行分享")
                return Response(result, status=400)

            if not request.data:
                result = general_message(400, "share info can not be empty",
                                         "分享信息不能为空")
                return Response(result, status=400)
            share_group_info = request.data.get("share_group_info", None)
            if share_group_info["scope"] == "goodrain":
                enterprise = enterprise_services.get_enterprise_by_enterprise_id(
                    self.team.enterprise_id)
                if not enterprise.is_active:
                    return Response(general_message(
                        10407, "enterprise is not active", "企业未激活"),
                                    status=403)
            share_app_info = request.data.get("share_service_list", None)
            if not share_group_info or not share_app_info:
                result = general_message(400, "share info can not be empty",
                                         "分享应用基本信息或应用信息不能为空")
                return Response(result, status=400)
            if not share_group_info.get("group_key", None):
                result = general_message(400,
                                         "share group key can not be empty",
                                         "分享应用信息不全")
                return Response(result, status=400)

            # 继续给app_template_incomplete赋值
            code, msg, bean = share_service.create_share_info(
                share_record=share_record,
                share_team=self.team,
                share_user=request.user,
                share_info=request.data,
                use_force=use_force)
            result = general_message(code, "create share info", msg, bean=bean)
            return Response(result, status=code)
        except ServiceHandleException as e:
            raise e
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=500)
示例#20
0
    def get(self, request, team_name, share_id, *args, **kwargs):
        """
        查询分享的插件信息
        ---
        parameter:
            - name: team_name
              description: 团队名
              required: true
              type: string
              paramType: path
            - name: share_id
              description: 分享记录ID
              required: true
              type: string
              paramType: path
        """
        team_id = self.team.tenant_id

        try:
            share_record = share_service.get_service_share_record_by_ID(
                ID=share_id, team_name=team_name)
            if not share_record:
                result = general_message(404, "share record not found",
                                         "分享流程不存在,请退出重试")
                return Response(result, status=404)
            if share_record.is_success or share_record.step >= 3:
                result = general_message(400, "share record is complete",
                                         "分享流程已经完成,请重新进行分享")
                return Response(result, status=400)

            share_plugin_info = dict()
            share_plugin = share_repo.get_share_plugin(share_record.group_id)

            if share_plugin:
                plugin_id = share_plugin.plugin_id
                share_plugin_info = share_plugin.to_dict()
                share_plugin_info["is_shared"] = True
                share_plugin_info.pop("update_time")
            else:
                plugin = plugin_repo.get_plugin_by_plugin_id(
                    team_id, share_record.group_id)
                if not plugin:
                    result = general_message(404,
                                             msg="plugin not exist",
                                             msg_show="插件不存在")
                    return Response(result, status=400)

                plugin_id = plugin.plugin_id

                share_plugin_info["category"] = plugin.category
                share_plugin_info["plugin_key"] = make_uuid()
                share_plugin_info["plugin_id"] = plugin_id
                share_plugin_info["plugin_name"] = plugin.plugin_alias
                share_plugin_info["version"] = "1.0"
                share_plugin_info["desc"] = "This is a default description."
                share_plugin_info["scope"] = "team"
                share_plugin_info["share_id"] = share_record.group_id
                share_plugin_info["pic"] = ""
                share_plugin_info["share_user"] = str(self.user.user_id)
                share_plugin_info["share_team"] = team_name
                share_plugin_info["is_shared"] = False

                plugin_version = plugin_svc.get_tenant_plugin_newest_versions(
                    self.response_region, self.tenant, plugin_id)

                share_plugin_info["build_version"] = plugin_version[
                    0].build_version

                config_groups = []
                for group in plugin_repo.get_plugin_config_groups(
                        plugin_id, plugin_version[0].build_version):
                    group_map = group.to_dict()

                    items = plugin_svc.get_config_items_by_id_metadata_and_version(
                        group.plugin_id, group.build_version,
                        group.service_meta_type)

                    config_items = []
                    for item in items:
                        config_items.append(item.to_dict())

                    group_map['config_items'] = config_items
                    config_groups.append(group_map)

                share_plugin_info["config_groups"] = config_groups

            return Response(
                general_message(200,
                                "",
                                "",
                                bean={'share_plugin_info': share_plugin_info}),
                200)
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            return Response(result, status=500)
示例#21
0
 def get(self, request, team_name, share_id, *args, **kwargs):
     """
     查询分享的所有应用信息和插件信息
     ---
     parameter:
         - name: team_name
           description: 团队名
           required: true
           type: string
           paramType: path
         - name: share_id
           description: 分享订单ID
           required: true
           type: string
           paramType: path
     """
     try:
         share_record = share_service.get_service_share_record_by_ID(
             ID=share_id, team_name=team_name)
         if not share_record:
             result = general_message(404, "share record not found",
                                      "分享流程不存在,请退出重试")
             return Response(result, status=404)
         if share_record.is_success or share_record.step >= 3:
             result = general_message(400, "share record is complete",
                                      "分享流程已经完成,请重新进行分享")
             return Response(result, status=400)
         # 获取分享应用组基本信息
         data = dict()
         share_group_info = dict()
         share_group = share_service.check_whether_have_share_history(
             group_id=share_record.group_id)
         if share_group:
             share_group_info["group_key"] = share_group.group_key
             share_group_info["group_name"] = share_group.group_name
             share_group_info["version"] = share_group.version
             share_group_info["describe"] = share_group.describe
             share_group_info["scope"] = share_group.scope
             share_group_info["share_id"] = share_group.ID
             share_group_info["pic"] = share_group.pic
             share_group_info["share_team"] = share_group.share_team
             share_group_info["share_user"] = share_group.share_user
             share_group_info["is_shared"] = True
             data["share_group_info"] = share_group_info
         else:
             try:
                 user = user_services.get_user_by_user_name(
                     user_name=request.user)
                 if not user:
                     result = general_message(400, "user failed",
                                              "数据紊乱,非当前用户操作页面")
                     return Response(result, status=400)
             except UserNotExistError as e:
                 result = general_message(400, e.message, "用户不存在")
                 return Response(result, status=400)
             code, msg, group = group_service.get_group_by_id(
                 tenant=self.team,
                 region=self.response_region,
                 group_id=share_record.group_id)
             if code == 200:
                 share_group_info["group_key"] = make_uuid()
                 share_group_info["group_name"] = group.get("group_name")
                 share_group_info["version"] = 'v1.0'
                 share_group_info[
                     "describe"] = 'This is a default description.'
                 share_group_info["scope"] = 'team'
                 share_group_info["share_id"] = share_record.group_id
                 share_group_info["pic"] = ''
                 share_group_info["share_team"] = team_name
                 share_group_info["share_user"] = str(user.user_id)
                 share_group_info["is_shared"] = False
                 data["share_group_info"] = share_group_info
             else:
                 result = general_message(code=code,
                                          msg="failed",
                                          msg_show=msg)
                 return Response(result, status=code)
         service_info_list = share_service.query_share_service_info(
             team=self.team, group_id=share_record.group_id)
         data["share_service_list"] = service_info_list
         plugins = share_service.get_group_services_used_plugins(
             group_id=share_record.group_id)
         data["share_plugin_list"] = plugins
         result = general_message(200, "query success", "获取成功", bean=data)
         return Response(result, status=200)
     except ServiceHandleException as e:
         raise e
     except Exception as e:
         logger.exception(e)
         result = error_message(e.message)
         return Response(result, status=500)