Skip to content

Commit

Permalink
chore: fix lint error (#1438)
Browse files Browse the repository at this point in the history
* chore: fix lint: revive error

* chore: golanci-lint uses go 1.18

* chore: refactor tasks in GNUmakefile

* chore: add trivy binary in fvuls image
  • Loading branch information
MaineK00n committed Apr 15, 2022
1 parent a9f29a6 commit 8775b5e
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
@@ -1,5 +1,9 @@
name: golang-ci

run:
timeout: 10m
go: '1.18'

linters-settings:
revive:
# see https://github.com/mgechev/revive#available-rules for details.
Expand Down
23 changes: 10 additions & 13 deletions GNUmakefile
Expand Up @@ -23,12 +23,9 @@ CGO_UNABLED := CGO_ENABLED=0 go
GO_OFF := GO111MODULE=off go


all: b
all: build test

build: ./cmd/vuls/main.go pretest fmt
$(GO) build -a -ldflags "$(LDFLAGS)" -o vuls ./cmd/vuls

b: ./cmd/vuls/main.go
build: ./cmd/vuls/main.go
$(GO) build -a -ldflags "$(LDFLAGS)" -o vuls ./cmd/vuls

install: ./cmd/vuls/main.go
Expand All @@ -41,13 +38,14 @@ install-scanner: ./cmd/scanner/main.go
$(CGO_UNABLED) install -tags=scanner -ldflags "$(LDFLAGS)" ./cmd/scanner

lint:
$(GO_OFF) get -u github.com/mgechev/revive
$(GO) install github.com/mgechev/revive@latest
revive -config ./.revive.toml -formatter plain $(PKGS)

vet:
echo $(PKGS) | xargs env $(GO) vet || exit;

golangci:
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run

fmt:
Expand All @@ -59,9 +57,9 @@ mlint:
fmtcheck:
$(foreach file,$(SRCS),gofmt -s -d $(file);)

pretest: lint vet fmtcheck golangci
pretest: lint vet fmtcheck

test:
test: pretest
$(GO) test -cover -v ./... || exit;

unused:
Expand All @@ -76,13 +74,12 @@ clean:
echo $(PKGS) | xargs go clean || exit;

# trivy-to-vuls
build-trivy-to-vuls: pretest fmt
$(GO) build -a -ldflags "$(LDFLAGS)" -o trivy-to-vuls contrib/trivy/cmd/*.go
build-trivy-to-vuls: ./contrib/trivy/cmd/main.go
$(GO) build -a -ldflags "$(LDFLAGS)" -o trivy-to-vuls ./contrib/trivy/cmd

# future-vuls
build-future-vuls: pretest fmt
$(GO) build -a -ldflags "$(LDFLAGS)" -o future-vuls contrib/future-vuls/cmd/*.go

build-future-vuls: ./contrib/future-vuls/cmd/main.go
$(GO) build -a -ldflags "$(LDFLAGS)" -o future-vuls ./contrib/future-vuls/cmd

# integration-test
BASE_DIR := '${PWD}/integration/results'
Expand Down
2 changes: 1 addition & 1 deletion contrib/Dockerfile
Expand Up @@ -5,7 +5,6 @@ RUN apk add --no-cache \
make \
gcc \
musl-dev
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.0

ENV REPOSITORY github.com/future-architect/vuls
COPY . $GOPATH/src/$REPOSITORY
Expand All @@ -27,6 +26,7 @@ RUN apk add --no-cache \
&& mkdir -p $WORKDIR $LOGDIR

COPY --from=builder /go/bin/vuls /go/bin/trivy-to-vuls /go/bin/future-vuls /usr/local/bin/
COPY --from=aquasec/trivy:latest /usr/local/bin/trivy /usr/local/bin/trivy

VOLUME ["$WORKDIR", "$LOGDIR"]
WORKDIR $WORKDIR
Expand Down
10 changes: 5 additions & 5 deletions detector/util.go
Expand Up @@ -130,7 +130,7 @@ func getPlusDiffCves(previous, current models.ScanResult) models.VulnInfos {
previousCveIDsSet[previousVulnInfo.CveID] = true
}

new := models.VulnInfos{}
newer := models.VulnInfos{}
updated := models.VulnInfos{}
for _, v := range current.ScannedCves {
if previousCveIDsSet[v.CveID] {
Expand All @@ -150,17 +150,17 @@ func getPlusDiffCves(previous, current models.ScanResult) models.VulnInfos {
logging.Log.Debugf("same: %s", v.CveID)
}
} else {
logging.Log.Debugf("new: %s", v.CveID)
logging.Log.Debugf("newer: %s", v.CveID)
v.DiffStatus = models.DiffPlus
new[v.CveID] = v
newer[v.CveID] = v
}
}

if len(updated) == 0 && len(new) == 0 {
if len(updated) == 0 && len(newer) == 0 {
logging.Log.Infof("%s: There are %d vulnerabilities, but no difference between current result and previous one.", current.FormatServerName(), len(current.ScannedCves))
}

for cveID, vuln := range new {
for cveID, vuln := range newer {
updated[cveID] = vuln
}
return updated
Expand Down
2 changes: 1 addition & 1 deletion gost/gost.go
Expand Up @@ -54,7 +54,7 @@ func FillCVEsWithRedHat(r *models.ScanResult, cnf config.GostConf, o logging.Log
return client.fillCvesWithRedHatAPI(r)
}

// NewClient make Client by family
// NewGostClient make Client by family
func NewGostClient(cnf config.GostConf, family string, o logging.LogOpts) (Client, error) {
if err := gostlog.SetLogger(o.LogToFile, o.LogDir, o.Debug, o.LogJSON); err != nil {
return nil, xerrors.Errorf("Failed to set gost logger. err: %w", err)
Expand Down
1 change: 1 addition & 0 deletions oval/pseudo.go
Expand Up @@ -18,6 +18,7 @@ func NewPseudo(family string) Pseudo {
}
}

// FillWithOval is a mock function for operating systems that do not use OVAL
func (pse Pseudo) FillWithOval(_ *models.ScanResult) (int, error) {
return 0, nil
}
10 changes: 5 additions & 5 deletions reporter/util.go
Expand Up @@ -623,7 +623,7 @@ func getPlusDiffCves(previous, current models.ScanResult) models.VulnInfos {
previousCveIDsSet[previousVulnInfo.CveID] = true
}

new := models.VulnInfos{}
newer := models.VulnInfos{}
updated := models.VulnInfos{}
for _, v := range current.ScannedCves {
if previousCveIDsSet[v.CveID] {
Expand All @@ -643,17 +643,17 @@ func getPlusDiffCves(previous, current models.ScanResult) models.VulnInfos {
logging.Log.Debugf("same: %s", v.CveID)
}
} else {
logging.Log.Debugf("new: %s", v.CveID)
logging.Log.Debugf("newer: %s", v.CveID)
v.DiffStatus = models.DiffPlus
new[v.CveID] = v
newer[v.CveID] = v
}
}

if len(updated) == 0 && len(new) == 0 {
if len(updated) == 0 && len(newer) == 0 {
logging.Log.Infof("%s: There are %d vulnerabilities, but no difference between current result and previous one.", current.FormatServerName(), len(current.ScannedCves))
}

for cveID, vuln := range new {
for cveID, vuln := range newer {
updated[cveID] = vuln
}
return updated
Expand Down
14 changes: 7 additions & 7 deletions reporter/util_test.go
Expand Up @@ -19,8 +19,8 @@ func TestMain(m *testing.M) {

func TestIsCveInfoUpdated(t *testing.T) {
f := "2006-01-02"
old, _ := time.Parse(f, "2015-12-15")
new, _ := time.Parse(f, "2015-12-16")
base, _ := time.Parse(f, "2015-12-15")
newer, _ := time.Parse(f, "2015-12-16")

type In struct {
cveID string
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestIsCveInfoUpdated(t *testing.T) {
models.CveContent{
Type: models.Jvn,
CveID: "CVE-2017-0002",
LastModified: old,
LastModified: base,
},
),
},
Expand All @@ -92,7 +92,7 @@ func TestIsCveInfoUpdated(t *testing.T) {
models.CveContent{
Type: models.Jvn,
CveID: "CVE-2017-0002",
LastModified: old,
LastModified: base,
},
),
},
Expand All @@ -114,7 +114,7 @@ func TestIsCveInfoUpdated(t *testing.T) {
models.CveContent{
Type: models.Nvd,
CveID: "CVE-2017-0002",
LastModified: new,
LastModified: newer,
},
),
},
Expand All @@ -129,7 +129,7 @@ func TestIsCveInfoUpdated(t *testing.T) {
models.CveContent{
Type: models.Nvd,
CveID: "CVE-2017-0002",
LastModified: old,
LastModified: base,
},
),
},
Expand All @@ -151,7 +151,7 @@ func TestIsCveInfoUpdated(t *testing.T) {
models.CveContent{
Type: models.Nvd,
CveID: "CVE-2017-0002",
LastModified: old,
LastModified: base,
},
),
},
Expand Down
20 changes: 10 additions & 10 deletions scanner/redhatbase.go
Expand Up @@ -784,49 +784,49 @@ func (o *redhatBase) getOwnerPkgs(paths []string) (names []string, _ error) {

func (o *redhatBase) rpmQa() string {
const old = `rpm -qa --queryformat "%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n"`
const new = `rpm -qa --queryformat "%{NAME} %{EPOCHNUM} %{VERSION} %{RELEASE} %{ARCH}\n"`
const newer = `rpm -qa --queryformat "%{NAME} %{EPOCHNUM} %{VERSION} %{RELEASE} %{ARCH}\n"`
switch o.Distro.Family {
case constant.OpenSUSE:
if o.Distro.Release == "tumbleweed" {
return new
return newer
}
return old
case constant.OpenSUSELeap:
return new
return newer
case constant.SUSEEnterpriseServer, constant.SUSEEnterpriseDesktop:
if v, _ := o.Distro.MajorVersion(); v < 12 {
return old
}
return new
return newer
default:
if v, _ := o.Distro.MajorVersion(); v < 6 {
return old
}
return new
return newer
}
}

func (o *redhatBase) rpmQf() string {
const old = `rpm -qf --queryformat "%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n" `
const new = `rpm -qf --queryformat "%{NAME} %{EPOCHNUM} %{VERSION} %{RELEASE} %{ARCH}\n" `
const newer = `rpm -qf --queryformat "%{NAME} %{EPOCHNUM} %{VERSION} %{RELEASE} %{ARCH}\n" `
switch o.Distro.Family {
case constant.OpenSUSE:
if o.Distro.Release == "tumbleweed" {
return new
return newer
}
return old
case constant.OpenSUSELeap:
return new
return newer
case constant.SUSEEnterpriseServer, constant.SUSEEnterpriseDesktop:
if v, _ := o.Distro.MajorVersion(); v < 12 {
return old
}
return new
return newer
default:
if v, _ := o.Distro.MajorVersion(); v < 6 {
return old
}
return new
return newer
}
}

Expand Down

0 comments on commit 8775b5e

Please sign in to comment.