Change ScanResult.Packages structure to Map
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/howeyc/gopass"
|
||||
)
|
||||
|
||||
func getPasswd(prompt string) (string, error) {
|
||||
for {
|
||||
fmt.Print(prompt)
|
||||
pass, err := gopass.GetPasswdMasked()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to read password")
|
||||
}
|
||||
if 0 < len(pass) {
|
||||
return string(pass[:]), nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import (
|
||||
"github.com/future-architect/vuls/models"
|
||||
"github.com/future-architect/vuls/report"
|
||||
"github.com/future-architect/vuls/util"
|
||||
"github.com/howeyc/gopass"
|
||||
)
|
||||
|
||||
// jsonDirPattern is file name pattern of JSON directory
|
||||
@@ -190,11 +191,14 @@ func diff(curResults, preResults models.ScanResults) (diffed models.ScanResults,
|
||||
new, updated := getDiffCves(previous, current)
|
||||
current.ScannedCves = append(new, updated...)
|
||||
|
||||
current.Packages = models.Packages{}
|
||||
packages := models.Packages{}
|
||||
for _, s := range current.ScannedCves {
|
||||
current.Packages = append(current.Packages, s.Packages...)
|
||||
for _, pack := range s.Packages {
|
||||
p := current.Packages[pack.Name]
|
||||
packages[pack.Name] = p
|
||||
}
|
||||
}
|
||||
current.Packages = current.Packages.UniqByName()
|
||||
current.Packages = packages
|
||||
}
|
||||
|
||||
diffed = append(diffed, current)
|
||||
@@ -320,3 +324,17 @@ func needToRefreshCve(r models.ScanResult) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func getPasswd(prompt string) (string, error) {
|
||||
for {
|
||||
fmt.Print(prompt)
|
||||
pass, err := gopass.GetPasswdMasked()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Failed to read password")
|
||||
}
|
||||
if 0 < len(pass) {
|
||||
return string(pass[:]), nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ func TestDiff(t *testing.T) {
|
||||
{
|
||||
CveID: "CVE-2012-6702",
|
||||
Packages: models.Packages{
|
||||
{
|
||||
"libexpat1": {
|
||||
Name: "libexpat1",
|
||||
Version: "2.1.0-7",
|
||||
Release: "",
|
||||
@@ -216,7 +216,7 @@ func TestDiff(t *testing.T) {
|
||||
{
|
||||
CveID: "CVE-2014-9761",
|
||||
Packages: models.Packages{
|
||||
{
|
||||
"libc-bin": {
|
||||
Name: "libc-bin",
|
||||
Version: "2.21-0ubuntu5",
|
||||
Release: "",
|
||||
@@ -229,7 +229,7 @@ func TestDiff(t *testing.T) {
|
||||
CpeNames: []string{},
|
||||
},
|
||||
},
|
||||
Packages: []models.Package{},
|
||||
Packages: models.Packages{},
|
||||
Errors: []string{},
|
||||
Optional: [][]interface{}{},
|
||||
},
|
||||
@@ -244,7 +244,7 @@ func TestDiff(t *testing.T) {
|
||||
{
|
||||
CveID: "CVE-2012-6702",
|
||||
Packages: models.Packages{
|
||||
{
|
||||
"libexpat1": {
|
||||
Name: "libexpat1",
|
||||
Version: "2.1.0-7",
|
||||
Release: "",
|
||||
@@ -259,7 +259,7 @@ func TestDiff(t *testing.T) {
|
||||
{
|
||||
CveID: "CVE-2014-9761",
|
||||
Packages: models.Packages{
|
||||
{
|
||||
"libc-bin": {
|
||||
Name: "libc-bin",
|
||||
Version: "2.21-0ubuntu5",
|
||||
Release: "",
|
||||
@@ -272,7 +272,7 @@ func TestDiff(t *testing.T) {
|
||||
CpeNames: []string{},
|
||||
},
|
||||
},
|
||||
Packages: []models.Package{},
|
||||
Packages: models.Packages{},
|
||||
Errors: []string{},
|
||||
Optional: [][]interface{}{},
|
||||
},
|
||||
@@ -282,7 +282,7 @@ func TestDiff(t *testing.T) {
|
||||
ServerName: "u16",
|
||||
Family: "ubuntu",
|
||||
Release: "16.04",
|
||||
Packages: []models.Package{},
|
||||
Packages: models.Packages{},
|
||||
Errors: []string{},
|
||||
Optional: [][]interface{}{},
|
||||
},
|
||||
@@ -298,7 +298,7 @@ func TestDiff(t *testing.T) {
|
||||
{
|
||||
CveID: "CVE-2016-6662",
|
||||
Packages: models.Packages{
|
||||
{
|
||||
"mysql-libs": {
|
||||
Name: "mysql-libs",
|
||||
Version: "5.1.73",
|
||||
Release: "7.el6",
|
||||
@@ -331,7 +331,7 @@ func TestDiff(t *testing.T) {
|
||||
{
|
||||
CveID: "CVE-2016-6662",
|
||||
Packages: models.Packages{
|
||||
{
|
||||
"mysql-libs": {
|
||||
Name: "mysql-libs",
|
||||
Version: "5.1.73",
|
||||
Release: "7.el6",
|
||||
@@ -345,7 +345,7 @@ func TestDiff(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Packages: models.Packages{
|
||||
models.Package{
|
||||
"mysql-libs": {
|
||||
Name: "mysql-libs",
|
||||
Version: "5.1.73",
|
||||
Release: "7.el6",
|
||||
@@ -368,14 +368,14 @@ func TestDiff(t *testing.T) {
|
||||
if !reflect.DeepEqual(actual.ScannedCves, tt.out.ScannedCves) {
|
||||
h := pp.Sprint(actual.ScannedCves)
|
||||
x := pp.Sprint(tt.out.ScannedCves)
|
||||
t.Errorf("[%d] actual: \n %s \n expected: \n %s", i, h, x)
|
||||
t.Errorf("[%d] cves actual: \n %s \n expected: \n %s", i, h, x)
|
||||
}
|
||||
|
||||
for j := range tt.out.Packages {
|
||||
if !reflect.DeepEqual(tt.out.Packages[j], actual.Packages[j]) {
|
||||
h := pp.Sprint(tt.out.Packages[j])
|
||||
x := pp.Sprint(actual.Packages[j])
|
||||
t.Errorf("[%d] actual: \n %s \n expected: \n %s", i, x, h)
|
||||
t.Errorf("[%d] packages actual: \n %s \n expected: \n %s", i, x, h)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user