3 Commits

Author SHA1 Message Date
zhangshuai
62ea5f5542 fix: runner, pcap, job 接口添加 workspaceId path 参数 2024-08-09 14:48:23 +08:00
zhangshuai
357ee0be62 fix: package 接口url增加 workspaceId path 参数 2024-08-09 10:25:11 +08:00
zhangshuai
2945c51b0f fix: application 接口url增加 workspaceId path 参数 2024-08-09 10:01:00 +08:00
15 changed files with 161 additions and 93 deletions

View File

@@ -1,5 +1,6 @@
package net.geedge.asw.module.app.controller; package net.geedge.asw.module.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import net.geedge.asw.common.util.ASWException; import net.geedge.asw.common.util.ASWException;
@@ -18,7 +19,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/api/v1/application") @RequestMapping("/api/v1/{workspaceId}/application")
public class ApplicationController { public class ApplicationController {
@Autowired @Autowired
@@ -28,9 +29,12 @@ public class ApplicationController {
private ISysUserService userService; private ISysUserService userService;
@GetMapping("/{id}") @GetMapping("/{id}")
public R detail(@PathVariable String id) { public R detail(@PathVariable String workspaceId,
ApplicationEntity entity = applicationService.getById(id); @PathVariable String id) {
if (T.ObjectUtil.isNull(entity)){ ApplicationEntity entity = applicationService.getOne(new LambdaQueryWrapper<ApplicationEntity>()
.eq(ApplicationEntity::getId, id)
.eq(ApplicationEntity::getWorkspaceId, workspaceId));
if (T.ObjectUtil.isNull(entity)) {
throw new ASWException(RCode.APP_NOT_EXIST); throw new ASWException(RCode.APP_NOT_EXIST);
} }
SysUserEntity createUser = userService.getById(entity.getCreateUserId()); SysUserEntity createUser = userService.getById(entity.getCreateUserId());
@@ -41,13 +45,11 @@ public class ApplicationController {
} }
@GetMapping("/{id}/{version}") @GetMapping("/{id}/{version}")
public R detail(@PathVariable String id, public R detail(@PathVariable String workspaceId,
@PathVariable String id,
@PathVariable(required = false) String version) { @PathVariable(required = false) String version) {
ApplicationEntity entity = applicationService.getById(id); ApplicationEntity entity = applicationService.queryByApplicationAndLog(id, version, workspaceId);
if (T.StrUtil.isNotEmpty(version)){ if (T.ObjectUtil.isNull(entity)) {
entity = applicationService.queryByApplicationAndLog(id, version);
}
if (T.ObjectUtil.isNull(entity)){
throw new ASWException(RCode.APP_NOT_EXIST); throw new ASWException(RCode.APP_NOT_EXIST);
} }
SysUserEntity createUser = userService.getById(entity.getCreateUserId()); SysUserEntity createUser = userService.getById(entity.getCreateUserId());
@@ -59,29 +61,34 @@ public class ApplicationController {
@GetMapping @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() 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 = applicationService.queryList(params); Page page = applicationService.queryList(params);
return R.ok(page); return R.ok(page);
} }
@PostMapping @PostMapping
public R add(@RequestBody ApplicationEntity entity) { public R add(@PathVariable String workspaceId,
@RequestBody ApplicationEntity entity) {
T.VerifyUtil.is(entity).notNull() T.VerifyUtil.is(entity).notNull()
.and(entity.getName()).notEmpty(RCode.APP_NAME_CANNOT_EMPTY) .and(entity.getName()).notEmpty(RCode.APP_NAME_CANNOT_EMPTY)
//.and(entity.getLongName()).notEmpty(RCode.APP_LONGNAME_CANNOT_EMPTY) //.and(entity.getLongName()).notEmpty(RCode.APP_LONGNAME_CANNOT_EMPTY)
//.and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY) //.and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY)
//.and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) //.and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY)
//.and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY) //.and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY)
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
entity.setWorkspaceId(workspaceId);
ApplicationEntity applicationEntity = applicationService.saveApplication(entity); ApplicationEntity applicationEntity = applicationService.saveApplication(entity);
return R.ok().putData("id", applicationEntity.getId()); return R.ok().putData("id", applicationEntity.getId());
} }
@PutMapping @PutMapping
public R update(@RequestBody ApplicationEntity entity) { public R update(@PathVariable String workspaceId,
@RequestBody ApplicationEntity entity) {
T.VerifyUtil.is(entity).notNull() T.VerifyUtil.is(entity).notNull()
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY) .and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
@@ -89,44 +96,48 @@ public class ApplicationController {
//.and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY) //.and(entity.getProperties()).notEmpty(RCode.APP_PROPERTIES_CANNOT_EMPTY)
//.and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY) //.and(entity.getSurrogates()).notEmpty(RCode.APP_SURROGATES_CANNOT_EMPTY)
//.and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY) //.and(entity.getDescription()).notEmpty(RCode.APP_DESCRIPTION_CANNOT_EMPTY)
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
entity.setWorkspaceId(workspaceId);
ApplicationEntity applicationEntity = applicationService.updateApplication(entity); ApplicationEntity applicationEntity = applicationService.updateApplication(entity);
return R.ok().putData("id", applicationEntity.getId()); return R.ok().putData("id", applicationEntity.getId());
} }
@DeleteMapping @DeleteMapping
public R delete(String[] ids) { public R delete(@PathVariable String workspaceId,
String[] ids) {
T.VerifyUtil.is(ids).notEmpty(); T.VerifyUtil.is(ids).notEmpty();
applicationService.removeApplication(T.ListUtil.of(ids)); applicationService.removeApplication(T.ListUtil.of(ids), workspaceId);
return R.ok(); return R.ok();
} }
@GetMapping("/{id}/log") @GetMapping("/{id}/log")
public R queryLogList(@PathVariable("id") String id) { public R queryLogList(@PathVariable String workspaceId,
List<ApplicationEntity> applicationEntityList = applicationService.queryLogList(id); @PathVariable("id") String id) {
List<ApplicationEntity> applicationEntityList = applicationService.queryLogList(id, workspaceId);
return R.ok().putData("record", applicationEntityList); return R.ok().putData("record", applicationEntityList);
} }
@GetMapping("/{id}/{oldVersion}/{newVersion}") @GetMapping("/{id}/{oldVersion}/{newVersion}")
public R applicationCompare(@PathVariable("id") String id, public R applicationCompare(@PathVariable String workspaceId,
@PathVariable("id") String id,
@PathVariable("oldVersion") String oldVersion, @PathVariable("oldVersion") String oldVersion,
@PathVariable("newVersion") String newVersion) { @PathVariable("newVersion") String newVersion) {
List<ApplicationEntity> list = applicationService.compare(id, oldVersion, newVersion); List<ApplicationEntity> list = applicationService.compare(id, oldVersion, newVersion,workspaceId);
return R.ok().putData("record", list); return R.ok().putData("record", list);
} }
@PostMapping("/{id}/{version}/restore") @PostMapping("/{id}/{version}/restore")
public R restore(@PathVariable("id") String id, public R restore(@PathVariable String workspaceId,
@PathVariable("id") String id,
@PathVariable("version") String version) { @PathVariable("version") String version) {
applicationService.restore(id, version); applicationService.restore(id, version, workspaceId);
return R.ok(); return R.ok();
} }
@GetMapping("/analyze") @GetMapping("/analyze")
public void analyze(@RequestParam String workspaceId, public void analyze(@PathVariable String workspaceId,
@RequestParam String pcapIds, @RequestParam String pcapIds,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
applicationService.redirectDiscoverPage(workspaceId, pcapIds, response); applicationService.redirectDiscoverPage(workspaceId, pcapIds, response);

View File

@@ -1,5 +1,6 @@
package net.geedge.asw.module.app.controller; package net.geedge.asw.module.app.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.geedge.asw.common.util.R; import net.geedge.asw.common.util.R;
import net.geedge.asw.common.util.RCode; import net.geedge.asw.common.util.RCode;
@@ -12,53 +13,63 @@ import org.springframework.web.bind.annotation.*;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/api/v1/package") @RequestMapping("/api/v1/{workspaceId}/package")
public class PackageController { public class PackageController {
@Autowired @Autowired
private IPackageService packageService; private IPackageService packageService;
@GetMapping("/{id}") @GetMapping("/{id}")
public R detail(@PathVariable("id") String id) { public R detail(@PathVariable String workspaceId,
PackageEntity entity = packageService.getById(id); @PathVariable("id") String id) {
PackageEntity entity = packageService.getOne(new LambdaQueryWrapper<PackageEntity>()
.eq(PackageEntity::getId, id)
.eq(PackageEntity::getWorkspaceId, workspaceId));
return R.ok().putData("record", entity); return R.ok().putData("record", entity);
} }
@GetMapping @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() 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 = packageService.queryList(params); Page page = packageService.queryList(params);
return R.ok(page); return R.ok(page);
} }
@PostMapping @PostMapping
public R add(@RequestBody PackageEntity entity) { public R add(@PathVariable String workspaceId,
@RequestBody PackageEntity entity) {
T.VerifyUtil.is(entity).notNull() T.VerifyUtil.is(entity).notNull()
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
.and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY) .and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY)
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
entity.setWorkspaceId(workspaceId);
PackageEntity pkgEntity = packageService.savePackage(entity); PackageEntity pkgEntity = packageService.savePackage(entity);
return R.ok().putData("id", pkgEntity.getId()); return R.ok().putData("id", pkgEntity.getId());
} }
@PutMapping @PutMapping
public R update(@RequestBody PackageEntity entity) { public R update(@PathVariable String workspaceId,
@RequestBody PackageEntity entity) {
T.VerifyUtil.is(entity).notNull() T.VerifyUtil.is(entity).notNull()
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY) .and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY) .and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
.and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY) .and(entity.getDescription()).notEmpty(RCode.PACKAGE_DESCRIPTION_CANNOT_EMPTY)
.and(entity.getWorkspaceId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY); .and(workspaceId).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY);
entity.setWorkspaceId(workspaceId);
PackageEntity pkgEntity = packageService.updatePackage(entity); PackageEntity pkgEntity = packageService.updatePackage(entity);
return R.ok().putData("id", pkgEntity.getId()); return R.ok().putData("id", pkgEntity.getId());
} }
@DeleteMapping @DeleteMapping
public R delete(String[] ids) { public R delete(@PathVariable String workspaceId,
String[] ids) {
T.VerifyUtil.is(ids).notEmpty(); T.VerifyUtil.is(ids).notEmpty();
packageService.removePackage(T.ListUtil.of(ids)); packageService.removePackage(T.ListUtil.of(ids), workspaceId);
return R.ok(); return R.ok();
} }

View File

@@ -15,10 +15,10 @@ public interface ApplicationDao extends BaseMapper<ApplicationEntity>{
List<ApplicationEntity> queryList(Page page, Map<String, Object> params); List<ApplicationEntity> queryList(Page page, Map<String, Object> params);
@Select("select * from ( select * from application union select * from application_log ) app where app.id = #{id} and app.op_version = #{version}") @Select("select * from ( select * from application union select * from application_log ) app where app.id = #{id} and app.op_version = #{version} and app.workspace_id = #{workspaceId}")
ApplicationEntity queryByApplicationAndLog(String id, String version); ApplicationEntity queryByApplicationAndLog(String id, String version, String workspaceId);
List<ApplicationEntity> queryLogList(String id); List<ApplicationEntity> queryLogList(String id, String workspaceId);
List<ApplicationEntity> compare(@Param("params") Map<String, Object> params); List<ApplicationEntity> compare(@Param("params") Map<String, Object> params);

View File

@@ -17,15 +17,15 @@ public interface IApplicationService extends IService<ApplicationEntity>{
ApplicationEntity updateApplication(ApplicationEntity entity); ApplicationEntity updateApplication(ApplicationEntity entity);
void removeApplication(List<String> ids); void removeApplication(List<String> ids, String workspaceId);
ApplicationEntity queryByApplicationAndLog(String id, String version); ApplicationEntity queryByApplicationAndLog(String id, String version, String workspaceId);
List<ApplicationEntity> compare(String id, String oldVersion, String newVersion); List<ApplicationEntity> compare(String id, String oldVersion, String newVersion, String workspaceId);
List<ApplicationEntity> queryLogList(String id); List<ApplicationEntity> queryLogList(String id, String workspaceId);
void restore(String id, String version); void restore(String id, String version, String workspaceId);
void redirectDiscoverPage(String workspaceId, String pcapIds, HttpServletResponse response) throws IOException; void redirectDiscoverPage(String workspaceId, String pcapIds, HttpServletResponse response) throws IOException;

View File

@@ -15,5 +15,5 @@ public interface IPackageService extends IService<PackageEntity>{
PackageEntity updatePackage(PackageEntity entity); PackageEntity updatePackage(PackageEntity entity);
void removePackage(List<String> ids); void removePackage(List<String> ids, String workspaceId);
} }

View File

@@ -56,8 +56,8 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
private KibanaClient kibanaClient; private KibanaClient kibanaClient;
@Override @Override
public ApplicationEntity queryByApplicationAndLog(String id, String version) { public ApplicationEntity queryByApplicationAndLog(String id, String version, String workspaceId) {
ApplicationEntity entity = this.baseMapper.queryByApplicationAndLog(id, version); ApplicationEntity entity = this.baseMapper.queryByApplicationAndLog(id, version, workspaceId);
return entity; return entity;
} }
@@ -122,21 +122,25 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void removeApplication(List<String> ids) { public void removeApplication(List<String> ids, String workspaceId) {
// remove // remove
this.removeBatchByIds(ids); this.remove(new LambdaQueryWrapper<ApplicationEntity>()
applicationLogService.removeBatchByIds(ids); .in(ApplicationEntity::getId, ids)
.eq(ApplicationEntity::getWorkspaceId, workspaceId));
applicationLogService.remove(new LambdaQueryWrapper<ApplicationLogEntity>()
.in(ApplicationLogEntity::getId, ids)
.eq(ApplicationLogEntity::getWorkspaceId, workspaceId));
} }
@Override @Override
public List<ApplicationEntity> queryLogList(String id) { public List<ApplicationEntity> queryLogList(String id, String workspaceId) {
List<ApplicationEntity> packageList = this.getBaseMapper().queryLogList(id); List<ApplicationEntity> packageList = this.getBaseMapper().queryLogList(id, workspaceId);
return packageList; return packageList;
} }
@Override @Override
public List<ApplicationEntity> compare(String id, String oldVersion, String newVersion) { public List<ApplicationEntity> compare(String id, String oldVersion, String newVersion, String workspaceId) {
Map<String, Object> params = Map.of("id", id, "versions", Arrays.asList(oldVersion, newVersion)); Map<String, Object> params = Map.of("id", id, "versions", Arrays.asList(oldVersion, newVersion),"workspaceId",workspaceId);
List<ApplicationEntity> packageList = this.getBaseMapper().compare(params); List<ApplicationEntity> packageList = this.getBaseMapper().compare(params);
return packageList; return packageList;
} }
@@ -144,13 +148,16 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationDao, Applicat
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void restore(String id, String version) { public void restore(String id, String version, String workspaceId) {
// save current to log // save current to log
ApplicationEntity curApplication = this.getById(id); ApplicationEntity curApplication = this.getOne(new LambdaQueryWrapper<ApplicationEntity>()
.eq(ApplicationEntity::getId, id)
.eq(ApplicationEntity::getWorkspaceId, workspaceId));
this.saveApplcationToLog(curApplication); this.saveApplcationToLog(curApplication);
// restore // restore
ApplicationLogEntity oldApplication = applicationLogService.getOne(new LambdaQueryWrapper<ApplicationLogEntity>() ApplicationLogEntity oldApplication = applicationLogService.getOne(new LambdaQueryWrapper<ApplicationLogEntity>()
.eq(ApplicationLogEntity::getId, id) .eq(ApplicationLogEntity::getId, id)
.eq(ApplicationLogEntity::getWorkspaceId, workspaceId)
.eq(ApplicationLogEntity::getOpVersion, version)); .eq(ApplicationLogEntity::getOpVersion, version));
oldApplication.setUpdateTimestamp(System.currentTimeMillis()); oldApplication.setUpdateTimestamp(System.currentTimeMillis());

View File

@@ -80,9 +80,11 @@ public class PackageServiceImpl extends ServiceImpl<PackageDao, PackageEntity> i
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void removePackage(List<String> ids) { public void removePackage(List<String> ids, String workspaceId) {
// remove // remove
this.removeBatchByIds(ids); this.remove(new LambdaQueryWrapper<PackageEntity>()
.eq(PackageEntity::getWorkspaceId, workspaceId)
.in(PackageEntity::getId, ids));
// workbook resource // workbook resource
workbookResourceService.removeResource(ids, WorkbookConstant.ResourceType.PACKAGE.getValue()); workbookResourceService.removeResource(ids, WorkbookConstant.ResourceType.PACKAGE.getValue());
} }

View File

@@ -13,33 +13,38 @@ import org.springframework.web.bind.annotation.*;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/api/v1/job") @RequestMapping("/api/v1/{workspaceId}/job")
public class JobController { public class JobController {
@Autowired @Autowired
private IJobService jobService; private IJobService jobService;
@GetMapping("/{id}") @GetMapping("/{id}")
public R detail(@PathVariable("id") String id) { public R detail(@PathVariable String workspaceId,
JobEntity jobEntity = jobService.queryInfo(id); @PathVariable("id") String id) {
JobEntity jobEntity = jobService.queryInfo(id, workspaceId);
return R.ok().putData("record", jobEntity); return R.ok().putData("record", jobEntity);
} }
@GetMapping @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() 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); Page page = jobService.queryList(params);
return R.ok(page); return R.ok(page);
} }
@PostMapping @PostMapping
public R add(@RequestBody JobEntity entity) { public R add(@PathVariable String workspaceId,
@RequestBody JobEntity entity) {
T.VerifyUtil.is(entity).notNull() T.VerifyUtil.is(entity).notNull()
.and(entity.getRunnerId()).notEmpty(RCode.RUNNER_ID_CANNOT_EMPTY) .and(entity.getRunnerId()).notEmpty(RCode.RUNNER_ID_CANNOT_EMPTY)
.and(entity.getPackageId()).notEmpty(RCode.PACKAGE_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); JobEntity jobEntity = jobService.saveJob(entity);
return R.ok().putData("id", jobEntity.getId()); return R.ok().putData("id", jobEntity.getId());
} }

View File

@@ -22,7 +22,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/api/v1/pcap") @RequestMapping("/api/v1/{workspaceId}/pcap")
public class PcapController { public class PcapController {
private static final Log log = Log.get(); private static final Log log = Log.get();
@@ -31,16 +31,19 @@ public class PcapController {
private IPcapService pcapService; private IPcapService pcapService;
@GetMapping("/{id}") @GetMapping("/{id}")
public R detail(@PathVariable("id") String id) { public R detail(@PathVariable String workspaceId,
PcapEntity pcapEntity = pcapService.queryInfo(id); @PathVariable("id") String id) {
PcapEntity pcapEntity = pcapService.queryInfo(id,workspaceId);
return R.ok().putData("record", pcapEntity); return R.ok().putData("record", pcapEntity);
} }
@GetMapping @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() 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); Page page = pcapService.queryList(params);
return R.ok(page); return R.ok(page);
} }

View File

@@ -3,6 +3,7 @@ package net.geedge.asw.module.runner.controller;
import cn.dev33.satoken.annotation.SaIgnore; import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.lang.Opt; import cn.hutool.core.lang.Opt;
import cn.hutool.log.Log; 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.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@@ -23,7 +24,7 @@ import java.io.IOException;
import java.util.Map; import java.util.Map;
@RestController @RestController
@RequestMapping("/api/v1/runner") @RequestMapping("/api/v1/{workspaceId}/runner")
public class RunnerController { public class RunnerController {
private static final Log log = Log.get(); private static final Log log = Log.get();
@@ -35,35 +36,44 @@ public class RunnerController {
private IRunnerService runnerService; private IRunnerService runnerService;
@GetMapping("/{id}") @GetMapping("/{id}")
public R detail(@PathVariable("id") String id) { public R detail(@PathVariable String workspaceId,
RunnerEntity runnerEntity = runnerService.getById(id); @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); return R.ok().putData("record", runnerEntity);
} }
@GetMapping @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() 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); Page page = runnerService.queryList(params);
return R.ok(page); return R.ok(page);
} }
@PostMapping @PostMapping
public R add(@RequestBody RunnerEntity entity) { public R add(@PathVariable String workspaceId,
@RequestBody RunnerEntity entity) {
T.VerifyUtil.is(entity).notNull() 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); RunnerEntity runner = runnerService.saveRunner(entity);
return R.ok().putData("record", runner); return R.ok().putData("record", runner);
} }
@PutMapping @PutMapping
public R update(@RequestBody RunnerEntity entity) { public R update(@PathVariable String workspaceId,
@RequestBody RunnerEntity entity) {
T.VerifyUtil.is(entity).notNull() T.VerifyUtil.is(entity).notNull()
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY) .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); RunnerEntity runner = runnerService.updateRunner(entity);
return R.ok().putData("record", runner); return R.ok().putData("record", runner);
} }

View File

@@ -10,7 +10,7 @@ import java.util.Map;
public interface IJobService extends IService<JobEntity>{ public interface IJobService extends IService<JobEntity>{
JobEntity queryInfo(String id); JobEntity queryInfo(String id, String workspaceId);
Page queryList(Map<String, Object> params); Page queryList(Map<String, Object> params);

View File

@@ -5,11 +5,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
import net.geedge.asw.module.runner.entity.PcapEntity; import net.geedge.asw.module.runner.entity.PcapEntity;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import java.util.List;
import java.util.Map; import java.util.Map;
public interface IPcapService extends IService<PcapEntity>{ public interface IPcapService extends IService<PcapEntity>{
PcapEntity queryInfo(String id); PcapEntity queryInfo(String id, String workspaceId);
Page queryList(Map<String, Object> params); Page queryList(Map<String, Object> params);

View File

@@ -3,6 +3,7 @@ package net.geedge.asw.module.runner.service.impl;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.io.IORuntimeException;
import cn.hutool.log.Log; 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.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -67,21 +68,31 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
} }
@Override @Override
public JobEntity queryInfo(String id) { public JobEntity queryInfo(String id, String workspaceId) {
JobEntity job = this.getById(id); 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); 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); 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); 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); job.setPkg(pkg);
if (T.ObjectUtil.isNotNull(playbook)) { 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); job.setApplication(application);
} }
return job; return job;
@@ -106,9 +117,10 @@ public class JobServiceImpl extends ServiceImpl<JobDao, JobEntity> implements IJ
// save // save
this.save(entity); this.save(entity);
// workbook resource if (T.StrUtil.isEmpty(entity.getWorkbookId())){
workbookResourceService.saveResource(entity.getWorkbookId(), entity.getId(), WorkbookConstant.ResourceType.JOB.getValue()); // workbook resource
workbookResourceService.saveResource(entity.getWorkbookId(), entity.getId(), WorkbookConstant.ResourceType.JOB.getValue());
}
// trace log file path // trace log file path
File traceLogFile = T.FileUtil.file(this.getJobResultPath(entity.getId()), "trace.log"); File traceLogFile = T.FileUtil.file(this.getJobResultPath(entity.getId()), "trace.log");
this.update(new LambdaUpdateWrapper<JobEntity>() this.update(new LambdaUpdateWrapper<JobEntity>()

View File

@@ -70,8 +70,8 @@ public class PcapServiceImpl extends ServiceImpl<PcapDao, PcapEntity> implements
private IWorkspaceService workspaceService; private IWorkspaceService workspaceService;
@Override @Override
public PcapEntity queryInfo(String id) { public PcapEntity queryInfo(String id, String workspaceId) {
PcapEntity pcap = this.getById(id); 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); T.VerifyUtil.is(pcap).notNull(RCode.SYS_RECORD_NOT_FOUND);
JobEntity job = jobService.getOne(new LambdaQueryWrapper<JobEntity>().eq(JobEntity::getPcapId, pcap.getId())); JobEntity job = jobService.getOne(new LambdaQueryWrapper<JobEntity>().eq(JobEntity::getPcapId, pcap.getId()));

View File

@@ -76,6 +76,9 @@
<if test="id != null and id != ''"> <if test="id != null and id != ''">
AND app.id = #{id} AND app.id = #{id}
</if> </if>
<if test="workspaceId != null and workspaceId != ''">
AND app.workspace_id = #{workspaceId}
</if>
</where> </where>
ORDER BY app.op_version DESC ORDER BY app.op_version DESC
</select> </select>
@@ -101,6 +104,9 @@
<if test="params.id != null and params.id != ''"> <if test="params.id != null and params.id != ''">
AND app.id = #{params.id} AND app.id = #{params.id}
</if> </if>
<if test="params.workspaceId != null and params.workspaceId != ''">
AND app.workspace_id = #{params.workspaceId}
</if>
</where> </where>
</select> </select>