Skip to content
Snippets Groups Projects
Commit 8031967e authored by Lyuben Penkovski's avatar Lyuben Penkovski
Browse files

Merge branch 'fix-linter-errors' into 'main'

Fix linter errors and warnings

See merge request gaia-x/data-infrastructure-federation-services/tsa/golib!3
parents cc9c0e96 b826f65e
No related branches found
Tags v1.1.1
1 merge request!3Fix linter errors and warnings
Pipeline #21388 passed with stage
in 1 minute and 4 seconds
......@@ -6,7 +6,7 @@ before_script:
- cd /go/src/gitlab.com/${CI_PROJECT_PATH}
unit tests:
image: golang:1.17.8
image: golang:1.19.2
stage: test
tags:
- amd64-docker
......@@ -14,15 +14,25 @@ unit tests:
- go version
- go test -race -coverprofile=coverage.out ./...
- go tool cover -func=coverage.out
coverage: '/total:\s+\(statements\)\s+(\d+.\d+\%)/'
lint:
image: golangci/golangci-lint:v1.45.0
image: golangci/golangci-lint:v1.50.0
stage: test
tags:
- amd64-docker
script:
- go version
- golangci-lint --version
- golangci-lint run
before_script:
- ln -s /builds /go/src/gitlab.com
- cd /go/src/gitlab.com/${CI_PROJECT_PATH}
govulncheck:
image: golang:1.19.2
stage: test
tags:
- amd64-docker
script:
- go version
- go install golang.org/x/vuln/cmd/govulncheck@latest
- govulncheck ./...
......@@ -12,7 +12,6 @@ linters:
enable:
- megacheck
- govet
- deadcode
- errcheck
- goconst
- gocyclo
......@@ -22,10 +21,9 @@ linters:
- ineffassign
- nakedret
- staticcheck
- structcheck
- unconvert
- varcheck
- vet
- vetshadow
- misspell
- staticcheck
- unused
......@@ -11,7 +11,7 @@ import (
"github.com/lestrrat-go/jwx/v2/jwt"
)
// AuthMiddleware is standard HTTP middleware used for authenticating
// Middleware is standard HTTP middleware used for authenticating
// requests carrying a bearer JWT token.
//
// It uses an internal caching mechanism for fetching Json Web Keys from
......@@ -19,11 +19,11 @@ import (
//
// JWT tokens are expected to carry a Header *kid* claim specifying the
// ID of the public key which should be used for verification.
type AuthMiddleware struct {
type Middleware struct {
jwkSet jwk.Set
}
func NewMiddleware(jwkURL string, refreshInterval time.Duration, c *http.Client) (*AuthMiddleware, error) {
func NewMiddleware(jwkURL string, refreshInterval time.Duration, c *http.Client) (*Middleware, error) {
if jwkURL == "" {
return nil, fmt.Errorf("missing JWK url")
}
......@@ -37,12 +37,12 @@ func NewMiddleware(jwkURL string, refreshInterval time.Duration, c *http.Client)
return nil, fmt.Errorf("fail to refresh JWK cache: %v", err)
}
return &AuthMiddleware{
return &Middleware{
jwkSet: jwk.NewCachedSet(cache, jwkURL),
}, nil
}
func (a *AuthMiddleware) Handler() func(http.Handler) http.Handler {
func (a *Middleware) Handler() func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token, err := tokenFromRequest(r)
......
......@@ -128,7 +128,7 @@ func TestAuthMiddleware_Handler(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, "https://example.com", nil)
assert.NoError(t, err)
token := "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImtleTEifQ.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTY2NDk2MDg2OCwiZXhwIjoxNjY0OTY0NDY4fQ.FrIA3A228den86qX72o4yP3TiEA9uOf46Yav_vY5daCQ8yeAm3GaBzC_nikt0y9NSCR6K2G2GCm7RcdfP3vQ9CFh2R7FtL4nfjffdauLmXVzp3z_lyBIKYL3RsTGChctfMeYZzk2F6EDmGHeI8xV3KiDC5Gfkvfdp9MfFxVy7DcuEV9MLo_9j4Y-7nfuB1CbdF_1vzSsO0twitePjsB59CNndugJgTUGFjKUJU2_e7vKMR_i9NvFHfJZS2VbtX3vrZ5f_pfOvBSSZJBxG50Uwf6COhtABieVHhhmLBSJq1P1EWRAI26Bk-YtE8k-jfjra9W1RF5DLF7Jh9Lw-utc5A"
token := "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImtleTEifQ.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTY2NDk2MDg2OCwiZXhwIjoxNjY0OTY0NDY4fQ.FrIA3A228den86qX72o4yP3TiEA9uOf46Yav_vY5daCQ8yeAm3GaBzC_nikt0y9NSCR6K2G2GCm7RcdfP3vQ9CFh2R7FtL4nfjffdauLmXVzp3z_lyBIKYL3RsTGChctfMeYZzk2F6EDmGHeI8xV3KiDC5Gfkvfdp9MfFxVy7DcuEV9MLo_9j4Y-7nfuB1CbdF_1vzSsO0twitePjsB59CNndugJgTUGFjKUJU2_e7vKMR_i9NvFHfJZS2VbtX3vrZ5f_pfOvBSSZJBxG50Uwf6COhtABieVHhhmLBSJq1P1EWRAI26Bk-YtE8k-jfjra9W1RF5DLF7Jh9Lw-utc5A" //nolint:gosec
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
response := httptest.NewRecorder()
......@@ -153,7 +153,7 @@ func TestAuthMiddleware_Handler(t *testing.T) {
token, err := createSignedToken()
assert.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("%s", token))
req.Header.Set("Authorization", token)
response := httptest.NewRecorder()
authHandler.ServeHTTP(response, req)
......@@ -171,7 +171,7 @@ func createSignedToken() (string, error) {
Audience([]string{"skynet"}).
Build()
if err != nil {
return "", fmt.Errorf("failed to build token: %s\n", err)
return "", fmt.Errorf("failed to build token: %s", err)
}
signed, err := jwt.Sign(token, jwt.WithKey(jwa.RS256, privateKey))
......
......@@ -73,16 +73,17 @@ func (k Kind) String() string {
// recorded.
//
// The supported types are:
// errors.Kind:
// The kind of the error.
// *errors.Error
// The underlying error that triggered this one. If the error has
// non-empty ID and Kind fields, they are promoted as values of the
// returned one.
// error:
// The underlying error that triggered this one.
// string:
// Treated as an error message and assigned to the Message field.
//
// errors.Kind:
// The kind of the error.
// *errors.Error
// The underlying error that triggered this one. If the error has
// non-empty ID and Kind fields, they are promoted as values of the
// returned one.
// error:
// The underlying error that triggered this one.
// string:
// Treated as an error message and assigned to the Message field.
func New(args ...interface{}) error {
if len(args) == 0 {
panic("call to errors.New without arguments")
......
......@@ -4,7 +4,6 @@ package goadec
import (
"fmt"
"io"
"io/ioutil"
"net/http"
goahttp "goa.design/goa/v3/http"
......@@ -25,7 +24,7 @@ func newBytesDecoder(r io.Reader) *bytesDecoder {
}
func (d *bytesDecoder) Decode(v interface{}) error {
b, err := ioutil.ReadAll(d.r)
b, err := io.ReadAll(d.r)
if err != nil {
return err
}
......
......@@ -5,6 +5,7 @@ import (
"errors"
"net/http"
"os"
"syscall"
"testing"
"time"
......@@ -65,7 +66,7 @@ func TestShutdownWithSignal(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
srv := &http.Server{
srv := &http.Server{ //nolint:gosec
Addr: test.addr,
Handler: &handler{requestTime: test.reqTime},
}
......@@ -89,7 +90,7 @@ func TestShutdownWithSignal(t *testing.T) {
proc, err := os.FindProcess(os.Getpid())
require.NoError(t, err)
require.NoError(t, proc.Signal(os.Interrupt))
require.NoError(t, proc.Signal(syscall.SIGTERM))
err = <-reqerr
......@@ -140,7 +141,7 @@ func TestShutdownWithContext(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
srv := &http.Server{
srv := &http.Server{ //nolint:gosec
Addr: test.addr,
Handler: &handler{requestTime: test.reqTime},
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment