水木逻辑新增
This commit is contained in:
parent
ca5f45d1a0
commit
8578dd2c55
@ -11,7 +11,8 @@ import jakarta.annotation.Resource;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@RestController("/shuimu")
|
@RestController
|
||||||
|
@RequestMapping("/shuimu")
|
||||||
public class ShuiMuController {
|
public class ShuiMuController {
|
||||||
@Resource
|
@Resource
|
||||||
private ShuiMuService shuiMuService;
|
private ShuiMuService shuiMuService;
|
||||||
@ -27,9 +28,8 @@ public class ShuiMuController {
|
|||||||
return CommonResult.success(shuiMuService.imageList(label));
|
return CommonResult.success(shuiMuService.imageList(label));
|
||||||
}
|
}
|
||||||
@PostMapping("/createProject")
|
@PostMapping("/createProject")
|
||||||
public CommonResult<Void> createProject(@RequestBody ShuiMuProjectCreateReq req){
|
public CommonResult<String> createProject(@RequestBody ShuiMuProjectCreateReq req){
|
||||||
shuiMuService.createProject(req);
|
return CommonResult.success(shuiMuService.createProject(req));
|
||||||
return CommonResult.success();
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 获取检测配置
|
* 获取检测配置
|
||||||
|
@ -14,4 +14,5 @@ public class ShuiMuUrlConstant {
|
|||||||
public static final String buildAndSaveConfig = "/api/driverGeneration/buildAndSaveConfig";
|
public static final String buildAndSaveConfig = "/api/driverGeneration/buildAndSaveConfig";
|
||||||
public static final String getProjectById = "/api/project/";
|
public static final String getProjectById = "/api/project/";
|
||||||
public static final String uploadWfuzzJson = "/api/project/code/uploadWfuzzJson";
|
public static final String uploadWfuzzJson = "/api/project/code/uploadWfuzzJson";
|
||||||
|
public static final String executeAllEntrypointsTest ="/api/driverGeneration/executeAllEntrypointsTest";
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package cd.casic.ci.process.engine.constant;
|
||||||
|
|
||||||
|
public class ShuiMuConstant {
|
||||||
|
public static final String SHUI_MU_PROJECT_ID_KEY="projectId";
|
||||||
|
public static final String SHUI_MU_FUZZ_MINUTES = "fuzzMinutes";
|
||||||
|
}
|
@ -83,9 +83,9 @@ public class AFLWorker extends DockerWorker {
|
|||||||
String commandScript = "docker run -v "+volumeWorkDirPath+":"+AFL_DOCKER_BASE_DIR+" -it "+imageName+" bash\n" +
|
String commandScript = "docker run -v "+volumeWorkDirPath+":"+AFL_DOCKER_BASE_DIR+" -it "+imageName+" bash\n" +
|
||||||
"cd " + AFL_DOCKER_BASE_DIR+File.separator+workDir+ "\n"+
|
"cd " + AFL_DOCKER_BASE_DIR+File.separator+workDir+ "\n"+
|
||||||
cdSourceName(fileName) +
|
cdSourceName(fileName) +
|
||||||
"mkdir -p "+ outputPath +"\n" +
|
|
||||||
"rm -rf " + outputPath + "\n" +
|
"rm -rf " + outputPath + "\n" +
|
||||||
"chmod o+rwx -p "+outputPath+"\n"+
|
"mkdir -p "+ outputPath +"\n" +
|
||||||
|
"chmod o+rwx -R "+outputPath+"\n"+
|
||||||
"afl-fuzz -i "+ AFL_DOCKER_BASE_DIR+File.separator+seedPath+" -o "+ outputPath+" ./"+ executableName + " " +commandEnd;
|
"afl-fuzz -i "+ AFL_DOCKER_BASE_DIR+File.separator+seedPath+" -o "+ outputPath+" ./"+ executableName + " " +commandEnd;
|
||||||
try {
|
try {
|
||||||
//将节点的配置信息反编译成对象
|
//将节点的配置信息反编译成对象
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package cd.casic.ci.process.engine.worker.shuimu;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.common.WorkAtom;
|
||||||
|
import cd.casic.ci.process.engine.constant.ShuiMuConstant;
|
||||||
|
import cd.casic.ci.process.engine.runContext.TaskRunContext;
|
||||||
|
import cd.casic.ci.process.engine.worker.base.BaseWorker;
|
||||||
|
import cd.casic.ci.process.engine.worker.base.SshWorker;
|
||||||
|
import cd.casic.ci.process.process.dataObject.task.PipTask;
|
||||||
|
import cd.casic.ci.process.process.service.shuimu.ShuiMuService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
@Slf4j
|
||||||
|
@WorkAtom(taskType = "SHUI_MU")
|
||||||
|
public class ShuiMuWorker extends BaseWorker {
|
||||||
|
@Resource
|
||||||
|
private ShuiMuService shuiMuService;
|
||||||
|
@Override
|
||||||
|
public void execute(TaskRunContext context) {
|
||||||
|
PipTask contextDef = (PipTask) context.getContextDef();
|
||||||
|
Map<String, Object> taskProperties = contextDef.getTaskProperties();
|
||||||
|
String projectId = (String)taskProperties.get(ShuiMuConstant.SHUI_MU_PROJECT_ID_KEY);
|
||||||
|
Integer fuzzMinutes = Integer.parseInt(String.valueOf(taskProperties.get(ShuiMuConstant.SHUI_MU_FUZZ_MINUTES)));
|
||||||
|
shuiMuService.executeAllEntrypointsTest(projectId,fuzzMinutes);
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,7 @@ public interface ShuiMuService {
|
|||||||
* 获取编译环境
|
* 获取编译环境
|
||||||
* */
|
* */
|
||||||
List<String> imageList(String label);
|
List<String> imageList(String label);
|
||||||
void createProject(ShuiMuProjectCreateReq req);
|
String createProject(ShuiMuProjectCreateReq req);
|
||||||
/**
|
/**
|
||||||
* 获取检测配置
|
* 获取检测配置
|
||||||
* */
|
* */
|
||||||
@ -29,4 +29,5 @@ public interface ShuiMuService {
|
|||||||
|
|
||||||
void buildAndSaveConfig(ShuiMuBuildAndSaveReq req);
|
void buildAndSaveConfig(ShuiMuBuildAndSaveReq req);
|
||||||
void uploadWfuzzJson(ShuiMuUpdateWFuzzJsonReq req);
|
void uploadWfuzzJson(ShuiMuUpdateWFuzzJsonReq req);
|
||||||
|
void executeAllEntrypointsTest(String projectId,Integer fuzzMinutes);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import cd.casic.ci.process.process.service.target.TargetVersionService;
|
|||||||
import cd.casic.ci.process.properties.ShuiMuProperties;
|
import cd.casic.ci.process.properties.ShuiMuProperties;
|
||||||
import cd.casic.framework.commons.exception.ServiceException;
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import cd.casic.framework.commons.util.object.BeanUtils;
|
||||||
import cd.casic.framework.redis.core.RedisTemplateUtils;
|
import cd.casic.framework.redis.core.RedisTemplateUtils;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
@ -107,11 +108,11 @@ public class ShuiMuServiceImpl implements ShuiMuService {
|
|||||||
res.add(name);
|
res.add(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res.stream().filter(item->item.startsWith(SHUI_MU_IMAGE_LIST_FILTER)).toList();
|
return res.stream().filter(item->!item.startsWith(SHUI_MU_IMAGE_LIST_FILTER)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createProject(ShuiMuProjectCreateReq req) {
|
public String createProject(ShuiMuProjectCreateReq req) {
|
||||||
MultiValueMap<String,Object> body = new LinkedMultiValueMap<>();
|
MultiValueMap<String,Object> body = new LinkedMultiValueMap<>();
|
||||||
body.add("projectName","应用检测_"+ UUID.randomUUID().toString().replaceAll("-",""));
|
body.add("projectName","应用检测_"+ UUID.randomUUID().toString().replaceAll("-",""));
|
||||||
body.add("language",req.getLanguage());
|
body.add("language",req.getLanguage());
|
||||||
@ -124,14 +125,21 @@ public class ShuiMuServiceImpl implements ShuiMuService {
|
|||||||
if (!targetFile.exists()) {
|
if (!targetFile.exists()) {
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"找不到目标文件");
|
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"找不到目标文件");
|
||||||
}
|
}
|
||||||
|
String fileName = targetVersion.getFileName();
|
||||||
|
String fileType = fileName.substring(fileName.indexOf(".")+1);
|
||||||
|
body.add("vcs",fileType);
|
||||||
FileSystemResource resource = new FileSystemResource(targetFile);
|
FileSystemResource resource = new FileSystemResource(targetFile);
|
||||||
body.add("file",resource);
|
body.add("file",resource);
|
||||||
HttpEntity<MultiValueMap<String,Object>> entity = new HttpEntity<>(body,getHeaders());
|
HttpHeaders headers = getHeaders();
|
||||||
|
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||||
|
HttpEntity<MultiValueMap<String,Object>> entity = new HttpEntity<>(body, headers);
|
||||||
ResponseEntity<String> exchange = restTemplate.exchange(shuiMuProperties.getBaseUrl() + createProject, HttpMethod.POST, entity, String.class, new HashMap<>());
|
ResponseEntity<String> exchange = restTemplate.exchange(shuiMuProperties.getBaseUrl() + createProject, HttpMethod.POST, entity, String.class, new HashMap<>());
|
||||||
HttpStatusCode statusCode = exchange.getStatusCode();
|
HttpStatusCode statusCode = exchange.getStatusCode();
|
||||||
if (statusCode.isError()) {
|
if (statusCode.isError()) {
|
||||||
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"创建项目失败");
|
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"创建项目失败");
|
||||||
}
|
}
|
||||||
|
JSONObject response = JSONObject.parseObject(exchange.getBody());
|
||||||
|
return response.getString("data");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -217,7 +225,26 @@ public class ShuiMuServiceImpl implements ShuiMuService {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
// 获取projectversion
|
||||||
|
ShuiMuProjectVersionResp projectVersion = getProjectVersion(req.getProjectId());
|
||||||
|
ShuiMuProjectVersionResp.Repo repo = projectVersion.getRepo();
|
||||||
|
ShuiMuBuildAndSaveReq shuiMuBuildAndSaveReq = new ShuiMuBuildAndSaveReq();
|
||||||
|
BeanUtils.copyProperties(repo,shuiMuBuildAndSaveReq);
|
||||||
|
buildAndSaveConfig(shuiMuBuildAndSaveReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeAllEntrypointsTest(String projectId,Integer fuzzMinutes) {
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(null,getHeaders());
|
||||||
|
String uriString = UriComponentsBuilder.fromUriString(shuiMuProperties.getBaseUrl() + executeAllEntrypointsTest)
|
||||||
|
.queryParam("projectId",projectId)
|
||||||
|
.queryParam("arch","x86")
|
||||||
|
.queryParam("fuzzMinutes",fuzzMinutes)
|
||||||
|
.toUriString();
|
||||||
|
ResponseEntity<String> exchange = restTemplate.exchange(uriString, HttpMethod.GET, entity, String.class, new HashMap<>());
|
||||||
|
if (exchange.getStatusCode().isError()) {
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.PIPELINE_ERROR.getCode(),"保存并且构建失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user