From f6dfa5d0043aeaa616c16f8babb64c0d0e8f72dd Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 21 May 2020 10:52:19 +1000 Subject: [PATCH 01/13] Add .golangci.yml linter configuration As part of https://gitlab.com/gitlab-org/gitlab-pages/-/issues/385 we have introduced the use of a custom `.golangci.yml` file with some custom rules for linting. This replaces the need of downloading and using `golint`, `gofmt` `go vet` and `gocyclo` manually. We take advantage of the custom `golangci-lint` docker image as stated in the [Automatic lintinb] (https://docs.gitlab.com/ee/development/go_guide/#automatic-linting) section of the Go standards and style guidelines. This iteration enables a subset of linters, with the remaining of them enabled on a separate MR as described in the issue above. The main changes introduced by this linter include: - gosec: potential hardcoded credentials - goconst: DRY by declaring and using constants - gosimple: reduce statements complexity and improve return statements --- .gitignore | 2 + .gitlab-ci.yml | 26 ++++++++++--- .golangci.yml | 60 ++++++++++++++++++++++++++++++ Makefile.build.mk | 3 -- Makefile.util.mk | 19 +++------- app.go | 6 +-- go.mod | 33 +++++++++++++++- go.sum | 15 ++++++++ helpers_test.go | 13 ++++--- internal/artifact/artifact.go | 1 - internal/artifact/artifact_test.go | 2 +- internal/auth/auth.go | 14 +++---- internal/auth/auth_test.go | 27 ++++++++------ internal/serving/disk/serving.go | 6 +-- internal/source/disk/disk.go | 4 +- main.go | 5 ++- multi_string_flag_test.go | 5 +-- 17 files changed, 173 insertions(+), 68 deletions(-) create mode 100644 .golangci.yml diff --git a/.gitignore b/.gitignore index 7c50688bf..ef404e9f5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ shared/pages/.update /gitlab-pages /vendor /gitlab-pages-config +/gl-code-quality-report.json +/coverage.html # Used by the makefile /.GOPATH diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d640f08b5..01732f454 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -86,19 +86,33 @@ download deps: - go.mod - go.sum -verify: - extends: .go-mod-cache +cover: stage: test + extends: .go-mod-cache needs: ['download deps'] script: - - make setup - - make generate-mocks - - make verify - - make cover + - make setup + - make generate-mocks + - make cover artifacts: paths: - coverage.html +lint: + extends: .go-mod-cache + needs: ['download deps'] + stage: test + image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine + script: + # Write the code coverage report to gl-code-quality-report.json + # and print linting issues to stdout in the format: path/to/file:line description + - golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' + artifacts: + reports: + codequality: gl-code-quality-report.json + paths: + - gl-code-quality-report.json + test:1.12: extends: .tests image: golang:1.12 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..9545dd52e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,60 @@ +run: + concurrency: 8 + deadline: 1m + issues-exit-code: 1 + modules-download-mode: vendor + tests: true + skip-dirs: + - vendor + - internal/httputil # from github.com/golang/gddo + skip-files: + - mock_*.go + +output: + format: colored-line-number + print-issued-lines: true + print-linter-name: true + +linters-settings: + gocyclo: + min-complexity: 10 + govet: + check-shadowing: false + goconst: + min-len: 3 + min-occurrences: 3 + +linters: + disable-all: true + enable: +# TODO: enable these linters on a separate MR https://gitlab.com/gitlab-org/gitlab-pages/-/issues/385#linters +# - bodyclose +# - deadcode +# - dogsled + - goconst + - gocyclo + - goimports + - golint + - gosimple + - govet + - gosec +# - ineffassign +# - misspell +# - structcheck +# - typecheck +# - unconvert +# - unused +# - varcheck +# - whitespace + fast: false + +issues: +# # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + - path: ".*_test.go" + linters: + - bodyclose + - gosec + - path: "internal/fixture/fixtures.go" + linters: + - gosec diff --git a/Makefile.build.mk b/Makefile.build.mk index 24c2ec39d..9a40f68b3 100644 --- a/Makefile.build.mk +++ b/Makefile.build.mk @@ -3,10 +3,7 @@ all: gitlab-pages setup: clean .GOPATH/.ok - go get golang.org/x/tools/cmd/goimports@v0.0.0-20191010201905-e5ffc44a6fee - go get golang.org/x/lint/golint@v0.0.0-20190930215403-16217165b5de go get github.com/wadey/gocovmerge@v0.0.0-20160331181800-b5bfa59ec0ad - go get github.com/fzipp/gocyclo@v0.0.0-20150627053110-6acd4345c835 go get github.com/golang/mock/mockgen@v1.3.1 generate-mocks: .GOPATH/.ok diff --git a/Makefile.util.mk b/Makefile.util.mk index 412b76550..dfc2c8fd1 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -1,18 +1,11 @@ -.PHONY: verify fmt vet lint complexity test cover list +GOLANGCI_LINT_IMAGE := registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine -verify: list fmt vet lint complexity +.PHONY: lint test race acceptance bench cover list deps-check deps-download -fmt: bin/goimports .GOPATH/.ok - $Q @_support/validate-formatting.sh $(allfiles) - -vet: .GOPATH/.ok - $Q go vet $(allpackages) - -lint: bin/golint - $Q ./bin/golint $(allpackages) | tee | ( ! grep -v "^$$" ) - -complexity: .GOPATH/.ok bin/gocyclo - $Q ./bin/gocyclo -over 9 $(allfiles) +lint: deps-download + docker run -v $(PWD):/app -w /app $(GOLANGCI_LINT_IMAGE) \ + sh -c "golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | \"\(.location.path):\(.location.lines.begin) \(.description)\"'" +# sh -c "golangci-lint run $(if $V,-v)" test: .GOPATH/.ok gitlab-pages go test $(if $V,-v) $(allpackages) diff --git a/app.go b/app.go index fa8dc04f2..8cfeef002 100644 --- a/app.go +++ b/app.go @@ -83,7 +83,7 @@ func (a *theApp) healthCheck(w http.ResponseWriter, r *http.Request, https bool) func (a *theApp) redirectToHTTPS(w http.ResponseWriter, r *http.Request, statusCode int) { u := *r.URL - u.Scheme = "https" + u.Scheme = request.SchemeHTTPS u.Host = r.Host u.User = nil @@ -400,7 +400,7 @@ func (a *theApp) listenHTTPFD(wg *sync.WaitGroup, fd uintptr, httpHandler http.H defer wg.Done() err := listenAndServe(fd, httpHandler, a.HTTP2, nil, limiter) if err != nil { - capturingFatal(err, errortracking.WithField("listener", "http")) + capturingFatal(err, errortracking.WithField("listener", request.SchemeHTTP)) } }() } @@ -411,7 +411,7 @@ func (a *theApp) listenHTTPSFD(wg *sync.WaitGroup, fd uintptr, httpHandler http. defer wg.Done() err := listenAndServeTLS(fd, a.RootCertificate, a.RootKey, httpHandler, a.ServeTLS, a.InsecureCiphers, a.TLSMinVersion, a.TLSMaxVersion, a.HTTP2, limiter) if err != nil { - capturingFatal(err, errortracking.WithField("listener", "https")) + capturingFatal(err, errortracking.WithField("listener", request.SchemeHTTPS)) } }() } diff --git a/go.mod b/go.mod index d33140f73..876c7c344 100644 --- a/go.mod +++ b/go.mod @@ -3,29 +3,60 @@ module gitlab.com/gitlab-org/gitlab-pages go 1.12 require ( + github.com/certifi/gocertifi v0.0.0-20180905225744-ee1a9a0726d2 // indirect + github.com/client9/reopen v1.0.0 // indirect + github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835 + github.com/getsentry/raven-go v0.1.0 // indirect + github.com/getsentry/sentry-go v0.5.1 // indirect + github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 // indirect + github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 // indirect + github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 // indirect github.com/golang/mock v1.3.1 + github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc // indirect github.com/gorilla/context v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/securecookie v1.1.1 github.com/gorilla/sessions v1.2.0 + github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect + github.com/jstemmer/go-junit-report v0.9.1 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/karrick/godirwalk v1.10.12 + github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect + github.com/lightstep/lightstep-tracer-go v0.15.6 // indirect github.com/namsral/flag v1.7.4-pre + github.com/opentracing/opentracing-go v1.0.2 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible + github.com/philhofer/fwd v1.0.0 // indirect github.com/prometheus/client_golang v1.1.0 + github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect github.com/rs/cors v1.7.0 + github.com/sebest/xff v0.0.0-20160910043805-6c115e0ffa35 // indirect github.com/sirupsen/logrus v1.4.2 github.com/stretchr/testify v1.4.0 + github.com/tinylib/msgp v1.0.2 // indirect github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce + github.com/uber-go/atomic v1.3.2 // indirect + github.com/uber/jaeger-client-go v2.15.0+incompatible // indirect + github.com/uber/jaeger-lib v1.5.0 // indirect github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad - gitlab.com/gitlab-org/labkit v0.0.0-20200414155917-f06e28fff6fa + gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891 gitlab.com/lupine/go-mimedb v0.0.0-20180307000149-e8af1d659877 + go.opencensus.io v0.22.2 // indirect + go.uber.org/atomic v1.3.2 // indirect golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f + golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee // indirect golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa + golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect + golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect golang.org/x/sys v0.0.0-20200113162924-86b910548bc1 golang.org/x/tools v0.0.0-20200117161641-43d50277825c + google.golang.org/api v0.15.0 // indirect + google.golang.org/appengine v1.6.5 // indirect + google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba // indirect + google.golang.org/grpc v1.24.0 // indirect + gopkg.in/DataDog/dd-trace-go.v1 v1.7.0 // indirect gopkg.in/yaml.v2 v2.2.8 ) diff --git a/go.sum b/go.sum index 6031c75f7..6e4ce1fdf 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,9 @@ cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6A cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.47.0/go.mod h1:5p3Ky/7f3N10VBkhuR5LFtddroTiMyjZV/Kj5qOQFxU= +cloud.google.com/go v0.48.0/go.mod h1:gGOnoa/XMQYHAscREBlbdHduGchEaP9N0//OXdrPI/M= +cloud.google.com/go v0.49.0/go.mod h1:hGvAdzcWNbyuxS3nWhD7H2cIJxjRRTRLQVB0bdputVY= cloud.google.com/go v0.50.0 h1:0E3eE8MX426vUOs7aHfI7aN1BrIzzzf4ccKCSfSjGmc= cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= cloud.google.com/go/bigquery v1.0.1 h1:hL+ycaJpVE9M7nLoiXb/Pn10ENE2u+oddxbD8uu0ZVU= @@ -75,6 +78,7 @@ github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/ github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -294,6 +298,8 @@ github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDf github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= gitlab.com/gitlab-org/labkit v0.0.0-20200414155917-f06e28fff6fa h1:KCrfuAvyh2XTBMUpPPXd9CtgAIhtqtuzrT72oCm4K34= gitlab.com/gitlab-org/labkit v0.0.0-20200414155917-f06e28fff6fa/go.mod h1:SNfxkfUwVNECgtmluVayv0GWFgEjjBs5AzgsowPQuo0= +gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891 h1:WiCGS5C0B0h+/dh5O7kUJoEZt34O/tbsis9QghNB3gE= +gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891/go.mod h1:SNfxkfUwVNECgtmluVayv0GWFgEjjBs5AzgsowPQuo0= gitlab.com/lupine/go-mimedb v0.0.0-20180307000149-e8af1d659877 h1:k5N2m0IPaMuwWmFTO9fyTK4IEnSm35GC/p1S7VRgUyM= gitlab.com/lupine/go-mimedb v0.0.0-20180307000149-e8af1d659877/go.mod h1:Es0wDVbtgNqhpEXMb+yct6JKnGMrNsUSh9oio0bqqdU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -313,6 +319,8 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20191227195350-da58074b4299 h1:zQpM52jfKHG6II1ISZY1ZcpygvuSFZpLwfluuF89XOg= golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= @@ -324,6 +332,8 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= @@ -411,6 +421,10 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191010171213-8abd42400456/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191010201905-e5ffc44a6fee h1:Cgj5oVkw7Gktu56MAiU0r1u0jyuT6jmtOzcAJwLj89c= +golang.org/x/tools v0.0.0-20191010201905-e5ffc44a6fee/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= @@ -443,6 +457,7 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba h1:pRj9OXZbwNtbtZtOB4dLwfK4u+EVRMvP+e9zKkg2grM= google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= diff --git a/helpers_test.go b/helpers_test.go index 195c3cea8..60fba9f5a 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -20,6 +20,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitlab-pages/internal/fixture" + "gitlab.com/gitlab-org/gitlab-pages/internal/request" ) type tWriter struct { @@ -116,9 +117,9 @@ type ListenSpec struct { } func (l ListenSpec) URL(suffix string) string { - scheme := "http" - if l.Type == "https" { - scheme = "https" + scheme := request.SchemeHTTP + if l.Type == request.SchemeHTTPS { + scheme = request.SchemeHTTPS } suffix = strings.TrimPrefix(suffix, "/") @@ -262,7 +263,7 @@ func getPagesArgs(t *testing.T, listeners []ListenSpec, promPort string, extraAr for _, spec := range listeners { args = append(args, "-listen-"+spec.Type, spec.JoinHostPort()) - if spec.Type == "https" { + if spec.Type == request.SchemeHTTPS { hasHTTPS = true } } @@ -362,9 +363,9 @@ func GetRedirectPage(t *testing.T, spec ListenSpec, host, urlsuffix string) (*ht } func GetProxyRedirectPageWithCookie(t *testing.T, spec ListenSpec, host string, urlsuffix string, cookie string, https bool) (*http.Response, error) { - schema := "http" + schema := request.SchemeHTTP if https { - schema = "https" + schema = request.SchemeHTTPS } header := http.Header{ "X-Forwarded-Proto": []string{schema}, diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go index ef173d9e7..d11a7ebd3 100644 --- a/internal/artifact/artifact.go +++ b/internal/artifact/artifact.go @@ -121,7 +121,6 @@ func (a *Artifact) makeRequest(w http.ResponseWriter, r *http.Request, reqURL *u w.Header().Set("Content-Length", strconv.FormatInt(resp.ContentLength, 10)) w.WriteHeader(resp.StatusCode) io.Copy(w, resp.Body) - return } func addCacheHeader(w http.ResponseWriter, resp *http.Response) { diff --git a/internal/artifact/artifact_test.go b/internal/artifact/artifact_test.go index 6425f7915..a55eda7ba 100644 --- a/internal/artifact/artifact_test.go +++ b/internal/artifact/artifact_test.go @@ -83,7 +83,7 @@ func TestTryMakeRequest(t *testing.T) { require.Equal(t, c.ContentType, result.Header().Get("Content-Type")) require.Equal(t, c.Length, result.Header().Get("Content-Length")) require.Equal(t, c.CacheControl, result.Header().Get("Cache-Control")) - require.Equal(t, c.Content, string(result.Body.Bytes())) + require.Equal(t, c.Content, result.Body.String()) }) } diff --git a/internal/auth/auth.go b/internal/auth/auth.go index c582d96b2..a89dd5999 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -26,6 +26,9 @@ import ( "golang.org/x/crypto/hkdf" ) +// nolint: gosec +// gosec: G101: Potential hardcoded credentials +// auth constants, not credentials const ( apiURLUserTemplate = "%s/api/v4/user" apiURLProjectTemplate = "%s/api/v4/projects/%d/pages_access" @@ -433,10 +436,7 @@ func destroySession(session *sessions.Session, w http.ResponseWriter, r *http.Re // IsAuthSupported checks if pages is running with the authentication support func (a *Auth) IsAuthSupported() bool { - if a == nil { - return false - } - return true + return a != nil } func (a *Auth) checkAuthentication(w http.ResponseWriter, r *http.Request, projectID uint64) bool { @@ -513,11 +513,7 @@ func (a *Auth) GetTokenIfExists(w http.ResponseWriter, r *http.Request) (string, // RequireAuth will trigger authentication flow if no token exists func (a *Auth) RequireAuth(w http.ResponseWriter, r *http.Request) bool { - session := a.checkSessionIsValid(w, r) - if session == nil { - return true - } - return false + return a.checkSessionIsValid(w, r) == nil } // CheckAuthentication checks if user is authenticated and has access to the project diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 4a5d63fa9..87cc988dc 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -16,6 +16,11 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/source" ) +const ( + testAccessToken = "abc" + apiPagesAccess = "/api/v4/projects/1000/pages_access" +) + func createAuth(t *testing.T) *Auth { return New("pages.gitlab-example.com", "something-very-secret", @@ -98,7 +103,7 @@ func testTryAuthenticateWithCodeAndState(t *testing.T, https bool) { require.Equal(t, "POST", r.Method) w.WriteHeader(http.StatusOK) fmt.Fprint(w, "{\"access_token\":\"abc\"}") - case "/api/v4/projects/1000/pages_access": + case apiPagesAccess: require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusOK) default: @@ -150,7 +155,7 @@ func TestTryAuthenticateWithCodeAndStateOverHTTPS(t *testing.T) { func TestCheckAuthenticationWhenAccess(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case "/api/v4/projects/1000/pages_access": + case apiPagesAccess: require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusOK) default: @@ -178,7 +183,7 @@ func TestCheckAuthenticationWhenAccess(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = "abc" + session.Values["access_token"] = testAccessToken session.Save(r, result) require.Equal(t, false, auth.CheckAuthentication(result, r, 1000)) @@ -188,7 +193,7 @@ func TestCheckAuthenticationWhenAccess(t *testing.T) { func TestCheckAuthenticationWhenNoAccess(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case "/api/v4/projects/1000/pages_access": + case apiPagesAccess: require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusUnauthorized) default: @@ -216,7 +221,7 @@ func TestCheckAuthenticationWhenNoAccess(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = "abc" + session.Values["access_token"] = testAccessToken session.Save(r, result) require.Equal(t, true, auth.CheckAuthentication(result, r, 1000)) @@ -226,7 +231,7 @@ func TestCheckAuthenticationWhenNoAccess(t *testing.T) { func TestCheckAuthenticationWhenInvalidToken(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case "/api/v4/projects/1000/pages_access": + case apiPagesAccess: require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusUnauthorized) fmt.Fprint(w, "{\"error\":\"invalid_token\"}") @@ -254,7 +259,7 @@ func TestCheckAuthenticationWhenInvalidToken(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = "abc" + session.Values["access_token"] = testAccessToken session.Save(r, result) require.Equal(t, true, auth.CheckAuthentication(result, r, 1000)) @@ -292,7 +297,7 @@ func TestCheckAuthenticationWithoutProject(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = "abc" + session.Values["access_token"] = testAccessToken session.Save(r, result) require.Equal(t, false, auth.CheckAuthenticationWithoutProject(result, r)) @@ -329,7 +334,7 @@ func TestCheckAuthenticationWithoutProjectWhenInvalidToken(t *testing.T) { require.NoError(t, err) r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = "abc" + session.Values["access_token"] = testAccessToken session.Save(r, result) require.Equal(t, true, auth.CheckAuthenticationWithoutProject(result, r)) @@ -358,11 +363,11 @@ func TestGetTokenIfExistsWhenTokenExists(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = "abc" + session.Values["access_token"] = testAccessToken session.Save(r, result) token, err := auth.GetTokenIfExists(result, r) - require.Equal(t, "abc", token) + require.Equal(t, testAccessToken, token) } func TestGetTokenIfExistsWhenTokenDoesNotExist(t *testing.T) { diff --git a/internal/serving/disk/serving.go b/internal/serving/disk/serving.go index 682791fe3..b4c1ba969 100644 --- a/internal/serving/disk/serving.go +++ b/internal/serving/disk/serving.go @@ -15,11 +15,7 @@ type Disk struct { // ServeFileHTTP serves a file from disk and returns true. It returns false // when a file could not been found. func (s *Disk) ServeFileHTTP(h serving.Handler) bool { - if s.reader.tryFile(h) == nil { - return true - } - - return false + return s.reader.tryFile(h) == nil } // ServeNotFoundHTTP tries to read a custom 404 page diff --git a/internal/source/disk/disk.go b/internal/source/disk/disk.go index b79d222de..272d6c4ee 100644 --- a/internal/source/disk/disk.go +++ b/internal/source/disk/disk.go @@ -31,9 +31,7 @@ func (d *Disk) GetDomain(host string) (*domain.Domain, error) { d.lock.RLock() defer d.lock.RUnlock() - domain, _ := d.dm[host] - - return domain, nil + return d.dm[host], nil } // IsReady checks if the domains source is ready for work. The disk source is diff --git a/main.go b/main.go index 010fbbdd1..755789138 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/host" "gitlab.com/gitlab-org/gitlab-pages/internal/logging" + "gitlab.com/gitlab-org/gitlab-pages/internal/request" "gitlab.com/gitlab-org/gitlab-pages/internal/tlsconfig" "gitlab.com/gitlab-org/gitlab-pages/internal/validateargs" "gitlab.com/gitlab-org/gitlab-pages/metrics" @@ -123,8 +124,8 @@ func setArtifactsServer(artifactsServer string, artifactsServerTimeout int, conf if err != nil { log.Fatal(err) } - // url.Parse ensures that the Scheme arttribute is always lower case. - if u.Scheme != "http" && u.Scheme != "https" { + // url.Parse ensures that the Scheme attribute is always lower case. + if u.Scheme != request.SchemeHTTP && u.Scheme != request.SchemeHTTPS { errortracking.Capture(err) log.Fatal(errArtifactSchemaUnsupported) } diff --git a/multi_string_flag_test.go b/multi_string_flag_test.go index 5cddac98c..c09f7225c 100644 --- a/multi_string_flag_test.go +++ b/multi_string_flag_test.go @@ -1,7 +1,6 @@ package main import ( - "flag" "testing" "github.com/stretchr/testify/require" @@ -9,9 +8,7 @@ import ( func TestMultiStringFlagAppendsOnSet(t *testing.T) { var concrete MultiStringFlag - var iface flag.Value - - iface = &concrete + iface := &concrete require.NoError(t, iface.Set("foo")) require.NoError(t, iface.Set("bar")) -- GitLab From ab4652942d3f5326f6166be300b7988c9c3df101 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 21 May 2020 11:06:39 +1000 Subject: [PATCH 02/13] Use readonly for modules in linter --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 9545dd52e..374475bc0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,7 +2,7 @@ run: concurrency: 8 deadline: 1m issues-exit-code: 1 - modules-download-mode: vendor + modules-download-mode: readonly tests: true skip-dirs: - vendor -- GitLab From a074c8681357de8d53df4ce123630ea157695826 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 21 May 2020 11:21:12 +1000 Subject: [PATCH 03/13] Update dependencies --- go.mod | 26 -------------------------- go.sum | 15 --------------- 2 files changed, 41 deletions(-) diff --git a/go.mod b/go.mod index 876c7c344..bf1980f59 100644 --- a/go.mod +++ b/go.mod @@ -3,54 +3,28 @@ module gitlab.com/gitlab-org/gitlab-pages go 1.12 require ( - github.com/certifi/gocertifi v0.0.0-20180905225744-ee1a9a0726d2 // indirect - github.com/client9/reopen v1.0.0 // indirect - github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835 - github.com/getsentry/raven-go v0.1.0 // indirect - github.com/getsentry/sentry-go v0.5.1 // indirect - github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 // indirect - github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72 // indirect - github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 // indirect github.com/golang/mock v1.3.1 - github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc // indirect github.com/gorilla/context v1.1.1 github.com/gorilla/handlers v1.4.2 github.com/gorilla/securecookie v1.1.1 github.com/gorilla/sessions v1.2.0 - github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect - github.com/jstemmer/go-junit-report v0.9.1 // indirect github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/karrick/godirwalk v1.10.12 - github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect - github.com/lightstep/lightstep-tracer-go v0.15.6 // indirect github.com/namsral/flag v1.7.4-pre - github.com/opentracing/opentracing-go v1.0.2 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/philhofer/fwd v1.0.0 // indirect github.com/prometheus/client_golang v1.1.0 - github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect github.com/rs/cors v1.7.0 - github.com/sebest/xff v0.0.0-20160910043805-6c115e0ffa35 // indirect github.com/sirupsen/logrus v1.4.2 github.com/stretchr/testify v1.4.0 - github.com/tinylib/msgp v1.0.2 // indirect github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce - github.com/uber-go/atomic v1.3.2 // indirect - github.com/uber/jaeger-client-go v2.15.0+incompatible // indirect - github.com/uber/jaeger-lib v1.5.0 // indirect github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891 gitlab.com/lupine/go-mimedb v0.0.0-20180307000149-e8af1d659877 - go.opencensus.io v0.22.2 // indirect - go.uber.org/atomic v1.3.2 // indirect golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f - golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee // indirect golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa - golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect - golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect golang.org/x/sys v0.0.0-20200113162924-86b910548bc1 golang.org/x/tools v0.0.0-20200117161641-43d50277825c google.golang.org/api v0.15.0 // indirect diff --git a/go.sum b/go.sum index 6e4ce1fdf..89b924aa4 100644 --- a/go.sum +++ b/go.sum @@ -6,9 +6,6 @@ cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6A cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.47.0/go.mod h1:5p3Ky/7f3N10VBkhuR5LFtddroTiMyjZV/Kj5qOQFxU= -cloud.google.com/go v0.48.0/go.mod h1:gGOnoa/XMQYHAscREBlbdHduGchEaP9N0//OXdrPI/M= -cloud.google.com/go v0.49.0/go.mod h1:hGvAdzcWNbyuxS3nWhD7H2cIJxjRRTRLQVB0bdputVY= cloud.google.com/go v0.50.0 h1:0E3eE8MX426vUOs7aHfI7aN1BrIzzzf4ccKCSfSjGmc= cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= cloud.google.com/go/bigquery v1.0.1 h1:hL+ycaJpVE9M7nLoiXb/Pn10ENE2u+oddxbD8uu0ZVU= @@ -78,7 +75,6 @@ github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/ github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -296,8 +292,6 @@ github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmv github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= -gitlab.com/gitlab-org/labkit v0.0.0-20200414155917-f06e28fff6fa h1:KCrfuAvyh2XTBMUpPPXd9CtgAIhtqtuzrT72oCm4K34= -gitlab.com/gitlab-org/labkit v0.0.0-20200414155917-f06e28fff6fa/go.mod h1:SNfxkfUwVNECgtmluVayv0GWFgEjjBs5AzgsowPQuo0= gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891 h1:WiCGS5C0B0h+/dh5O7kUJoEZt34O/tbsis9QghNB3gE= gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891/go.mod h1:SNfxkfUwVNECgtmluVayv0GWFgEjjBs5AzgsowPQuo0= gitlab.com/lupine/go-mimedb v0.0.0-20180307000149-e8af1d659877 h1:k5N2m0IPaMuwWmFTO9fyTK4IEnSm35GC/p1S7VRgUyM= @@ -319,8 +313,6 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20191227195350-da58074b4299 h1:zQpM52jfKHG6II1ISZY1ZcpygvuSFZpLwfluuF89XOg= golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= @@ -332,8 +324,6 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE= golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= @@ -421,10 +411,6 @@ golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191010171213-8abd42400456/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191010201905-e5ffc44a6fee h1:Cgj5oVkw7Gktu56MAiU0r1u0jyuT6jmtOzcAJwLj89c= -golang.org/x/tools v0.0.0-20191010201905-e5ffc44a6fee/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= @@ -457,7 +443,6 @@ google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba h1:pRj9OXZbwNtbtZtOB4dLwfK4u+EVRMvP+e9zKkg2grM= google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -- GitLab From 0bfbd56c4de5c74dae1952e107e7b3a60fcdcc88 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 21 May 2020 12:07:43 +1000 Subject: [PATCH 04/13] Add missing coverage --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 01732f454..5d350f0a4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -94,6 +94,7 @@ cover: - make setup - make generate-mocks - make cover + coverage: '/total:.+\(statements\).+\d+\.\d+/' artifacts: paths: - coverage.html -- GitLab From 1564ca1df0155350d01692eb1a4781cde763edac Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 21 May 2020 12:11:03 +1000 Subject: [PATCH 05/13] Fix odd formatting --- .gitlab-ci.yml | 12 ++++++------ Makefile.util.mk | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5d350f0a4..772dbbde1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -91,9 +91,9 @@ cover: extends: .go-mod-cache needs: ['download deps'] script: - - make setup - - make generate-mocks - - make cover + - make setup + - make generate-mocks + - make cover coverage: '/total:.+\(statements\).+\d+\.\d+/' artifacts: paths: @@ -109,10 +109,10 @@ lint: # and print linting issues to stdout in the format: path/to/file:line description - golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' artifacts: - reports: + reports: codequality: gl-code-quality-report.json - paths: - - gl-code-quality-report.json + paths: + - gl-code-quality-report.json test:1.12: extends: .tests diff --git a/Makefile.util.mk b/Makefile.util.mk index dfc2c8fd1..2d90172ab 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -5,7 +5,6 @@ GOLANGCI_LINT_IMAGE := registry.gitlab.com/gitlab-org/gitlab-build-images:golang lint: deps-download docker run -v $(PWD):/app -w /app $(GOLANGCI_LINT_IMAGE) \ sh -c "golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | \"\(.location.path):\(.location.lines.begin) \(.description)\"'" -# sh -c "golangci-lint run $(if $V,-v)" test: .GOPATH/.ok gitlab-pages go test $(if $V,-v) $(allpackages) -- GitLab From 9051ec94f18b67f4729da2a432591785643bd785 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 21 May 2020 12:14:32 +1000 Subject: [PATCH 06/13] Consolidate ordering in CI config --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 772dbbde1..bb87d51fa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -87,8 +87,8 @@ download deps: - go.sum cover: - stage: test extends: .go-mod-cache + stage: test needs: ['download deps'] script: - make setup @@ -101,8 +101,8 @@ cover: lint: extends: .go-mod-cache - needs: ['download deps'] stage: test + needs: ['download deps'] image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine script: # Write the code coverage report to gl-code-quality-report.json -- GitLab From febba427ebf268ac498f0eda09d5f9818ff2bf10 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Fri, 22 May 2020 14:40:50 +1000 Subject: [PATCH 07/13] Add lint and lint-docker rules to Makefile Remove references to ./bin/golint, ./bin/gocycle and remove _support/ directory. Add formatting rule to .golangci.yml for goimports and local imports. --- .golangci.yml | 2 ++ Makefile.build.mk | 3 +++ Makefile.internal.mk | 14 +++++--------- Makefile.util.mk | 6 +++++- _support/validate-formatting.sh | 11 ----------- go.mod | 13 +++++-------- go.sum | 31 +++++++++++++++++++++++++++++++ 7 files changed, 51 insertions(+), 29 deletions(-) delete mode 100755 _support/validate-formatting.sh diff --git a/.golangci.yml b/.golangci.yml index 374475bc0..f2219e4c0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,6 +23,8 @@ linters-settings: goconst: min-len: 3 min-occurrences: 3 + goimports: + local-prefixes: gitlab.com/gitlab-org/gitlab-pages linters: disable-all: true diff --git a/Makefile.build.mk b/Makefile.build.mk index 9a40f68b3..b203cf4f7 100644 --- a/Makefile.build.mk +++ b/Makefile.build.mk @@ -1,3 +1,5 @@ +GOLANGCI_LINT_VERSION := v1.25.1 # version used by $GOLANGCI_LINT_IMAGE + .PHONY: all setup generate-mocks build clean all: gitlab-pages @@ -5,6 +7,7 @@ all: gitlab-pages setup: clean .GOPATH/.ok go get github.com/wadey/gocovmerge@v0.0.0-20160331181800-b5bfa59ec0ad go get github.com/golang/mock/mockgen@v1.3.1 + go get github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) generate-mocks: .GOPATH/.ok $Q bin/mockgen -source=internal/interface.go -destination=internal/mocks/mocks.go -package=mocks diff --git a/Makefile.internal.mk b/Makefile.internal.mk index e7d0e8fe9..a33634fd3 100644 --- a/Makefile.internal.mk +++ b/Makefile.internal.mk @@ -34,16 +34,12 @@ Q := $(if $V,,@) $Q ln -s ../bin .GOPATH/bin $Q touch $@ -.PHONY: bin/gocovmerge bin/goimports bin/gocyclo bin/golint +.PHONY: bin/gocovmerge bin/golangci-lint bin/gocovmerge: .GOPATH/.ok @test -x $@ || \ { echo "Vendored gocovmerge not found, try running 'make setup'..."; exit 1; } -bin/gocyclo: .GOPATH/.ok - @test -x $@ || \ - { echo "Vendored gocyclo not found, try running 'make setup'..."; exit 1; } -bin/goimports: .GOPATH/.ok - @test -x $@ || \ - { echo "Vendored goimports not found, try running 'make setup'..."; exit 1; } -bin/golint: .GOPATH/.ok + +bin/golangci-lint: .GOPATH/.ok @test -x $@ || \ - { echo "Vendored golint not found, try running 'make setup'..."; exit 1; } + { echo "Vendored golangci-lint not found, try running 'make setup'..."; exit 1; } + diff --git a/Makefile.util.mk b/Makefile.util.mk index 2d90172ab..c49b58bb6 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -1,8 +1,12 @@ +# Dockerfile https://gitlab.com/gitlab-org/gitlab-build-images/-/blob/master/Dockerfile.golangci-lint-alpine GOLANGCI_LINT_IMAGE := registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine .PHONY: lint test race acceptance bench cover list deps-check deps-download -lint: deps-download +lint: .GOPATH/.ok bin/golangci-lint + $Q ./bin/golangci-lint run $(if $V,-v) + +lint-docker: docker run -v $(PWD):/app -w /app $(GOLANGCI_LINT_IMAGE) \ sh -c "golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | \"\(.location.path):\(.location.lines.begin) \(.description)\"'" diff --git a/_support/validate-formatting.sh b/_support/validate-formatting.sh deleted file mode 100755 index 38f546617..000000000 --- a/_support/validate-formatting.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -set -eu - -IMPORT_RESULT=$(./bin/goimports -e -local "gitlab.com/gitlab-org/gitlab-pages" -l "$@") - -if [ -n "${IMPORT_RESULT}" ]; then - echo >&2 "Please run ./bin/goimports -w -local gitlab.com/gitlab-org/gitlab-pages -l $@" - echo "${IMPORT_RESULT}" - exit 1 -fi diff --git a/go.mod b/go.mod index bf1980f59..c18dc1aec 100644 --- a/go.mod +++ b/go.mod @@ -12,25 +12,22 @@ require ( github.com/gorilla/sessions v1.2.0 github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 github.com/karrick/godirwalk v1.10.12 + github.com/kr/text v0.2.0 // indirect github.com/namsral/flag v1.7.4-pre + github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/patrickmn/go-cache v2.1.0+incompatible github.com/prometheus/client_golang v1.1.0 github.com/rs/cors v1.7.0 github.com/sirupsen/logrus v1.4.2 - github.com/stretchr/testify v1.4.0 + github.com/stretchr/objx v0.2.0 // indirect + github.com/stretchr/testify v1.5.1 github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891 gitlab.com/lupine/go-mimedb v0.0.0-20180307000149-e8af1d659877 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f - golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa + golang.org/x/net v0.0.0-20200226121028-0de0cce0169b golang.org/x/sys v0.0.0-20200113162924-86b910548bc1 - golang.org/x/tools v0.0.0-20200117161641-43d50277825c - google.golang.org/api v0.15.0 // indirect - google.golang.org/appengine v1.6.5 // indirect - google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba // indirect - google.golang.org/grpc v1.24.0 // indirect - gopkg.in/DataDog/dd-trace-go.v1 v1.7.0 // indirect gopkg.in/yaml.v2 v2.2.8 ) diff --git a/go.sum b/go.sum index 89b924aa4..a27839506 100644 --- a/go.sum +++ b/go.sum @@ -49,6 +49,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -62,6 +63,7 @@ github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHj github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA= +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835 h1:roDmqJ4Qes7hrDOsWsMCce0vQHz3xiMPjJ9m4c2eeNs= github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835/go.mod h1:BjL/N0+C+j9uNX+1xcNuM9vdSIcXCZrQZUYbXOFbgN8= @@ -134,10 +136,12 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmg github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI= github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0= @@ -162,6 +166,7 @@ github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4 github.com/kataras/iris/v12 v12.0.1/go.mod h1:udK4vLQKkdDqMGJJVd/msuMtN6hpYJhg/lSzuxjhO+U= github.com/kataras/neffos v0.0.10/go.mod h1:ZYmJC07hQPW67eKuzlfY7SO3bC0mw83A3j6im82hfqw= github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d/go.mod h1:NV88laa9UiiDuX9AhMbDPkGYSPugBOV6yTZB1l2K9Z0= +github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= @@ -175,6 +180,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g= github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= github.com/lightstep/lightstep-tracer-go v0.15.6/go.mod h1:6AMpwZpsyCFwSovxzM78e+AsYxE8sGwiM6C3TytaWeI= @@ -182,6 +189,7 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= @@ -189,7 +197,9 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5 github.com/mediocregopher/mediocre-go-lib v0.0.0-20181029021733-cb65787f37ed/go.mod h1:dSsfyI2zABAdhcbvkXqgxOxrCsbYeHCPgrZkku60dSg= github.com/mediocregopher/radix/v3 v3.3.0/go.mod h1:EmfVyvspXz1uZEyPBMyGK+kjWiKQGvsUt6O3Pj+LDCQ= github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -202,12 +212,15 @@ github.com/namsral/flag v1.7.4-pre/go.mod h1:OXldTctbM6SWH1K899kPZcf65KxJiD7Msce github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM= github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= @@ -253,20 +266,28 @@ github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce h1:fb190+cK2Xz/dvi9Hv8eCYJYvIGUTN2/KLq1pT6CjEc= github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4= @@ -292,6 +313,7 @@ github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmv github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891 h1:WiCGS5C0B0h+/dh5O7kUJoEZt34O/tbsis9QghNB3gE= gitlab.com/gitlab-org/labkit v0.0.0-20200520155818-96e583c57891/go.mod h1:SNfxkfUwVNECgtmluVayv0GWFgEjjBs5AzgsowPQuo0= gitlab.com/lupine/go-mimedb v0.0.0-20180307000149-e8af1d659877 h1:k5N2m0IPaMuwWmFTO9fyTK4IEnSm35GC/p1S7VRgUyM= @@ -331,6 +353,8 @@ golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCc golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -352,6 +376,8 @@ golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -412,10 +438,13 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200117161641-43d50277825c h1:2EA2K0k9bcvvEDlqD8xdlOhCOqq+O/p9Voqi4x9W1YU= golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e h1:3Dzrrxi54Io7Aoyb0PYLsI47K2TxkRQg+cqUn+m04do= +golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= @@ -457,6 +486,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= -- GitLab From 08d8a8c4b27ec66485dbc4cbcb0d9088ba52720b Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Wed, 27 May 2020 15:34:12 +1000 Subject: [PATCH 08/13] Revert goconst changes in auth_test.go --- .golangci.yml | 1 + internal/auth/auth_test.go | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f2219e4c0..2df443248 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -57,6 +57,7 @@ issues: linters: - bodyclose - gosec + - goconst - path: "internal/fixture/fixtures.go" linters: - gosec diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 87cc988dc..4a5d63fa9 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -16,11 +16,6 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/source" ) -const ( - testAccessToken = "abc" - apiPagesAccess = "/api/v4/projects/1000/pages_access" -) - func createAuth(t *testing.T) *Auth { return New("pages.gitlab-example.com", "something-very-secret", @@ -103,7 +98,7 @@ func testTryAuthenticateWithCodeAndState(t *testing.T, https bool) { require.Equal(t, "POST", r.Method) w.WriteHeader(http.StatusOK) fmt.Fprint(w, "{\"access_token\":\"abc\"}") - case apiPagesAccess: + case "/api/v4/projects/1000/pages_access": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusOK) default: @@ -155,7 +150,7 @@ func TestTryAuthenticateWithCodeAndStateOverHTTPS(t *testing.T) { func TestCheckAuthenticationWhenAccess(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case apiPagesAccess: + case "/api/v4/projects/1000/pages_access": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusOK) default: @@ -183,7 +178,7 @@ func TestCheckAuthenticationWhenAccess(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, false, auth.CheckAuthentication(result, r, 1000)) @@ -193,7 +188,7 @@ func TestCheckAuthenticationWhenAccess(t *testing.T) { func TestCheckAuthenticationWhenNoAccess(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case apiPagesAccess: + case "/api/v4/projects/1000/pages_access": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusUnauthorized) default: @@ -221,7 +216,7 @@ func TestCheckAuthenticationWhenNoAccess(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, true, auth.CheckAuthentication(result, r, 1000)) @@ -231,7 +226,7 @@ func TestCheckAuthenticationWhenNoAccess(t *testing.T) { func TestCheckAuthenticationWhenInvalidToken(t *testing.T) { apiServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { - case apiPagesAccess: + case "/api/v4/projects/1000/pages_access": require.Equal(t, "Bearer abc", r.Header.Get("Authorization")) w.WriteHeader(http.StatusUnauthorized) fmt.Fprint(w, "{\"error\":\"invalid_token\"}") @@ -259,7 +254,7 @@ func TestCheckAuthenticationWhenInvalidToken(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, true, auth.CheckAuthentication(result, r, 1000)) @@ -297,7 +292,7 @@ func TestCheckAuthenticationWithoutProject(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, false, auth.CheckAuthenticationWithoutProject(result, r)) @@ -334,7 +329,7 @@ func TestCheckAuthenticationWithoutProjectWhenInvalidToken(t *testing.T) { require.NoError(t, err) r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) require.Equal(t, true, auth.CheckAuthenticationWithoutProject(result, r)) @@ -363,11 +358,11 @@ func TestGetTokenIfExistsWhenTokenExists(t *testing.T) { r := &http.Request{URL: reqURL} session, _ := store.Get(r, "gitlab-pages") - session.Values["access_token"] = testAccessToken + session.Values["access_token"] = "abc" session.Save(r, result) token, err := auth.GetTokenIfExists(result, r) - require.Equal(t, testAccessToken, token) + require.Equal(t, "abc", token) } func TestGetTokenIfExistsWhenTokenDoesNotExist(t *testing.T) { -- GitLab From fcc4821ce03aa2f1c44c9a4b705f691e648de0d4 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 28 May 2020 09:57:33 +1000 Subject: [PATCH 09/13] Use custom code_quality job inspired by the runner --- .gitlab-ci.yml | 19 +++++++++++-------- Makefile.build.mk | 2 +- Makefile.util.mk | 11 +++++++---- go.mod | 3 +++ go.sum | 7 +++++-- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bb87d51fa..2b2bbf0ff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -99,20 +99,23 @@ cover: paths: - coverage.html -lint: - extends: .go-mod-cache +code_quality: stage: test needs: ['download deps'] - image: registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine + extends: .go-mod-cache + image: golangci/golangci-lint:v1.27.0 + variables: + REPORT_FILE: gl-code-quality-report.json + LINT_FLAGS: "--issues-exit-code 0 --color never --deadline 15m" + OUT_FORMAT: code-climate script: - # Write the code coverage report to gl-code-quality-report.json - # and print linting issues to stdout in the format: path/to/file:line description - - golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | "\(.location.path):\(.location.lines.begin) \(.description)"' + - make lint | tee ${REPORT_FILE} + timeout: 15 minutes artifacts: reports: - codequality: gl-code-quality-report.json + codequality: ${REPORT_FILE} paths: - - gl-code-quality-report.json + - ${REPORT_FILE} test:1.12: extends: .tests diff --git a/Makefile.build.mk b/Makefile.build.mk index b203cf4f7..9cfcf69be 100644 --- a/Makefile.build.mk +++ b/Makefile.build.mk @@ -1,4 +1,4 @@ -GOLANGCI_LINT_VERSION := v1.25.1 # version used by $GOLANGCI_LINT_IMAGE +GOLANGCI_LINT_VERSION := v1.27.0 # version used by $GOLANGCI_LINT_IMAGE .PHONY: all setup generate-mocks build clean diff --git a/Makefile.util.mk b/Makefile.util.mk index c49b58bb6..3f483647b 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -1,14 +1,17 @@ # Dockerfile https://gitlab.com/gitlab-org/gitlab-build-images/-/blob/master/Dockerfile.golangci-lint-alpine -GOLANGCI_LINT_IMAGE := registry.gitlab.com/gitlab-org/gitlab-build-images:golangci-lint-alpine +GOLANGCI_LINT_IMAGE := golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) -.PHONY: lint test race acceptance bench cover list deps-check deps-download +.PHONY: lint lint-docker test race acceptance bench cover list deps-check deps-download + +OUT_FORMAT ?= colored-line-number +LINT_FLAGS ?= $(if $V,-v) lint: .GOPATH/.ok bin/golangci-lint - $Q ./bin/golangci-lint run $(if $V,-v) + $Q ./bin/golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS) lint-docker: docker run -v $(PWD):/app -w /app $(GOLANGCI_LINT_IMAGE) \ - sh -c "golangci-lint run --out-format code-climate | tee gl-code-quality-report.json | jq -r '.[] | \"\(.location.path):\(.location.lines.begin) \(.description)\"'" + sh -c "golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS)" test: .GOPATH/.ok gitlab-pages go test $(if $V,-v) $(allpackages) diff --git a/go.mod b/go.mod index c18dc1aec..84a99d328 100644 --- a/go.mod +++ b/go.mod @@ -29,5 +29,8 @@ require ( golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f golang.org/x/net v0.0.0-20200226121028-0de0cce0169b golang.org/x/sys v0.0.0-20200113162924-86b910548bc1 + golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770 + gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/yaml.v2 v2.2.8 + honnef.co/go/tools v0.0.1-2020.1.3 // indirect ) diff --git a/go.sum b/go.sum index a27839506..830b16033 100644 --- a/go.sum +++ b/go.sum @@ -440,11 +440,12 @@ golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200117161641-43d50277825c h1:2EA2K0k9bcvvEDlqD8xdlOhCOqq+O/p9Voqi4x9W1YU= golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e h1:3Dzrrxi54Io7Aoyb0PYLsI47K2TxkRQg+cqUn+m04do= -golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770 h1:M9Fif0OxNji8w+HvmhVQ8KJtiZOsjU9RgslJGhn95XE= +golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= @@ -506,4 +507,6 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -- GitLab From f98b87053275008e9921099872af9c1bcd16e219 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 28 May 2020 10:15:44 +1000 Subject: [PATCH 10/13] Remove make step in CI config --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b2bbf0ff..e202da1ff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -109,7 +109,7 @@ code_quality: LINT_FLAGS: "--issues-exit-code 0 --color never --deadline 15m" OUT_FORMAT: code-climate script: - - make lint | tee ${REPORT_FILE} + - golangci-lint run ./... --out-format ${OUT_FORMAT} ${LINT_FLAGS} | tee ${REPORT_FILE} timeout: 15 minutes artifacts: reports: -- GitLab From d92f6f44ac5910215a5286839c534760df8d071b Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 28 May 2020 10:47:15 +1000 Subject: [PATCH 11/13] Add REPORT_FILE to makefile --- Makefile.util.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.util.mk b/Makefile.util.mk index 3f483647b..93689d5f2 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -1,17 +1,17 @@ -# Dockerfile https://gitlab.com/gitlab-org/gitlab-build-images/-/blob/master/Dockerfile.golangci-lint-alpine GOLANGCI_LINT_IMAGE := golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) .PHONY: lint lint-docker test race acceptance bench cover list deps-check deps-download OUT_FORMAT ?= colored-line-number LINT_FLAGS ?= $(if $V,-v) +REPORT_FILE ?= lint: .GOPATH/.ok bin/golangci-lint - $Q ./bin/golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS) + $Q ./bin/golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS) | tee ${REPORT_FILE} lint-docker: docker run -v $(PWD):/app -w /app $(GOLANGCI_LINT_IMAGE) \ - sh -c "golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS)" + sh -c "golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS) | tee ${REPORT_FILE}" test: .GOPATH/.ok gitlab-pages go test $(if $V,-v) $(allpackages) -- GitLab From f52ca2dc5a8483c25c02378846567a0d8e4a47a7 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Thu, 28 May 2020 10:49:09 +1000 Subject: [PATCH 12/13] Remove issue-exit-code in CI --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e202da1ff..82878f16b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -106,7 +106,7 @@ code_quality: image: golangci/golangci-lint:v1.27.0 variables: REPORT_FILE: gl-code-quality-report.json - LINT_FLAGS: "--issues-exit-code 0 --color never --deadline 15m" + LINT_FLAGS: "--color never --deadline 15m" OUT_FORMAT: code-climate script: - golangci-lint run ./... --out-format ${OUT_FORMAT} ${LINT_FLAGS} | tee ${REPORT_FILE} -- GitLab From 60beff0794ee0865ce36ebfd4b5864c737c797d6 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Fri, 29 May 2020 12:01:58 +1000 Subject: [PATCH 13/13] Remove lint-docker --- Makefile.util.mk | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile.util.mk b/Makefile.util.mk index 93689d5f2..ea465fbf2 100644 --- a/Makefile.util.mk +++ b/Makefile.util.mk @@ -1,6 +1,6 @@ GOLANGCI_LINT_IMAGE := golangci/golangci-lint:$(GOLANGCI_LINT_VERSION) -.PHONY: lint lint-docker test race acceptance bench cover list deps-check deps-download +.PHONY: lint test race acceptance bench cover list deps-check deps-download OUT_FORMAT ?= colored-line-number LINT_FLAGS ?= $(if $V,-v) @@ -9,10 +9,6 @@ REPORT_FILE ?= lint: .GOPATH/.ok bin/golangci-lint $Q ./bin/golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS) | tee ${REPORT_FILE} -lint-docker: - docker run -v $(PWD):/app -w /app $(GOLANGCI_LINT_IMAGE) \ - sh -c "golangci-lint run ./... --out-format $(OUT_FORMAT) $(LINT_FLAGS) | tee ${REPORT_FILE}" - test: .GOPATH/.ok gitlab-pages go test $(if $V,-v) $(allpackages) -- GitLab