From 648a999514a3b525706fee4706990aa670eeef63 Mon Sep 17 00:00:00 2001 From: kota kanbe Date: Fri, 18 Aug 2017 22:39:45 +0900 Subject: [PATCH] Include config in json result --- config/config.go | 8 ++++---- models/scanresults.go | 8 ++++++++ report/report.go | 7 +++++++ scan/serverapi.go | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index ee7ea41b..033ecc35 100644 --- a/config/config.go +++ b/config/config.go @@ -110,7 +110,7 @@ type Config struct { S3ResultsDir string AzureAccount string - AzureKey string + AzureKey string `json:"-"` AzureContainer string Pipe bool @@ -300,7 +300,7 @@ type SMTPConf struct { SMTPPort string `valid:"port"` User string - Password string + Password string `json:"-"` From string To []string Cc []string @@ -360,7 +360,7 @@ func (c *SMTPConf) Validate() (errs []error) { // SlackConf is slack config type SlackConf struct { - HookURL string `valid:"url"` + HookURL string `valid:"url" json:"-"` Channel string `json:"channel"` IconEmoji string `json:"icon_emoji"` AuthUser string `json:"username"` @@ -410,7 +410,7 @@ type ServerInfo struct { Host string Port string KeyPath string - KeyPassword string + KeyPassword string `json:"-"` CpeNames []string DependencyCheckXMLPath string diff --git a/models/scanresults.go b/models/scanresults.go index 5c3076a0..60024eab 100644 --- a/models/scanresults.go +++ b/models/scanresults.go @@ -21,6 +21,8 @@ import ( "bytes" "fmt" "time" + + "github.com/future-architect/vuls/config" ) // ScanResults is a slide of ScanResult @@ -29,6 +31,7 @@ type ScanResults []ScanResult // ScanResult has the result of scanned CVE information. type ScanResult struct { ScannedAt time.Time + ReportedAt time.Time JSONVersion int Lang string ServerUUID string @@ -44,6 +47,11 @@ type ScanResult struct { Packages Packages Errors []string Optional [][]interface{} + + Config struct { + Scan config.Config + Report config.Config + } } // FilterByCvssOver is filter function. diff --git a/report/report.go b/report/report.go index ba0922d8..cd304885 100644 --- a/report/report.go +++ b/report/report.go @@ -20,6 +20,7 @@ package report import ( "fmt" "strings" + "time" c "github.com/future-architect/vuls/config" "github.com/future-architect/vuls/models" @@ -35,12 +36,18 @@ const ( // FillCveInfos fills CVE Detailed Information func FillCveInfos(rs []models.ScanResult, dir string) ([]models.ScanResult, error) { var filled []models.ScanResult + reportedAt := time.Now() for _, r := range rs { if c.Conf.RefreshCve || needToRefreshCve(r) { if err := fillCveInfo(&r); err != nil { return nil, err } r.Lang = c.Conf.Lang + r.ReportedAt = reportedAt + r.Config.Report = c.Conf + r.Config.Report.Servers = map[string]c.ServerInfo{ + r.ServerName: c.Conf.Servers[r.ServerName], + } if err := overwriteJSONFile(dir, r); err != nil { return nil, fmt.Errorf("Failed to write JSON: %s", err) } diff --git a/scan/serverapi.go b/scan/serverapi.go index d8008553..71898e74 100644 --- a/scan/serverapi.go +++ b/scan/serverapi.go @@ -449,6 +449,7 @@ func scanVulns(jsonDir string, scannedAt time.Time, timeoutSec int) error { for _, s := range append(servers, errServers...) { r := s.convertToModel() r.ScannedAt = scannedAt + r.Config.Scan = config.Conf results = append(results, r) }