Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: add golangci.yaml and fix errors #28

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2023 Adevinta

name: Golangci-lint
on: [push, pull_request]
permissions:
contents: read
jobs:
golangci-lint:
name: Lint
runs-on: ubuntu-latest
env:
GOLANGCI_LINT_VERSION: v1.54.2
GOLANGCI_LINT_OUT_FORMAT: ${{ github.event_name == 'pull_request' && 'github-actions' || 'colored-line-number' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Remove Go problem matchers
run: echo "::remove-matcher owner=go::"
- name: Install "golangci-lint"
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${{ env.GOLANGCI_LINT_VERSION }}
- name: Run "golangci-lint run"
run: golangci-lint run --out-format=${{ env.GOLANGCI_LINT_OUT_FORMAT }} ./...
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ vulcan-tracker

# Dependency directories (remove the comment below to include it)
# vendor/
.vscode/
out/


dist/
.env
.DS_Store
.history
.idea


jesusfcr marked this conversation as resolved.
Show resolved Hide resolved
# generated run toml config
run.toml
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
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
3 changes: 2 additions & 1 deletion 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 @@ -113,7 +114,7 @@ func (api *API) CreateTicket(c echo.Context) error {
ticket.TicketType = configuration.VulnerabilityIssueType

// Check if the ticket exists.
findingTicket, err := api.storage.GetFindingTicket(ticket.FindingID, ticket.TeamID)
findingTicket, _ := api.storage.GetFindingTicket(ticket.FindingID, ticket.TeamID)
if findingTicket.ID != "" {
return echo.NewHTTPError(http.StatusConflict, "The ticket for this finding and team already exists.")
}
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
5 changes: 3 additions & 2 deletions pkg/tracking/jira/client.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/*
Copyright 2022 Adevinta
*/

package jira

import (
"fmt"
"net/http"
"strings"

gojira "github.com/andygrunwald/go-jira"

vterrors "github.com/adevinta/vulcan-tracker/pkg/errors"
"github.com/adevinta/vulcan-tracker/pkg/model"

gojira "github.com/andygrunwald/go-jira"
)

// Issuer manages all the operations related with the ticket tracker issues.
Expand Down
Loading
Loading