summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/net/geedge/asw/module/runner/controller/JobController.java19
-rw-r--r--src/main/java/net/geedge/asw/module/runner/controller/PcapController.java13
-rw-r--r--src/main/java/net/geedge/asw/module/runner/controller/RunnerController.java28
-rw-r--r--src/main/java/net/geedge/asw/module/runner/service/IJobService.java2
-rw-r--r--src/main/java/net/geedge/asw/module/runner/service/IPcapService.java3
-rw-r--r--src/main/java/net/geedge/asw/module/runner/service/impl/JobServiceImpl.java30
-rw-r--r--src/main/java/net/geedge/asw/module/runner/service/impl/PcapServiceImpl.java4
7 files changed, 65 insertions, 34 deletions
diff --git a/src/main/java/net/geedge/asw/module/runner/controller/JobController.java b/src/main/java/net/geedge/asw/module/runner/controller/JobController.java
index b12aa05..45dd3c9 100644
--- a/src/main/java/net/geedge/asw/module/runner/controller/JobController.java
+++ b/src/main/java/net/geedge/asw/module/runner/controller/JobController.java
@@ -13,33 +13,38 @@ import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
-@RequestMapping("/api/v1/job")
+@RequestMapping("/api/v1/{workspaceId}/job")
public class JobController {
@Autowired
private IJobService jobService;
@GetMapping("/{id}")
- public R detail(@PathVariable("id") String id) {
- JobEntity jobEntity = jobService.queryInfo(id);
+ public R detail(@PathVariable String workspaceId,
+ @PathVariable("id") String id) {
+ JobEntity jobEntity = jobService.queryInfo(id, workspaceId);
return R.ok().putData("record", jobEntity);
}
@GetMapping
- public R list(@RequestParam Map<String, Object> params) {
+ public R list(@PathVariable String workspaceId,
+ @RequestParam Map<String, Object> params) {
T.VerifyUtil.is(params).notNull()
- .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ params.put("workspaceId", workspaceId);
Page page = jobService.queryList(params);
return R.ok(page);
}
@PostMapping
- public R add(@RequestBody JobEntity entity) {
+ public R add(@PathVariable String workspaceId,
+ @RequestBody JobEntity entity) {
T.VerifyUtil.is(entity).notNull()
.and(entity.getRunnerId()).notEmpty(RCode.RUNNER_ID_CANNOT_EMPTY)
.and(entity.getPackageId()).notEmpty(RCode.PACKAGE_ID_CANNOT_EMPTY)
- .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ entity.setWorkspaceId(workspaceId);
JobEntity jobEntity = jobService.saveJob(entity);
return R.ok().putData("id", jobEntity.getId());
}
diff --git a/src/main/java/net/geedge/asw/module/runner/controller/PcapController.java b/src/main/java/net/geedge/asw/module/runner/controller/PcapController.java
index a52bd59..4b6b9b0 100644
--- a/src/main/java/net/geedge/asw/module/runner/controller/PcapController.java
+++ b/src/main/java/net/geedge/asw/module/runner/controller/PcapController.java
@@ -22,7 +22,7 @@ import java.util.List;
import java.util.Map;
@RestController
-@RequestMapping("/api/v1/pcap")
+@RequestMapping("/api/v1/{workspaceId}/pcap")
public class PcapController {
private static final Log log = Log.get();
@@ -31,16 +31,19 @@ public class PcapController {
private IPcapService pcapService;
@GetMapping("/{id}")
- public R detail(@PathVariable("id") String id) {
- PcapEntity pcapEntity = pcapService.queryInfo(id);
+ public R detail(@PathVariable String workspaceId,
+ @PathVariable("id") String id) {
+ PcapEntity pcapEntity = pcapService.queryInfo(id,workspaceId);
return R.ok().putData("record", pcapEntity);
}
@GetMapping
- public R list(@RequestParam Map<String, Object> params) {
+ public R list(@PathVariable String workspaceId,
+ @RequestParam Map<String, Object> params) {
T.VerifyUtil.is(params).notNull()
- .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ params.put("workspaceId",workspaceId);
Page page = pcapService.queryList(params);
return R.ok(page);
}
diff --git a/src/main/java/net/geedge/asw/module/runner/controller/RunnerController.java b/src/main/java/net/geedge/asw/module/runner/controller/RunnerController.java
index e7499c8..3abe3e1 100644
--- a/src/main/java/net/geedge/asw/module/runner/controller/RunnerController.java
+++ b/src/main/java/net/geedge/asw/module/runner/controller/RunnerController.java
@@ -3,6 +3,7 @@ package net.geedge.asw.module.runner.controller;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.Opt;
import cn.hutool.log.Log;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletResponse;
@@ -23,7 +24,7 @@ import java.io.IOException;
import java.util.Map;
@RestController
-@RequestMapping("/api/v1/runner")
+@RequestMapping("/api/v1/{workspaceId}/runner")
public class RunnerController {
private static final Log log = Log.get();
@@ -35,35 +36,44 @@ public class RunnerController {
private IRunnerService runnerService;
@GetMapping("/{id}")
- public R detail(@PathVariable("id") String id) {
- RunnerEntity runnerEntity = runnerService.getById(id);
+ public R detail(@PathVariable String workspaceId,
+ @PathVariable("id") String id) {
+ RunnerEntity runnerEntity = runnerService.getOne(new LambdaQueryWrapper<RunnerEntity>()
+ .eq(RunnerEntity::getId, id)
+ .eq(RunnerEntity::getWorkspaceId, workspaceId));
return R.ok().putData("record", runnerEntity);
}
@GetMapping
- public R list(@RequestParam Map<String, Object> params) {
+ public R list(@PathVariable String workspaceId,
+ @RequestParam Map<String, Object> params) {
T.VerifyUtil.is(params).notNull()
- .and(T.MapUtil.getStr(params, "workspaceId")).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ params.put("workspaceId", workspaceId);
Page page = runnerService.queryList(params);
return R.ok(page);
}
@PostMapping
- public R add(@RequestBody RunnerEntity entity) {
+ public R add(@PathVariable String workspaceId,
+ @RequestBody RunnerEntity entity) {
T.VerifyUtil.is(entity).notNull()
- .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ entity.setWorkspaceId(workspaceId);
RunnerEntity runner = runnerService.saveRunner(entity);
return R.ok().putData("record", runner);
}
@PutMapping
- public R update(@RequestBody RunnerEntity entity) {
+ public R update(@PathVariable String workspaceId,
+ @RequestBody RunnerEntity entity) {
T.VerifyUtil.is(entity).notNull()
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
- .and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
+ entity.setWorkspaceId(workspaceId);
RunnerEntity runner = runnerService.updateRunner(entity);
return R.ok().putData("record", runner);
}
diff --git a/src/main/java/net/geedge/asw/module/runner/service/IJobService.java b/src/main/java/net/geedge/asw/module/runner/service/IJobService.java
index c0341e8..46170e9 100644
--- a/src/main/java/net/geedge/asw/module/runner/service/IJobService.java
+++ b/src/main/java/net/geedge/asw/module/runner/service/IJobService.java
@@ -10,7 +10,7 @@ import java.util.Map;
public interface IJobService extends IService<JobEntity>{
- JobEntity queryInfo(String id);
+ JobEntity queryInfo(String id, String workspaceId);
Page queryList(Map<String, Object> params);
diff --git a/src/main/java/net/geedge/asw/module/runner/service/IPcapService.java b/src/main/java/net/geedge/asw/module/runner/service/IPcapService.java
index 72c9f5a..51b8f74 100644
--- a/src/main/java/net/geedge/asw/module/runner/service/IPcapService.java
+++ b/src/main/java/net/geedge/asw/module/runner/service/IPcapService.java
@@ -5,11 +5,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
import net.geedge.asw.module.runner.entity.PcapEntity;
import org.springframework.core.io.Resource;
+import java.util.List;
import java.util.Map;
public interface IPcapService extends IService<PcapEntity>{
- PcapEntity queryInfo(String id);
+ PcapEntity queryInfo(String id, String workspaceId);
Page queryList(Map<String, Object> params);
diff --git a/src/main/java/net/geedge/asw/module/runner/service/impl/JobServiceImpl.java b/src/main/java/net/geedge/asw/module/runner/service/impl/JobServiceImpl.java
index 29473d6..7f023cd 100644
--- a/src/main/java/net/geedge/asw/module/runner/service/impl/JobServiceImpl.java
+++ b/src/main/java/net/geedge/asw/module/runner/service/impl/JobServiceImpl.java
@@ -3,6 +3,7 @@ package net.geedge.asw.module.runner.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.log.Log;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -67,21 +68,31 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
}
@Override
- public JobEntity queryInfo(String id) {
- JobEntity job = this.getById(id);
+ public JobEntity queryInfo(String id, String workspaceId) {
+ JobEntity job = this.getOne(new LambdaQueryWrapper<JobEntity>()
+ .eq(JobEntity::getId, id)
+ .eq(JobEntity::getWorkspaceId, workspaceId));
T.VerifyUtil.is(job).notNull(RCode.SYS_RECORD_NOT_FOUND);
- RunnerEntity runner = runnerService.getById(job.getRunnerId());
+ RunnerEntity runner = runnerService.getOne(new LambdaQueryWrapper<RunnerEntity>()
+ .eq(RunnerEntity::getId, job.getRunnerId())
+ .eq(RunnerEntity::getWorkspaceId, workspaceId));
job.setRunner(runner);
- PlaybookEntity playbook = playbookService.getById(job.getPlaybookId());
+ PlaybookEntity playbook = playbookService.getOne(new LambdaQueryWrapper<PlaybookEntity>()
+ .eq(PlaybookEntity::getId, job.getPlaybookId())
+ .eq(PlaybookEntity::getWorkspaceId, workspaceId));
job.setPlaybook(playbook);
- PackageEntity pkg = packageService.getById(job.getPackageId());
+ PackageEntity pkg = packageService.getOne(new LambdaQueryWrapper<PackageEntity>()
+ .eq(PackageEntity::getId, job.getPackageId())
+ .eq(PackageEntity::getWorkspaceId, workspaceId));
job.setPkg(pkg);
if (T.ObjectUtil.isNotNull(playbook)) {
- ApplicationEntity application = applicationService.getById(playbook.getAppId());
+ ApplicationEntity application = applicationService.getOne(new LambdaQueryWrapper<ApplicationEntity>()
+ .eq(ApplicationEntity::getId, playbook.getAppId())
+ .eq(ApplicationEntity::getWorkspaceId, workspaceId));
job.setApplication(application);
}
return job;
@@ -106,9 +117,10 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
// save
this.save(entity);
- // workbook resource
- workbookResourceService.saveResource(entity.getWorkbookId(), entity.getId(), WorkbookConstant.ResourceType.JOB.getValue());
-
+ if (T.StrUtil.isEmpty(entity.getWorkbookId())){
+ // workbook resource
+ workbookResourceService.saveResource(entity.getWorkbookId(), entity.getId(), WorkbookConstant.ResourceType.JOB.getValue());
+ }
// trace log file path
File traceLogFile = T.FileUtil.file(this.getJobResultPath(entity.getId()), "trace.log");
this.update(new LambdaUpdateWrapper<JobEntity>()
diff --git a/src/main/java/net/geedge/asw/module/runner/service/impl/PcapServiceImpl.java b/src/main/java/net/geedge/asw/module/runner/service/impl/PcapServiceImpl.java
index 72301f1..63fced9 100644
--- a/src/main/java/net/geedge/asw/module/runner/service/impl/PcapServiceImpl.java
+++ b/src/main/java/net/geedge/asw/module/runner/service/impl/PcapServiceImpl.java
@@ -70,8 +70,8 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
private IWorkspaceService workspaceService;
@Override
- public PcapEntity queryInfo(String id) {
- PcapEntity pcap = this.getById(id);
+ public PcapEntity queryInfo(String id, String workspaceId) {
+ PcapEntity pcap = this.getOne(new LambdaQueryWrapper<PcapEntity>().eq(PcapEntity::getId, id).eq(PcapEntity::getWorkspaceId, workspaceId));
T.VerifyUtil.is(pcap).notNull(RCode.SYS_RECORD_NOT_FOUND);
JobEntity job = jobService.getOne(new LambdaQueryWrapper<JobEntity>().eq(JobEntity::getPcapId, pcap.getId()));