向server端轮询扫描结果 :param team_name: :param org_sid: :param dog_server: :param server_url: :param repo_id: :param proj_id: :param scan_id: :param timeout: 查询超时 :param job_web_url: 任务详情页面url :return: status, url, , m
(dog_server, server_url, repo_id, proj_id, scan_id, timeout,
org_sid, team_name, job_web_url, fix_result)
| 82 | |
| 83 | @staticmethod |
| 84 | def query_result(dog_server, server_url, repo_id, proj_id, scan_id, timeout, |
| 85 | org_sid, team_name, job_web_url, fix_result): |
| 86 | """ |
| 87 | 向server端轮询扫描结果 |
| 88 | :param team_name: |
| 89 | :param org_sid: |
| 90 | :param dog_server: |
| 91 | :param server_url: |
| 92 | :param repo_id: |
| 93 | :param proj_id: |
| 94 | :param scan_id: |
| 95 | :param timeout: 查询超时 |
| 96 | :param job_web_url: 任务详情页面url |
| 97 | :return: status, url, , message |
| 98 | { |
| 99 | "status": "success|error", |
| 100 | "error_code": 错误码, |
| 101 | "url": "result url", |
| 102 | "text": "simple msg", |
| 103 | "description": "message", |
| 104 | "stat_report": {"current_scan": xx, "total": xx} | {}, |
| 105 | "scan_report": {...} |
| 106 | } |
| 107 | """ |
| 108 | LogPrinter.info("query result from server ...") |
| 109 | # 等待数据入库后再开始轮询结果 |
| 110 | time.sleep(settings.RESULT_INTO_DB_TIME) |
| 111 | |
| 112 | # 转换成前端页面url,供展示用 |
| 113 | front_end_url = UrlMap.get_frontend_url(server_url) |
| 114 | |
| 115 | scan_history_url = UrlMgr(front_end_url, repo_id, proj_id, org_sid=org_sid, |
| 116 | team_name=team_name).get_scan_history_url() |
| 117 | url = job_web_url if job_web_url else scan_history_url |
| 118 | |
| 119 | start_time = time.time() |
| 120 | while True: |
| 121 | # 判断是否超时 |
| 122 | cur_time = time.time() |
| 123 | if cur_time - start_time > timeout: |
| 124 | return { |
| 125 | "status": StatusType.ERROR, |
| 126 | "error_code": E_NODE_TASK_EXPIRED, |
| 127 | "url": url, |
| 128 | "text": "超时", |
| 129 | "description": "获取扫描结果超时,超时限制为%s秒,请查看任务详情:%s" % (timeout, url), |
| 130 | # "stat_report": {}, |
| 131 | "scan_report": {} |
| 132 | } |
| 133 | |
| 134 | # 向server查询扫描结果 |
| 135 | result = dog_server.get_scan_result(proj_id, scan_id, repo_id, org_sid, team_name) |
| 136 | result_code = result["result_code"] |
| 137 | |
| 138 | # 有更新的任务执行完成了,本次扫描取消,取更新的结果(任务重定向结果码从303调整为2) |
| 139 | if result_code == 303 or result_code == 2: |
| 140 | result_msg = result["result_msg"] |
| 141 | result_msg = json.loads(result_msg) |
no test coverage detected