* refactor: cve_client.go * refactor: don't use global Config in private func * remove import alias for config * refactor: dbclient * refactor: resultDir * refactor: resultsDir * refactor * refactor: gost * refactor: db client * refactor: cveDB * refactor: cvedb * refactor: exploitDB * refactor: remove detector/dbclient.go * refactor: writer * refactor: syslog writer * refactor: ips * refactor: ensureResultDir * refactor: proxy * fix(db): call CloseDB * add integration test * feat(report): sort array in json * sort func for json diff * add build-int to makefile * add int-rds-redis to makefile * fix: test case, makefile * fix makefile * show cve count after diff * make diff * diff -c * sort exploits in json for diff * sort metasploit, exploit
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package reporter
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/future-architect/vuls/models"
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
// HTTPRequestWriter writes results to HTTP request
|
|
type HTTPRequestWriter struct {
|
|
Proxy string
|
|
}
|
|
|
|
// Write sends results as HTTP response
|
|
func (w HTTPRequestWriter) Write(rs ...models.ScanResult) (err error) {
|
|
for _, r := range rs {
|
|
b := new(bytes.Buffer)
|
|
if err := json.NewEncoder(b).Encode(r); err != nil {
|
|
return err
|
|
}
|
|
_, err = http.Post(w.Proxy, "application/json; charset=utf-8", b)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// HTTPResponseWriter writes results to HTTP response
|
|
type HTTPResponseWriter struct {
|
|
Writer http.ResponseWriter
|
|
}
|
|
|
|
// Write sends results as HTTP response
|
|
func (w HTTPResponseWriter) Write(rs ...models.ScanResult) (err error) {
|
|
res, err := json.Marshal(rs)
|
|
if err != nil {
|
|
return xerrors.Errorf("Failed to marshal scan results: %w", err)
|
|
}
|
|
w.Writer.Header().Set("Content-Type", "application/json")
|
|
_, err = w.Writer.Write(res)
|
|
|
|
return err
|
|
}
|