refactor(config): localize config used like a global variable (#1179)
* refactor(report): LocalFileWriter * refactor -format-json * refacotr: -format-one-email * refactor: -format-csv * refactor: -gzip * refactor: -format-full-text * refactor: -format-one-line-text * refactor: -format-list * refacotr: remove -to-* from config * refactor: IgnoreGitHubDismissed * refactor: GitHub * refactor: IgnoreUnsocred * refactor: diff * refacotr: lang * refacotr: cacheDBPath * refactor: Remove config references * refactor: ScanResults * refacotr: constant pkg * chore: comment * refactor: scanner * refactor: scanner * refactor: serverapi.go * refactor: serverapi * refactor: change pkg structure * refactor: serverapi.go * chore: remove emtpy file * fix(scan): remove -ssh-native-insecure option * fix(scan): remove the deprecated option `keypassword`
This commit is contained in:
@@ -11,16 +11,17 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
c "github.com/future-architect/vuls/config"
|
||||
"github.com/future-architect/vuls/detector"
|
||||
"github.com/future-architect/vuls/models"
|
||||
"github.com/future-architect/vuls/report"
|
||||
"github.com/future-architect/vuls/scan"
|
||||
"github.com/future-architect/vuls/reporter"
|
||||
"github.com/future-architect/vuls/scanner"
|
||||
"github.com/future-architect/vuls/util"
|
||||
)
|
||||
|
||||
// VulsHandler is used for vuls server mode
|
||||
type VulsHandler struct {
|
||||
DBclient report.DBClient
|
||||
DBclient detector.DBClient
|
||||
ToLocalFile bool
|
||||
}
|
||||
|
||||
// ServeHTTP is http handler
|
||||
@@ -48,7 +49,7 @@ func (h VulsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if result, err = scan.ViaHTTP(req.Header, buf.String()); err != nil {
|
||||
if result, err = scanner.ViaHTTP(req.Header, buf.String(), h.ToLocalFile); err != nil {
|
||||
util.Log.Error(err)
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
@@ -59,13 +60,13 @@ func (h VulsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := report.DetectPkgCves(h.DBclient, &result); err != nil {
|
||||
if err := detector.DetectPkgCves(h.DBclient, &result); err != nil {
|
||||
util.Log.Errorf("Failed to detect Pkg CVE: %+v", err)
|
||||
http.Error(w, err.Error(), http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
if err := report.FillCveInfo(h.DBclient, &result); err != nil {
|
||||
if err := detector.FillCveInfo(h.DBclient, &result); err != nil {
|
||||
util.Log.Errorf("Failed to fill CVE detailed info: %+v", err)
|
||||
http.Error(w, err.Error(), http.StatusServiceUnavailable)
|
||||
return
|
||||
@@ -78,24 +79,26 @@ func (h VulsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
// report
|
||||
reports := []report.ResultWriter{
|
||||
report.HTTPResponseWriter{Writer: w},
|
||||
reports := []reporter.ResultWriter{
|
||||
reporter.HTTPResponseWriter{Writer: w},
|
||||
}
|
||||
if c.Conf.ToLocalFile {
|
||||
if h.ToLocalFile {
|
||||
scannedAt := result.ScannedAt
|
||||
if scannedAt.IsZero() {
|
||||
scannedAt = time.Now().Truncate(1 * time.Hour)
|
||||
result.ScannedAt = scannedAt
|
||||
}
|
||||
dir, err := scan.EnsureResultDir(scannedAt)
|
||||
dir, err := scanner.EnsureResultDir(scannedAt)
|
||||
if err != nil {
|
||||
util.Log.Errorf("Failed to ensure the result directory: %+v", err)
|
||||
http.Error(w, err.Error(), http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
reports = append(reports, report.LocalFileWriter{
|
||||
// sever subcmd doesn't have diff option
|
||||
reports = append(reports, reporter.LocalFileWriter{
|
||||
CurrentDir: dir,
|
||||
FormatJSON: true,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user