Skip to content

Commit

Permalink
all: add golangci.yaml and fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
seilagamo committed Mar 5, 2024
1 parent df605c8 commit 53f0a53
Show file tree
Hide file tree
Showing 26 changed files with 298 additions and 141 deletions.
38 changes: 38 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
linters:
enable:
- gci
- godot
- gofmt
- goheader
- misspell
- revive
- whitespace
- unparam
linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/adevinta/vulcan-tracker)
custom-order: true
goheader:
values:
const:
COMPANY: Adevinta
regexp:
ANY-YEAR: \d{4}
template: |-
Copyright {{ ANY-YEAR }} {{ COMPANY }}
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-use-default: false
exclude-rules:
- linters:
- errcheck
text: 'Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked'
- linters:
- revive
text: 'unused-parameter: parameter ''.*'' seems to be unused'
run:
timeout: 5m
1 change: 1 addition & 0 deletions cmd/vulcan-tracker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright 2022 Adevinta
*/

// Package main start a vulcan-tracker server.
package main

import (
Expand Down
47 changes: 30 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
module github.com/adevinta/vulcan-tracker

go 1.20
go 1.21

require (
github.com/BurntSushi/toml v1.2.0
github.com/BurntSushi/toml v1.3.2
github.com/andygrunwald/go-jira v1.16.0
github.com/aws/aws-sdk-go v1.44.284
github.com/aws/aws-secretsmanager-caching-go v1.1.0
github.com/go-testfixtures/testfixtures/v3 v3.8.1
github.com/google/go-cmp v0.5.9
github.com/aws/aws-sdk-go v1.50.31
github.com/aws/aws-secretsmanager-caching-go v1.1.3
github.com/go-testfixtures/testfixtures/v3 v3.10.0
github.com/google/go-cmp v0.6.0
github.com/jmoiron/sqlx v1.3.5
github.com/labstack/echo/v4 v4.9.0
github.com/labstack/gommon v0.3.1
github.com/lib/pq v1.10.6
github.com/labstack/echo/v4 v4.11.4
github.com/labstack/gommon v0.4.2
github.com/lib/pq v1.10.9
)

require (
github.com/ClickHouse/ch-go v0.58.2 // indirect
github.com/ClickHouse/clickhouse-go/v2 v2.18.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/go-faster/city v1.0.1 // indirect
github.com/go-faster/errors v0.6.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/paulmach/orb v0.11.1 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/trivago/tgo v1.0.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
214 changes: 158 additions & 56 deletions go.sum

Large diffs are not rendered by default.

34 changes: 1 addition & 33 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
Copyright 2022 Adevinta
*/

// Package api contains the endpoints to manage finding tickets.
package api

import (
"errors"

"github.com/adevinta/vulcan-tracker/pkg/storage"
"github.com/adevinta/vulcan-tracker/pkg/tracking"
)
Expand All @@ -25,37 +24,6 @@ type Options struct {
DefaultSize int
}

// Pagination represents the pagination options for the API requests.
type Pagination struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
Total int `json:"total"`
More bool `json:"more"`
}

var (
// Regular expression matching date format 'yyyy-mm-dd'.
dateFmtRegEx = `^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$`

// ErrDateMalformed indicates that the date format does not comply with YYYY-MM-DD.
ErrDateMalformed = errors.New("malformed Date")

// ErrPageMalformed indicates that the page requested is not an integer larger than 0.
ErrPageMalformed = errors.New("malformed Page Number")

// ErrPageNotFound indicates that the page requested does not exist.
ErrPageNotFound = errors.New("page Not Found")

// ErrSizeMalformed indicates that the size requested is not an integer larger than 0.
ErrSizeMalformed = errors.New("malformed Size Number")

// ErrSizeTooLarge indicates that the size requested is larger than the maximum allowed.
ErrSizeTooLarge = errors.New("size Number Too Large")

// ErrInvalidFilter indicates that there is a conflict between specified params for the filter.
ErrInvalidFilter = errors.New("filter parameters combination is invalid")
)

// New instantiates a new API.
func New(ticketServer tracking.TicketServer, ticketTrackerBuilder tracking.TicketTrackerBuilder,
storage storage.Storage, options Options) *API {
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/tracking.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2023 Adevinta
*/

package api

import (
Expand Down Expand Up @@ -117,6 +118,9 @@ func (api *API) CreateTicket(c echo.Context) error {
if findingTicket.ID != "" {
return echo.NewHTTPError(http.StatusConflict, "The ticket for this finding and team already exists.")
}
if err != nil {
return responseError(err)
}

// Get a ticket tracker client.
ttClient, err := api.ticketTrackerBuilder.GenerateTicketTrackerClient(api.ticketServer, teamID, c.Logger())
Expand Down
6 changes: 4 additions & 2 deletions pkg/api/tracking_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2022 Adevinta
*/

package api

import (
Expand All @@ -12,12 +13,13 @@ import (
"net/http/httptest"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/labstack/echo/v4"

vterrors "github.com/adevinta/vulcan-tracker/pkg/errors"
"github.com/adevinta/vulcan-tracker/pkg/model"
"github.com/adevinta/vulcan-tracker/pkg/storage"
"github.com/adevinta/vulcan-tracker/pkg/tracking"
"github.com/google/go-cmp/cmp"
"github.com/labstack/echo/v4"
)

const (
Expand Down
8 changes: 5 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
Copyright 2022 Adevinta
*/

// Package config parses and validates the configuration
// needed to run vulcan-tracker.
package config

import (
"io"
"os"
"strconv"

"github.com/adevinta/vulcan-tracker/pkg/storage/postgresql"

"github.com/BurntSushi/toml"
"github.com/labstack/gommon/log"

"github.com/adevinta/vulcan-tracker/pkg/storage/postgresql"
)

// Config represents all the configuration needed to run the project.
Expand All @@ -33,7 +35,7 @@ type logConfig struct {
Level string `toml:"level"`
}

// AwsConfig stores the AWS configuration
// AwsConfig stores the AWS configuration.
type AwsConfig struct {
ServerCredentialsKey string `toml:"server_credentials_key"`
Region string `toml:"region"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
Copyright 2022 Adevinta
*/

// Package errors manage the errors for vulcan-tracker.
package errors

// TrackingError represents a custom error for this project.
Expand Down
1 change: 1 addition & 0 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright 2002 Adevinta
*/

// Package model represents the data model for vulcan-tracker.
package model

// Ticket represents a vulnerability in a ticket tracker.
Expand Down
7 changes: 4 additions & 3 deletions pkg/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
Copyright 2023 Adevinta
*/

// Package secrets manages the storage of credentials for ticket trackers.
package secrets

import (
"encoding/json"
"fmt"
"net/http"

"github.com/adevinta/vulcan-tracker/pkg/config"
vterrors "github.com/adevinta/vulcan-tracker/pkg/errors"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/aws/aws-secretsmanager-caching-go/secretcache"
"github.com/labstack/echo/v4"

"github.com/aws/aws-secretsmanager-caching-go/secretcache"
"github.com/adevinta/vulcan-tracker/pkg/config"
vterrors "github.com/adevinta/vulcan-tracker/pkg/errors"
)

// Secrets manage the credentials of ticket trackers servers.
Expand Down
5 changes: 3 additions & 2 deletions pkg/secrets/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (
"testing"
"time"

"github.com/adevinta/vulcan-tracker/pkg/config"
"github.com/adevinta/vulcan-tracker/pkg/testutil"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface"
"github.com/aws/aws-secretsmanager-caching-go/secretcache"
"github.com/google/go-cmp/cmp"
"github.com/labstack/echo/v4"

"github.com/adevinta/vulcan-tracker/pkg/config"
"github.com/adevinta/vulcan-tracker/pkg/testutil"
)

type smMock struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Copyright 2023 Adevinta
*/

// Package postgresql manage the storage in a PostgreSQL database.
package postgresql

import (
Expand Down Expand Up @@ -92,7 +93,7 @@ func (db *PostgresStore) Healthcheck() error {
return nil
}

// Close closes PostgresStore db connection
// Close closes PostgresStore db connection.
func (db *PostgresStore) Close() error {
return db.DB.Close()
}
7 changes: 6 additions & 1 deletion pkg/storage/postgresql/postgresql_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/*
Copyright 2023 Adevinta
*/

package postgresql

import (
"testing"

"github.com/adevinta/vulcan-tracker/pkg/testutil"
"github.com/google/go-cmp/cmp"

"github.com/adevinta/vulcan-tracker/pkg/testutil"
)

func errToStr(err error) string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/postgresql/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ Copyright 2023 Adevinta
package postgresql

import (
"github.com/adevinta/vulcan-tracker/pkg/model"
"github.com/lib/pq"

"github.com/adevinta/vulcan-tracker/pkg/model"
)

// FindingTicket represents
// FindingTicket represents a relation between tickets and findings.
type FindingTicket struct {
model.FindingTicket
CreatedAt pq.NullTime `db:"created_at"`
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/postgresql/tickets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"database/sql"
"testing"

"github.com/adevinta/vulcan-tracker/pkg/model"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/labstack/gommon/log"

"github.com/adevinta/vulcan-tracker/pkg/model"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/postgresql/ticketserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"database/sql"
"testing"

"github.com/adevinta/vulcan-tracker/pkg/model"
"github.com/google/go-cmp/cmp"
"github.com/labstack/gommon/log"

"github.com/adevinta/vulcan-tracker/pkg/model"
)

func TestFindServerConf(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
Copyright 2022 Adevinta
*/

// Package storage manage the data storage in a database.
package storage

import "github.com/adevinta/vulcan-tracker/pkg/model"
Expand Down
2 changes: 2 additions & 0 deletions pkg/testutil/testutils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*
Copyright 2022 Adevinta
*/

// Package testutil provide utils for testing.
package testutil

// ErrToStr returns a string even when it is nil.
Expand Down
Loading

0 comments on commit 53f0a53

Please sign in to comment.