Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Commit 8e8510a

Browse files
author
Bruno Oliveira da Silva
committed
Run golangci-lint as part of pull request workflow #604
- Merge build and linter jobs in a single file - Runs tests for go 1.13 and 1.14 - Introduces code coverage with coveralls - Fixes some issues reported by golangci-lint and relax/disable some rules until the codebase is refactored Resolves #604
1 parent c500821 commit 8e8510a

File tree

7 files changed

+74
-12
lines changed

7 files changed

+74
-12
lines changed

.github/workflows/build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Build & Lint
2+
3+
# Only trigger the event on pull-requests
4+
on: [pull_request]
5+
6+
jobs:
7+
build:
8+
name: Build
9+
runs-on: ubuntu-latest
10+
# Test the latest release of Go
11+
strategy:
12+
matrix:
13+
go: [ '1.14', '1.13' ]
14+
steps:
15+
# Setup the workflow to use the specific version of Go
16+
- name: Set up Go 1.x
17+
uses: actions/setup-go@v2
18+
with:
19+
go-version: ${{ matrix.go }}
20+
id: go
21+
# Checkout the repository
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
# Verify downloaded dependencies
25+
- name: Verify dependencies
26+
run: go mod verify
27+
# Run tests and generates a coverage profile
28+
- name: Test
29+
run: |
30+
go test -v -coverprofile=profile.cov ./...
31+
# Run Go benchmarks
32+
- name: Benchmark
33+
run: |
34+
go test -bench=. -benchmem
35+
# Sends code coverage report to Coveralls
36+
- name: Coveralls
37+
env:
38+
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
run: |
40+
GO111MODULE=off go get github.com/mattn/goveralls
41+
$(go env GOPATH)/bin/goveralls -coverprofile=profile.cov -service=github
42+
# Run the linter as a separate job
43+
golangci:
44+
name: Lint
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v2
49+
- name: golangci-lint
50+
uses: golangci/[email protected]
51+
with:
52+
version: v1.26
53+
github-token: "${{ secrets.GITHUB_TOKEN }}"

.golangci.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ linters-settings:
44
golint:
55
min-confidence: 0
66
gocyclo:
7-
min-complexity: 60
7+
min-complexity: 64
88
maligned:
99
suggest-new: true
1010
dupl:
1111
threshold: 100
1212
goconst:
1313
min-len: 2
1414
min-occurrences: 2
15-
15+
# TODO: Revisit after the refactor
16+
funlen:
17+
lines: 220
18+
statements: 110
19+
1620
linters:
1721
enable-all: true
1822
disable:
@@ -21,3 +25,13 @@ linters:
2125
- lll
2226
- gochecknoinits
2327
- gochecknoglobals
28+
- dupl
29+
- wsl
30+
- godox
31+
- gomnd
32+
# TODO: Revisit after the refactor
33+
- gocognit
34+
- testpackage
35+
- goerr113
36+
- godot
37+
- nestif

forwarding.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
140140
zap.String("subject", state.identity.ID),
141141
zap.String("email", state.identity.Email),
142142
zap.String("expires", state.expiration.Format(time.RFC3339)))
143-
144143
} else {
145144
r.log.Info("access token is about to expiry",
146145
zap.String("subject", state.identity.ID),
@@ -182,7 +181,6 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
182181
zap.String("subject", state.identity.ID),
183182
zap.String("email", state.identity.Email),
184183
zap.String("expires", state.expiration.Format(time.RFC3339)))
185-
186184
} else {
187185
r.log.Info("session does not support refresh token, acquiring new token",
188186
zap.String("subject", state.identity.ID),

self_signed.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"crypto/rand"
2222
"crypto/rsa"
2323
"crypto/tls"
24-
"errors"
24+
"fmt"
2525
"sync"
2626
"time"
2727

@@ -47,10 +47,10 @@ type selfSignedCertificate struct {
4747
// newSelfSignedCertificate creates and returns a self signed certificate manager
4848
func newSelfSignedCertificate(hostnames []string, expiry time.Duration, log *zap.Logger) (*selfSignedCertificate, error) {
4949
if len(hostnames) == 0 {
50-
return nil, errors.New("no hostnames specified")
50+
return nil, fmt.Errorf("no hostnames specified")
5151
}
5252
if expiry < 5*time.Minute {
53-
return nil, errors.New("expiration must be greater then 5 minutes")
53+
return nil, fmt.Errorf("expiration must be greater then 5 minutes")
5454
}
5555

5656
// @step: generate a certificate pair

server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ func (r *oauthProxy) createHTTPListener(config listenerConfig) (net.Listener, er
512512
return nil, err
513513
}
514514
getCertificate = rotate.GetCertificate
515-
516515
}
517516

518517
if config.useFileTLS {

utils.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package main
1818
import (
1919
"crypto/aes"
2020
"crypto/cipher"
21-
"crypto/rand"
2221
cryptorand "crypto/rand"
2322
"crypto/rsa"
2423
sha "crypto/sha256"
@@ -70,7 +69,7 @@ var (
7069
// createCertificate is responsible for creating a certificate
7170
func createCertificate(key *rsa.PrivateKey, hostnames []string, expire time.Duration) (tls.Certificate, error) {
7271
// @step: create a serial for the certificate
73-
serial, err := cryptorand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))
72+
serial, err := cryptorand.Int(cryptorand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))
7473
if err != nil {
7574
return tls.Certificate{}, err
7675
}

utils_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ func TestDecryptDataBlock(t *testing.T) {
276276
t.Errorf("test case: %d are not the same", i)
277277
}
278278
}
279-
280279
}
281280

282281
func TestHasAccessOK(t *testing.T) {
@@ -586,7 +585,7 @@ func writeFakeConfigFile(t *testing.T, content string) *os.File {
586585
}
587586
f.Close()
588587

589-
if err := ioutil.WriteFile(f.Name(), []byte(content), 0700); err != nil {
588+
if err := ioutil.WriteFile(f.Name(), []byte(content), 0600); err != nil {
590589
t.Fatalf("unexpected error writing node label file: %v", err)
591590
}
592591

0 commit comments

Comments
 (0)