Skip to content

Commit

Permalink
feat: 支持查询扫描任务 TencentBlueKing#1103
Browse files Browse the repository at this point in the history
  • Loading branch information
felixncheng committed Aug 30, 2023
1 parent 1964e75 commit fd6a088
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@ interface ScanClient {
* */
@GetMapping("/token/verify")
fun verifyToken(@RequestParam subtaskId: String, @RequestParam token: String): Response<Boolean>

/**
* 查询task状态
* */
@GetMapping("/task/{taskId}")
fun getTask(@PathVariable taskId: String): Response<ScanTask>
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.tencent.bkrepo.analyst.pojo.license.SpdxLicenseInfo
import com.tencent.bkrepo.analyst.pojo.request.ReportResultRequest
import com.tencent.bkrepo.analyst.pojo.request.ScanRequest
import com.tencent.bkrepo.analyst.service.ScanService
import com.tencent.bkrepo.analyst.service.ScanTaskService
import com.tencent.bkrepo.analyst.service.SpdxLicenseService
import com.tencent.bkrepo.analyst.service.TemporaryScanTokenService
import com.tencent.bkrepo.common.api.pojo.Response
Expand All @@ -48,7 +49,8 @@ import org.springframework.web.bind.annotation.RestController
class ScanController @Autowired constructor(
private val scanService: ScanService,
private val licenseService: SpdxLicenseService,
private val tokenService: TemporaryScanTokenService
private val tokenService: TemporaryScanTokenService,
private val scanTaskService: ScanTaskService,
) : ScanClient {

override fun scan(scanRequest: ScanRequest): Response<ScanTask> {
Expand Down Expand Up @@ -88,4 +90,8 @@ class ScanController @Autowired constructor(
}
return ResponseBuilder.success(ret)
}

override fun getTask(taskId: String): Response<ScanTask> {
return ResponseBuilder.success(scanTaskService.task(taskId))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ class ScanTaskServiceImpl(

override fun task(taskId: String): ScanTask {
return scanTaskDao.findById(taskId)?.let { task ->
val repos = RuleUtil.getRepoNames(task.rule?.readJsonString())
if (task.projectId == null) {
permissionCheckHandler.permissionManager.checkPrincipal(SecurityUtils.getUserId(), PrincipalType.ADMIN)
} else if (repos.isNotEmpty()) {
permissionCheckHandler.checkReposPermission(task.projectId, repos, PermissionAction.READ)
} else {
permissionCheckHandler.checkProjectPermission(task.projectId, PermissionAction.MANAGE)
}
Expand Down

0 comments on commit fd6a088

Please sign in to comment.