-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add way to insert dlp jobs and query dlp jobs / results / findings. A…
…lso add possibility to query dlp findings by field
- Loading branch information
Showing
9 changed files
with
93 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 33 additions & 6 deletions
39
src/main/kotlin/io/hawk/service/dlp/DlpInputRestController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
package io.hawk.service.dlp | ||
|
||
import io.hawk.dlp.common.InspectResult | ||
import io.hawk.dlp.common.Job | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class DlpInputRestController { | ||
|
||
@PostMapping("/dlp/input") | ||
fun test(job: Job) { | ||
|
||
|
||
@RequestMapping("/api/dlp") | ||
class DlpInputRestController( | ||
private val dlpJobRepository: DlpJobRepository | ||
) { | ||
@PostMapping | ||
fun input(job: Job) { | ||
val dlpJob = DlpJob().apply dlp@{ | ||
id = job.id | ||
created = job.created | ||
status = job.status | ||
error = job.error?.replace("\u0000", "") | ||
results = job.results?.values?.mapNotNull { | ||
if(it is InspectResult) { | ||
InspectDlpResult().apply { | ||
id = it.id | ||
this.job = this@dlp | ||
timestamp = it.timestamp | ||
additional = it.additional | ||
findings = it.findings.map { | ||
DlpFinding().apply { | ||
infoType = it.infoType | ||
likelihood = it.likelihood | ||
occurrences = it.occurrences | ||
additional = it.additional | ||
} | ||
} | ||
} | ||
} else null | ||
} ?: emptyList() | ||
} | ||
dlpJobRepository.save(dlpJob) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.hawk.service.dlp | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.util.* | ||
|
||
interface DlpJobRepository : JpaRepository<DlpJob, UUID> |
19 changes: 18 additions & 1 deletion
19
src/main/kotlin/io/hawk/service/dlp/DlpOutputRestController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
package io.hawk.service.dlp | ||
|
||
import org.springframework.data.domain.Sort | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import org.springframework.web.server.ResponseStatusException | ||
import java.util.* | ||
|
||
@RestController | ||
class DlpOutputRestController { | ||
@RequestMapping("/api/dlp") | ||
class DlpOutputRestController( | ||
private val dlpJobRepository: DlpJobRepository, | ||
private val dlpResultRepository: DlpResultRepository | ||
) { | ||
@GetMapping | ||
fun list(): List<DlpJob> = dlpJobRepository.findAll(Sort.by(Sort.Direction.DESC, "created")) | ||
|
||
@GetMapping("/results/{id}") | ||
fun show(@PathVariable id: UUID): DlpResult = | ||
dlpResultRepository.findById(id).orElseThrow { ResponseStatusException(HttpStatus.NOT_FOUND) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.hawk.service.dlp | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.util.* | ||
|
||
interface DlpResultRepository : JpaRepository<DlpResult, UUID> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package io.hawk.service.dlp | ||
|
||
import jakarta.persistence.CascadeType | ||
import jakarta.persistence.DiscriminatorValue | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.OneToMany | ||
|
||
@Entity | ||
@DiscriminatorValue("inspect") | ||
class InspectDlpResult : DlpResult() { | ||
@OneToMany(mappedBy = "result") | ||
@OneToMany(mappedBy = "result", cascade = [CascadeType.ALL]) | ||
lateinit var findings: List<DlpFinding> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters