0609 ljc sca模块修改
This commit is contained in:
parent
622567d385
commit
c5563ad8e0
@ -18,7 +18,7 @@ public final class PageResult<T> implements Serializable {
|
||||
private Long total;
|
||||
|
||||
@Schema(description = "分页查询页数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Long pageNun;
|
||||
private Long pageNum;
|
||||
|
||||
@Schema(description = "每页条数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Long pageSize;
|
||||
@ -31,10 +31,10 @@ public final class PageResult<T> implements Serializable {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public PageResult(List<T> list, Long total , Long pageNun, Long pageSize) {
|
||||
public PageResult(List<T> list, Long total , Long pageNum, Long pageSize) {
|
||||
this.list = list;
|
||||
this.total = total;
|
||||
this.pageNun = pageNun;
|
||||
this.pageNum = pageNum;
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cd.casic.ci.api;
|
||||
|
||||
|
||||
import cd.casic.ci.process.dal.req.report.ReportAssetTaskReq;
|
||||
import cd.casic.ci.process.dal.req.report.ReportDeleteReq;
|
||||
import cd.casic.ci.process.dal.resp.report.ReportResp;
|
||||
import cd.casic.ci.process.process.dataObject.base.BaseIdPageReq;
|
||||
@ -18,7 +19,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -63,5 +63,12 @@ public class ReportController {
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(path="/assetReportTask")
|
||||
public CommonResult<ReportResp> assetReportTask(@RequestBody @Valid ReportAssetTaskReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
|
||||
ReportResp reportResp = reportService.assetReportTask(req);
|
||||
|
||||
return CommonResult.success(reportResp);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,47 @@
|
||||
package cd.casic.ci.process.dal.req.report;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName PipelineReq
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/10 10:53
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class ReportAdvancedSearch {
|
||||
//组件风险等级 1-严重 2-高危 3-中危 4-低危 5-无漏洞
|
||||
private List<Integer> componentSecurityLevelList;
|
||||
|
||||
//组件状态 0-黑名单组件 1-白名单组件 2-未标记 4-符合基线范围组件 5-不符合基线范围组件
|
||||
private List<Integer> componentStatusList;
|
||||
|
||||
//许可证风险等级 1-高风险 2-中风险 3-低风险
|
||||
private List<Integer> licenseSecurityLevelList;
|
||||
|
||||
//许可证状态 0-黑名单许可证 1-白名单许可证 2-未标记 6-误报
|
||||
private List<Integer> licenseStatusList;
|
||||
|
||||
//漏洞风险等级 1-严重 2-高危 3-中危 4-低危 5-无等级
|
||||
private List<Integer> vulSecurityLevelList;
|
||||
|
||||
//漏洞状态 0-黑名单漏洞 1-白名单漏洞 2-未标记 6-误报
|
||||
private List<Integer> vulStatusList;
|
||||
|
||||
//CVSS分数逻辑操作符:and or,用于连接CVSS V2和V3分数的条件,即是V2 and V3还是V2 or V3
|
||||
private String cvssLogicalOperator;
|
||||
|
||||
//cvss v2分数最低值,范围0~10
|
||||
private Integer cvssV2Score;
|
||||
|
||||
//cvss v3分数最低值,范围0~10
|
||||
private Integer cvssV3Score;
|
||||
|
||||
//依赖方式 0-未设置 1-直接依赖 2-间接依赖
|
||||
private Integer dependType;
|
||||
|
||||
//漏洞利用难度,可选-2-未知 0-困难 1-容易 2-一般 不传默认为空
|
||||
private Integer exploitLevelId;
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package cd.casic.ci.process.dal.req.report;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @ClassName PipelineReq
|
||||
* @Author hopeli
|
||||
* @Date 2025/5/10 10:53
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class ReportAssetTaskReq {
|
||||
private ReportAdvancedSearch advancedSearch;
|
||||
|
||||
//报告维度 5-组件,默认为5-组件
|
||||
private Integer dimension;
|
||||
|
||||
//报告模板id,可选,默认为默认模板
|
||||
private Integer reportTemplateId;
|
||||
|
||||
//检测任务ID
|
||||
private Integer scaTaskId;
|
||||
|
||||
//报告类型 5-excel 1-word 2-pdf 3-html 4-json,默认为5-excel
|
||||
private Integer type;
|
||||
|
||||
//报告名称,如果不填则会自动生成
|
||||
private String reportName;
|
||||
}
|
@ -81,5 +81,6 @@ public class ReportResp {
|
||||
|
||||
private Integer fail;
|
||||
private Integer success;
|
||||
private Integer code;
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cd.casic.ci.process.dal.resp.target;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author HopeLi
|
||||
@ -36,6 +37,8 @@ public class TargetManagerResp{
|
||||
*/
|
||||
private String targetDesc;
|
||||
|
||||
private List<TargetVersionResp> versionList;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
@ -126,21 +126,24 @@ public class ApplicationWorker extends HttpWorker {
|
||||
append(context,"===============SCA上传成功=================");
|
||||
JSONObject data = response.getJSONObject("data");
|
||||
Integer scaTaskId = data.getInteger("scaTaskId");
|
||||
append(context,"任务执行成功,scaTaskId为" + scaTaskId);
|
||||
|
||||
//更新scaTaskId数据到task表
|
||||
applicationConfigInfo.put("scaTaskId",scaTaskId);
|
||||
pipTask.setTaskProperties(applicationConfigInfo);
|
||||
pipTaskDao.updateById(pipTask);
|
||||
pollTaskStatus(restTemplate, scaTaskId);
|
||||
pollTaskStatus(restTemplate, scaTaskId,context);
|
||||
} else if (message.equals("应用已经存在")) {
|
||||
append(context,message);
|
||||
Integer oldScaTaskId = (Integer) applicationConfigInfo.get("scaTaskId");
|
||||
Integer oldApplicationId = (Integer) applicationConfigInfo.get("applicationId");
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId);
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId,context);
|
||||
append(context,"应用已经存在,开始重新启动任务,scaTaskId为" + oldScaTaskId);
|
||||
if (restartResult != 0) {
|
||||
append(context,"重新启动任务失败");
|
||||
return;
|
||||
}
|
||||
pollTaskStatus(restTemplate, oldScaTaskId);
|
||||
pollTaskStatus(restTemplate, oldScaTaskId,context);
|
||||
} else {
|
||||
append(context,"==================SCA接口异常,调用失败=================");
|
||||
append(context,message);
|
||||
@ -176,11 +179,10 @@ public class ApplicationWorker extends HttpWorker {
|
||||
* @param restTemplate RestTemplate
|
||||
* @param scaTaskId 任务ID
|
||||
*/
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId) {
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId,BaseRunContext context) {
|
||||
int currentPollingTimes = 0;
|
||||
while (currentPollingTimes < MAX_POLLING_TIMES) {
|
||||
try {
|
||||
// 根据任务 id 获取任务状态
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("OpenApiUserToken", ConstantContextHolder.getScaToken());
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(null, headers);
|
||||
@ -190,18 +192,23 @@ public class ApplicationWorker extends HttpWorker {
|
||||
if (Objects.requireNonNull(response.getBody()).getString("message").equals("success")) {
|
||||
//"status": 5, //状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中
|
||||
int status = response.getBody().getJSONObject("data").getInteger("status");
|
||||
append(context,"\"状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中\"");
|
||||
log.info("当前任务状态: " + status);
|
||||
append(context,"当前任务状态: " + status);
|
||||
if (status == 5) {
|
||||
System.out.println("任务已完成,停止轮询。");
|
||||
log.info("任务已完成,停止轮询。");
|
||||
append(context,"任务已完成,停止状态获取。" );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log.error("获取任务状态失败: " + response.getBody().getString("message"));
|
||||
append(context,"获取任务状态失败" );
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取任务状态时发生错误: " + e.getMessage());
|
||||
append(context,"获取任务状态时发生错误" );
|
||||
}
|
||||
try {
|
||||
// 轮询间隔 5 秒
|
||||
@ -215,14 +222,13 @@ public class ApplicationWorker extends HttpWorker {
|
||||
System.out.println("停止轮询");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重新检测接口
|
||||
*
|
||||
* @param restTemplate
|
||||
* @param applicationId
|
||||
*/
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId) {
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId, BaseRunContext context) {
|
||||
try {
|
||||
String url = ConstantContextHolder.getScaIp() + "/openapi/v1/task/batch/detect";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@ -233,19 +239,22 @@ public class ApplicationWorker extends HttpWorker {
|
||||
param.put("applicationIds", Arrays.asList(applicationId));
|
||||
String s = JSON.toJSONString(param);
|
||||
HttpEntity<String> formEntry = new HttpEntity<>(s, headers);
|
||||
//
|
||||
|
||||
JSONObject res = restTemplate.postForObject(url, formEntry, JSONObject.class);
|
||||
if (res.getString("message").equals("success")) {
|
||||
log.info("重新检测成功");
|
||||
append(context,"重新检测成功");
|
||||
return 0;
|
||||
} else {
|
||||
log.error("重新检测失败");
|
||||
log.error(res.getString("message"));
|
||||
append(context,"重新检测失败:" + res.getString("message"));
|
||||
return -1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("重新检测失败");
|
||||
log.error(e.getMessage());
|
||||
append(context,"重新检测失败:" + e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package cd.casic.ci.process.engine.worker;
|
||||
|
||||
import cd.casic.ci.process.common.WorkAtom;
|
||||
import cd.casic.ci.process.engine.context.ConstantContextHolder;
|
||||
import cd.casic.ci.process.engine.runContext.BaseRunContext;
|
||||
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||
import cd.casic.ci.process.engine.worker.base.HttpWorker;
|
||||
import cd.casic.ci.process.process.dal.pipeline.PipTaskDao;
|
||||
@ -75,6 +76,7 @@ public class CodingWorker extends HttpWorker {
|
||||
Integer type = Integer.valueOf((String) codingConfigInfo.get("type"));
|
||||
vcsRepo.put("type", type);
|
||||
if (REPO_TYPE_GIT.equals(type)) {
|
||||
append(context,"===============SCA-GIT仓库配置=================");
|
||||
HashMap<String,String> gitVCSAssetRepo = new HashMap<>();
|
||||
vcsRepo.put("gitVCSAssetRepo",gitVCSAssetRepo);
|
||||
gitVCSAssetRepo.put("url", (String) codingConfigInfo.get("url"));
|
||||
@ -92,29 +94,34 @@ public class CodingWorker extends HttpWorker {
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(bodyStr, headers);
|
||||
// 4. 发送请求并获取响应
|
||||
log.info("SCA上传接口:" + scaUploadUrl);
|
||||
append(context,"SCA上传接口:" + scaUploadUrl);
|
||||
JSONObject response = restTemplate.postForObject(scaUploadUrl, requestEntity, JSONObject.class);
|
||||
append(context,"SCA上传接口响应:" + response);
|
||||
|
||||
if (response.getString("message").equals("success")) {
|
||||
append(context,"===============SCA上传成功=================");
|
||||
JSONObject data = response.getJSONObject("data");
|
||||
Integer scaTaskId = data.getInteger("scaTaskId");
|
||||
append(context,"SCA-代码仓库管理节点执行成功,SCA任务ID为:" + scaTaskId);
|
||||
|
||||
//更新scaTaskId数据到task表
|
||||
codingConfigInfo.put("scaTaskId",scaTaskId);
|
||||
pipTask.setTaskProperties(codingConfigInfo);
|
||||
pipTaskDao.updateById(pipTask);
|
||||
//轮询请求状态
|
||||
pollTaskStatus(restTemplate, scaTaskId);
|
||||
pollTaskStatus(restTemplate, scaTaskId,context);
|
||||
} else if (response.getString("message").equals("应用已经存在")){
|
||||
append(context,response.getString("message"));
|
||||
Integer oldScaTaskId = (Integer) codingConfigInfo.get("scaTaskId");
|
||||
Integer oldApplicationId = (Integer) codingConfigInfo.get("applicationId");
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId);
|
||||
append(context,"SCA-代码仓库管理节点应用已存在,正在准备重试,SCA任务ID为:" + oldScaTaskId);
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId,context);
|
||||
if (restartResult != 0) {
|
||||
append(context,"SCA-代码仓库管理节点重试失败,请检查当前节点配置!");
|
||||
localVariables.put("statusCode", "-1");
|
||||
}
|
||||
//轮询请求状态
|
||||
pollTaskStatus(restTemplate, oldScaTaskId);
|
||||
pollTaskStatus(restTemplate, oldScaTaskId,context);
|
||||
} else {
|
||||
//基于第三方文档表明500状态基本属于无镜像配置,对比失败,于是打印日志为无法对比镜像
|
||||
append(context,"==================SCA校验失败=================");
|
||||
@ -152,7 +159,7 @@ public class CodingWorker extends HttpWorker {
|
||||
* @param restTemplate
|
||||
* @param scaTaskId
|
||||
*/
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId) {
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId,BaseRunContext context) {
|
||||
int currentPollingTimes = 0;
|
||||
while (currentPollingTimes < MAX_POLLING_TIMES) {
|
||||
try {
|
||||
@ -165,18 +172,23 @@ public class CodingWorker extends HttpWorker {
|
||||
if (Objects.requireNonNull(response.getBody()).getString("message").equals("success")) {
|
||||
//"status": 5, //状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中
|
||||
int status = response.getBody().getJSONObject("data").getInteger("status");
|
||||
append(context,"\"状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中\"");
|
||||
log.info("当前任务状态: " + status);
|
||||
append(context,"当前任务状态: " + status);
|
||||
if (status == 5) {
|
||||
System.out.println("任务已完成,停止轮询。");
|
||||
log.info("任务已完成,停止轮询。");
|
||||
append(context,"任务已完成,停止状态获取。" );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log.error("获取任务状态失败: " + response.getBody().getString("message"));
|
||||
append(context,"获取任务状态失败" );
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取任务状态时发生错误: " + e.getMessage());
|
||||
append(context,"获取任务状态时发生错误" );
|
||||
}
|
||||
try {
|
||||
// 轮询间隔 5 秒
|
||||
@ -196,7 +208,7 @@ public class CodingWorker extends HttpWorker {
|
||||
* @param restTemplate
|
||||
* @param applicationId
|
||||
*/
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId) {
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId, BaseRunContext context) {
|
||||
try {
|
||||
String url = ConstantContextHolder.getScaIp() + "/openapi/v1/task/batch/detect";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@ -211,15 +223,18 @@ public class CodingWorker extends HttpWorker {
|
||||
JSONObject res = restTemplate.postForObject(url, formEntry, JSONObject.class);
|
||||
if (res.getString("message").equals("success")) {
|
||||
log.info("重新检测成功");
|
||||
append(context,"重新检测成功");
|
||||
return 0;
|
||||
} else {
|
||||
log.error("重新检测失败");
|
||||
log.error(res.getString("message"));
|
||||
append(context,"重新检测失败:" + res.getString("message"));
|
||||
return -1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("重新检测失败");
|
||||
log.error(e.getMessage());
|
||||
append(context,"重新检测失败:" + e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -134,22 +134,25 @@ public class ScaBinaryWorker extends HttpWorker {
|
||||
append(context,"===============SCA上传成功=================");
|
||||
JSONObject data = response.getJSONObject("data");
|
||||
Integer scaTaskId = data.getInteger("scaTaskId");
|
||||
append(context,"SCA-BINARY节点上传成功,SCA任务ID为:" + scaTaskId);
|
||||
|
||||
//更新scaTaskId数据到task表
|
||||
scaBinaryConfigInfo.put("scaTaskId",scaTaskId);
|
||||
pipTask.setTaskProperties(scaBinaryConfigInfo);
|
||||
pipTaskDao.updateById(pipTask);
|
||||
|
||||
pollTaskStatus(restTemplate, scaTaskId);
|
||||
pollTaskStatus(restTemplate, scaTaskId,context);
|
||||
} else if (message.equals("应用已经存在")) {
|
||||
append(context,message);
|
||||
Integer oldScaTaskId = (Integer) scaBinaryConfigInfo.get("scaTaskId");
|
||||
Integer oldApplicationId = (Integer) scaBinaryConfigInfo.get("applicationId");
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId);
|
||||
append(context,"SCA-BINARY节点应用已经存在,开始重新启动任务,当前scaTaskId为" + oldApplicationId);
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId,context);
|
||||
if (restartResult != 0) {
|
||||
append(context,"重新启动任务失败");
|
||||
return;
|
||||
}
|
||||
pollTaskStatus(restTemplate, oldScaTaskId);
|
||||
pollTaskStatus(restTemplate, oldScaTaskId, context);
|
||||
} else {
|
||||
append(context,"==================SCA接口异常,调用失败=================");
|
||||
append(context,message);
|
||||
@ -184,8 +187,9 @@ public class ScaBinaryWorker extends HttpWorker {
|
||||
*
|
||||
* @param restTemplate
|
||||
* @param scaTaskId
|
||||
* @param context
|
||||
*/
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId) {
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId, BaseRunContext context) {
|
||||
int currentPollingTimes = 0;
|
||||
while (currentPollingTimes < MAX_POLLING_TIMES) {
|
||||
try {
|
||||
@ -198,18 +202,23 @@ public class ScaBinaryWorker extends HttpWorker {
|
||||
if (Objects.requireNonNull(response.getBody()).getString("message").equals("success")) {
|
||||
//"status": 5, //状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中
|
||||
int status = response.getBody().getJSONObject("data").getInteger("status");
|
||||
append(context,"\"状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中\"");
|
||||
log.info("当前任务状态: " + status);
|
||||
append(context,"当前任务状态: " + status);
|
||||
if (status == 5) {
|
||||
System.out.println("任务已完成,停止轮询。");
|
||||
log.info("任务已完成,停止轮询。");
|
||||
append(context,"任务已完成,停止状态获取。" );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log.error("获取任务状态失败: " + response.getBody().getString("message"));
|
||||
append(context,"获取任务状态失败" );
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取任务状态时发生错误: " + e.getMessage());
|
||||
append(context,"获取任务状态时发生错误" );
|
||||
}
|
||||
try {
|
||||
// 轮询间隔 5 秒
|
||||
@ -228,8 +237,9 @@ public class ScaBinaryWorker extends HttpWorker {
|
||||
*
|
||||
* @param restTemplate
|
||||
* @param applicationId
|
||||
* @param context
|
||||
*/
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId) {
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId, BaseRunContext context) {
|
||||
try {
|
||||
String url = ConstantContextHolder.getScaIp() + "/openapi/v1/task/batch/detect";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@ -244,15 +254,18 @@ public class ScaBinaryWorker extends HttpWorker {
|
||||
JSONObject res = restTemplate.postForObject(url, formEntry, JSONObject.class);
|
||||
if (res.getString("message").equals("success")) {
|
||||
log.info("重新检测成功");
|
||||
append(context,"重新检测成功");
|
||||
return 0;
|
||||
} else {
|
||||
log.error("重新检测失败");
|
||||
log.error(res.getString("message"));
|
||||
append(context,"重新检测失败:" + res.getString("message"));
|
||||
return -1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("重新检测失败");
|
||||
log.error(e.getMessage());
|
||||
append(context,"重新检测失败:" + e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -131,22 +131,25 @@ public class ScaMirrorWorker extends HttpWorker {
|
||||
append(context,"===============SCA上传成功=================");
|
||||
JSONObject data = response.getJSONObject("data");
|
||||
Integer scaTaskId = data.getInteger("scaTaskId");
|
||||
append(context,"SCA-MIRROR节点执行成功,SCA任务ID为:" + scaTaskId);
|
||||
|
||||
//更新scaTaskId数据到task表
|
||||
scaMirrorConfigInfo.put("scaTaskId",scaTaskId);
|
||||
pipTask.setTaskProperties(scaMirrorConfigInfo);
|
||||
pipTaskDao.updateById(pipTask);
|
||||
|
||||
pollTaskStatus(restTemplate, scaTaskId);
|
||||
pollTaskStatus(restTemplate, scaTaskId,context);
|
||||
} else if (message.equals("应用已经存在")) {
|
||||
append(context,message);
|
||||
Integer oldScaTaskId = (Integer) scaMirrorConfigInfo.get("scaTaskId");
|
||||
Integer oldApplicationId = (Integer) scaMirrorConfigInfo.get("applicationId");
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId);
|
||||
append(context,"SCA-MIRROR节点应用已存在,重新开始执行检测任务,SCA任务ID为:" + oldScaTaskId);
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId,context);
|
||||
if (restartResult != 0) {
|
||||
append(context,"SCA-MIRROR节点执行失败");
|
||||
return;
|
||||
}
|
||||
pollTaskStatus(restTemplate, oldScaTaskId);
|
||||
pollTaskStatus(restTemplate, oldScaTaskId,context);
|
||||
} else {
|
||||
append(context,"==================SCA接口异常,调用失败=================");
|
||||
append(context,message);
|
||||
@ -189,7 +192,7 @@ public class ScaMirrorWorker extends HttpWorker {
|
||||
* @param restTemplate
|
||||
* @param scaTaskId
|
||||
*/
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId) {
|
||||
public void pollTaskStatus(RestTemplate restTemplate, Integer scaTaskId,BaseRunContext context) {
|
||||
int currentPollingTimes = 0;
|
||||
while (currentPollingTimes < MAX_POLLING_TIMES) {
|
||||
try {
|
||||
@ -202,18 +205,23 @@ public class ScaMirrorWorker extends HttpWorker {
|
||||
if (Objects.requireNonNull(response.getBody()).getString("message").equals("success")) {
|
||||
//"status": 5, //状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中
|
||||
int status = response.getBody().getJSONObject("data").getInteger("status");
|
||||
append(context,"\"状态 0-未审计 1-未检测 2-排队中 3-检测中 4-检测暂停 5-检测完成 6-检测超时 7-手动停止 8-检测异常 9-已删除 10-拉取中 11-停止中 12-下载中\"");
|
||||
log.info("当前任务状态: " + status);
|
||||
append(context,"当前任务状态: " + status);
|
||||
if (status == 5) {
|
||||
System.out.println("任务已完成,停止轮询。");
|
||||
log.info("任务已完成,停止轮询。");
|
||||
append(context,"任务已完成,停止状态获取。" );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log.error("获取任务状态失败: " + response.getBody().getString("message"));
|
||||
append(context,"获取任务状态失败" );
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取任务状态时发生错误: " + e.getMessage());
|
||||
append(context,"获取任务状态时发生错误" );
|
||||
}
|
||||
try {
|
||||
// 轮询间隔 5 秒
|
||||
@ -233,7 +241,7 @@ public class ScaMirrorWorker extends HttpWorker {
|
||||
* @param restTemplate
|
||||
* @param applicationId
|
||||
*/
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId) {
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId, BaseRunContext context) {
|
||||
try {
|
||||
String url = ConstantContextHolder.getScaIp() + "/openapi/v1/task/batch/detect";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@ -248,15 +256,18 @@ public class ScaMirrorWorker extends HttpWorker {
|
||||
JSONObject res = restTemplate.postForObject(url, formEntry, JSONObject.class);
|
||||
if (res.getString("message").equals("success")) {
|
||||
log.info("重新检测成功");
|
||||
append(context,"重新检测成功");
|
||||
return 0;
|
||||
} else {
|
||||
log.error("重新检测失败");
|
||||
log.error(res.getString("message"));
|
||||
append(context,"重新检测失败:" + res.getString("message"));
|
||||
return -1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("重新检测失败");
|
||||
log.error(e.getMessage());
|
||||
append(context,"重新检测失败:" + e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ public class ScaSbomWorker extends HttpWorker {
|
||||
Integer oldApplicationId = (Integer) scaSbomConfigInfo.get("applicationId");
|
||||
append(context,"跳过上传步骤,获取scaTaskId:"+oldScaTaskId);
|
||||
append(context,"重新运行上一次的,scaTaskId:"+oldScaTaskId);
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId);
|
||||
int restartResult = reStartTask(restTemplate, oldApplicationId,context);
|
||||
if (restartResult != 0) {
|
||||
return;
|
||||
}
|
||||
@ -230,7 +230,7 @@ public class ScaSbomWorker extends HttpWorker {
|
||||
* @param restTemplate
|
||||
* @param applicationId
|
||||
*/
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId) {
|
||||
public int reStartTask(RestTemplate restTemplate, Integer applicationId, BaseRunContext context) {
|
||||
try {
|
||||
String url = ConstantContextHolder.getScaIp() + "/openapi/v1/task/batch/detect";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
@ -245,15 +245,18 @@ public class ScaSbomWorker extends HttpWorker {
|
||||
JSONObject res = restTemplate.postForObject(url, formEntry, JSONObject.class);
|
||||
if (res.getString("message").equals("success")) {
|
||||
log.info("重新检测成功");
|
||||
append(context,"重新检测成功");
|
||||
return 0;
|
||||
} else {
|
||||
log.error("重新检测失败");
|
||||
log.error(res.getString("message"));
|
||||
append(context,"重新检测失败:" + res.getString("message"));
|
||||
return -1;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("重新检测失败");
|
||||
log.error(e.getMessage());
|
||||
append(context,"重新检测失败:" + e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cd.casic.ci.process.process.service.report;
|
||||
|
||||
import cd.casic.ci.process.dal.req.report.ReportAssetTaskReq;
|
||||
import cd.casic.ci.process.dal.req.report.ReportDeleteReq;
|
||||
import cd.casic.ci.process.dal.resp.report.ReportResp;
|
||||
import cd.casic.ci.process.process.dataObject.base.BaseIdPageReq;
|
||||
@ -8,7 +9,6 @@ import cd.casic.framework.commons.pojo.PageResult;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@ -26,4 +26,6 @@ public interface ReportService{
|
||||
ReportResp deleteReport(@Valid ReportDeleteReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
|
||||
ResponseEntity<String> downLoadReport(@Valid BaseIdReq req) throws Exception;
|
||||
|
||||
ReportResp assetReportTask(@Valid ReportAssetTaskReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cd.casic.ci.process.process.service.report.impl;
|
||||
|
||||
import cd.casic.ci.process.dal.req.report.ReportAssetTaskReq;
|
||||
import cd.casic.ci.process.dal.req.report.ReportDeleteReq;
|
||||
import cd.casic.ci.process.dal.resp.report.ReportResp;
|
||||
import cd.casic.ci.process.engine.context.ConstantContextHolder;
|
||||
@ -11,22 +12,20 @@ import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||
import cd.casic.framework.commons.pojo.PageResult;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.activation.MimeType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tika.Tika;
|
||||
import org.apache.tika.metadata.Metadata;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cd.casic.ci.process.engine.worker.base.HttpWorker.getRestTemplateWithoutSANCheck;
|
||||
|
||||
@ -134,7 +133,33 @@ public class ReportServiceImpl implements ReportService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReportResp assetReportTask(ReportAssetTaskReq req) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
|
||||
if (ObjectUtils.isEmpty(req.getScaTaskId())){
|
||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"任务ID不能为空");
|
||||
}
|
||||
RestTemplate restTemplate = getRestTemplateWithoutSANCheck();
|
||||
String reportDeleteUrl = ConstantContextHolder.getScaIp() + "/openapi/v1/asset/report/task";
|
||||
String body = buildAssetRequestBody(req);
|
||||
HttpHeaders headers = createHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<String> requestEntity = new HttpEntity<>(body, headers);
|
||||
|
||||
log.info("根据任务ID列表生成检测报告:" + reportDeleteUrl);
|
||||
JSONObject response = restTemplate.postForObject(reportDeleteUrl, requestEntity, JSONObject.class);
|
||||
String message = response.getString("message");
|
||||
if (message.equals("success")) {
|
||||
ReportResp reportResp = new ReportResp();
|
||||
log.info("===============根据任务ID列表生成检测报告成功=================");
|
||||
setReportAssetResp(response.getString("xmTraceId"),reportResp);
|
||||
|
||||
return reportResp;
|
||||
|
||||
} else {
|
||||
log.error("===============根据任务ID列表生成检测报告失败=================");
|
||||
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"根据任务ID列表生成检测报告失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private HttpHeaders createHeaders() {
|
||||
@ -176,6 +201,23 @@ public class ReportServiceImpl implements ReportService {
|
||||
}
|
||||
|
||||
|
||||
private String buildAssetRequestBody(ReportAssetTaskReq req) {
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
if (req.getAdvancedSearch() != null) {
|
||||
json.put("advancedSearch", JSONObject.toJSONString(req.getAdvancedSearch()));
|
||||
|
||||
}
|
||||
json.put("dimension", req.getDimension());
|
||||
json.put("reportTemplateId", req.getReportTemplateId());
|
||||
json.put("type", req.getType());
|
||||
json.put("reportName", req.getReportName());
|
||||
json.put("scaTaskId", req.getScaTaskId());
|
||||
|
||||
return json.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
private void setReportFindResp(JSONObject data, String xmTraceId, List<ReportResp> respList) {
|
||||
JSONArray records = data.getJSONArray("records");
|
||||
for (int i = 0; i < records.size(); i++) {
|
||||
@ -213,6 +255,12 @@ public class ReportServiceImpl implements ReportService {
|
||||
reportResp.setSuccess(data.getInteger("success"));
|
||||
reportResp.setXmTraceId(xmTraceId);
|
||||
}
|
||||
|
||||
private void setReportAssetResp(String xmTraceId, ReportResp reportResp) {
|
||||
reportResp.setXmTraceId(xmTraceId);
|
||||
}
|
||||
|
||||
|
||||
public enum FileType {
|
||||
// 文档类
|
||||
XLSX("xlsx", "Excel", new byte[]{0x50, 0x4B, 0x03, 0x04}),
|
||||
|
@ -146,6 +146,13 @@ public class TargetManagerServiceImpl extends ServiceImpl<TargetManagerDao, Targ
|
||||
List<TargetManagerResp> respList = TargetConverter.INSTANCE.toRespList(targetManagerPage.getRecords());
|
||||
respList.forEach(this::setUserName);
|
||||
|
||||
respList.forEach(o->{
|
||||
List<TargetVersionResp> targetVersionResps = targetVersionService.selectListByManagerId(o.getId());
|
||||
if (!ObjectUtils.isEmpty(targetVersionResps)){
|
||||
o.setVersionList(targetVersionResps);
|
||||
}
|
||||
});
|
||||
|
||||
PageResult<TargetManagerResp> pageResult = new PageResult<>(respList,targetManagerPage.getTotal(),targetManagerPage.getCurrent(),targetManagerPage.getSize());
|
||||
return pageResult;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user