Handle the scanning result to be outputted without the temporary file "hack"
- Dominant language
- Go
- Stars
- 58
- Forks
- 55
- Avg merge
- 9h 9m
- Merged PRs (30d)
- 424
Description
When scanning the EBS snapshots via `Trivy` in order to get the scan response we should provide an `io.Writer` to `Trivy` for it to work on.
This is the configuration for the output writer:
```go
ReportOptions: flag.ReportOptions{
Output: o,
Format: "json",
Severities: []db_types.Severity{0, 1, 2, 3, 4},
},
```
In order to make it work I'm basically creating a temp file and providing it as the `io.Writer` likewise:
```go
o, err := ioutil.TempFile("", "")
if err != nil {
f.log.Error("VulnerabilityScanner.evaluate.TempFile error: ", err)
return
}
defer os.Remove(o.Name())
```
Then later on when the scanning ended, I unmarshal this file into `Go` likewise:
```go
f.log.Info("VulnerabilityScanner.evaluate.jsonFile")
jsonFile, err := os.Open(o.Name())
if err != nil {
f.log.Error("VulnerabilityScanner.evaluate.jsonFile error: ", err)
return
}
defer jsonFile.Close()
f.log.Info("VulnerabilityScanner.evaluate.ReadAll")
byteValue, _ := ioutil.ReadAll(jsonFile)
var result trivy_types.Report
json.Unmarshal([]byte(byteValue), &result)
```
This is a quite a hack and I would like to simplify and remove this behavior.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.