Skip to content

Commit affe8a4

Browse files
committed
Use errcheck, gosec, govulncheck
1 parent d133e5c commit affe8a4

6 files changed

Lines changed: 44 additions & 29 deletions

File tree

.github/workflows/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ jobs:
99
test_publish:
1010
name: Test and publish
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 10
1213
steps:
1314
- name: Checkout code
1415
uses: actions/checkout@v3
1516
with:
1617
fetch-depth: 0 # Needed to describe git ref during build.
1718

1819
- name: Export GOBIN
19-
uses: actions/setup-go@v3
20+
uses: actions/setup-go@v4
2021
with:
21-
go-version: '1.19'
22+
go-version: '1.20.2'
2223

2324
- name: Install dependencies
2425
run: make setup
@@ -30,7 +31,7 @@ jobs:
3031
run: make build
3132

3233
- name: Run GoReleaser
33-
uses: goreleaser/goreleaser-action@v2
34+
uses: goreleaser/goreleaser-action@v4
3435
if: startsWith(github.ref, 'refs/tags/v') # Only release for tagged commits.
3536
with:
3637
distribution: goreleaser

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
OUT_DIR := ./out
2+
GO_FILES := $(shell find . -type f \( -iname '*.go' \))
23

34
PBCLI_BUILD_VERSION ?= $(shell git describe --tags)
45
ifeq ($(PBCLI_BUILD_VERSION),)
@@ -20,14 +21,20 @@ clean:
2021
test:
2122
stdout=$$(gofumpt -l . 2>&1); if [ "$$stdout" ]; then exit 1; fi
2223
go vet ./...
23-
gocyclo -over 10 $(shell find . -type f -iname '*.go')
24+
gocyclo -over 10 $(GO_FILES)
2425
staticcheck ./...
26+
errcheck ./...
2527
go test -v -cover ./...
28+
gosec -exclude-dir=tests ./...
29+
govulncheck ./...
2630
@printf '\n%s\n' "> Test successful"
2731

2832
.PHONY: setup
2933
setup:
3034
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
35+
go install github.com/kisielk/errcheck@latest
36+
go install github.com/securego/gosec/v2/cmd/gosec@latest
37+
go install golang.org/x/vuln/cmd/govulncheck@latest
3138
go install honnef.co/go/tools/cmd/staticcheck@latest
3239
go install mvdan.cc/gofumpt@latest
3340

go.mod

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ module github.com/pushbits/cli
33
go 1.19
44

55
require (
6-
github.com/alecthomas/kong v0.5.0
7-
github.com/sirupsen/logrus v1.8.1
8-
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
6+
github.com/alecthomas/kong v0.7.1
7+
github.com/sirupsen/logrus v1.9.0
8+
golang.org/x/term v0.6.0
99
)
1010

11-
require (
12-
github.com/pkg/errors v0.9.1 // indirect
13-
golang.org/x/sys v0.0.0-20210603125802-9665404d3644 // indirect
14-
)
11+
require golang.org/x/sys v0.6.0 // indirect

go.sum

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
github.com/alecthomas/kong v0.5.0 h1:u8Kdw+eeml93qtMZ04iei0CFYve/WPcA5IFh+9wSskE=
2-
github.com/alecthomas/kong v0.5.0/go.mod h1:uzxf/HUh0tj43x1AyJROl3JT7SgsZ5m+icOv1csRhc0=
3-
github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48=
4-
github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
1+
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
2+
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
3+
github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
4+
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
55
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
77
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
9-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
8+
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
109
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1110
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12-
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
13-
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
11+
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
12+
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
1413
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15-
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
1614
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
1715
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
18-
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
20-
golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I=
21-
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22-
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
23-
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
16+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
17+
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
18+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
19+
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
20+
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
2421
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
2523
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
26-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
27-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/api/mod.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/url"
88
"strings"
99

10+
"github.com/pushbits/cli/internal/handling"
1011
log "github.com/sirupsen/logrus"
1112
)
1213

@@ -73,12 +74,12 @@ func Request(base, endpoint, method, proxy, username, password string, hasBody b
7374
if err != nil {
7475
log.Fatal(err)
7576
}
77+
defer handling.Close(resp.Body)
7678

7779
if resp.StatusCode != http.StatusOK {
7880
log.Fatalf("Request failed with HTTP %s.", resp.Status)
7981
}
8082

81-
defer resp.Body.Close()
8283
bodyText, err := io.ReadAll(resp.Body)
8384
if err != nil {
8485
log.Fatal(err)

internal/handling/handling.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package handling
2+
3+
import (
4+
"io"
5+
6+
log "github.com/sirupsen/logrus"
7+
)
8+
9+
func Close(c io.Closer) {
10+
if err := c.Close(); err != nil {
11+
log.Warn(err)
12+
}
13+
}

0 commit comments

Comments
 (0)