Skip to content
Open
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
167 changes: 129 additions & 38 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,154 @@
version: '2'

run:
modules-download-mode: readonly
relative-path-mode: wd
formatters:
enable:
- gci
- gofumpt
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
settings:
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- localmodule
custom-order: true

output:
formats:
tab:
path: stdout
colors: false
issues:
max-issues-per-linter: 0
max-same-issues: 0

linters:
default: none

enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- canonicalheader
- containedctx
- contextcheck
- copyloopvar
- decorder
- dogsled
- dupword
- durationcheck
- errcheck
- errchkjson
- forbidigo
- funcorder
- funlen
- gocheckcompilerdirectives
- gocognit
- goconst
- gocritic
- gocyclo
- godox
- gosec
- govet
- ineffassign
- iotamixing
- misspell
- mnd
- nakedret
- modernize
- nilerr
- nilnil
- noctx
- nolintlint
- nosprintfhostport
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- testifylint
- thelper
- tparallel
- unconvert
- unused
- usestdlibvars
- usetesting
- wastedassign
- wrapcheck

exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
rules:
- path: (.+)_test\.go
linters:
- revive
text: "^(unused-parameter|add-constant):"

settings:
decorder:
dec-order:
- const
- type
- var
- func
disable-dec-order-check: false
disable-type-dec-num-check: false

forbidigo:
forbid:
- pattern: "^(fmt\\.Print(|f|ln)|print|println)$"
- pattern: "^(errors\\.Wrap)$"
msg: errors.Wrap is no longer needed, use fmt.Errorf

funcorder:
alphabetical: true

funlen:
lines: 100
statements: 60

gocyclo:
min-complexity: 15

mnd:
ignored-functions:
- strconv.(?:Format|Parse)\B+
gosec:
excludes:
# G7xx-group causes LOTS of false-positives
- G701 # SQL injection via taint analysis
- G702 # Command injection via taint analysis
- G703 # Path traversal via taint analysis
- G704 # SSRF via taint analysis
- G705 # XSS via taint analysis
- G706 # Log injection via taint analysis
- G707 # SMTP command/header injection via taint analysis

nolintlint:
require-explanation: true
require-specific: true

revive:
directives:
- name: specify-disable-reason
severity: error
rules:
- name: add-constant
arguments:
- max-lit-count: "3"
allow-strs: '""'
allow-ints: "0,1,2"
allow-floats: "0.0,0.,1.0,1.,2.0,2."
ignore-funcs: 'strconv\.(Format|Parse).*,make'
- name: atomic
- name: banned-characters
arguments:
- ;
- "\u037E" # Greek question mark (looks like ;)
- name: bare-return
- name: blank-imports
- name: bool-literal-in-expr
- name: call-to-gc
- name: comment-spacings
arguments:
- "#nosec:G"
- name: confusing-naming
- name: confusing-results
- name: constant-logical-expr
Expand All @@ -81,31 +161,51 @@ linters:
- name: early-return
- name: empty-block
- name: empty-lines
- name: errorf
- name: enforce-map-style
arguments:
- "make"
- name: enforce-slice-style
arguments:
- "nil"
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
arguments:
- sayRepetitiveInsteadOfStutters
- "check-public-interface"
- "say-repetitive-instead-of-stutters"
- name: flag-parameter
- name: forbidden-call-in-wg-go
- name: get-return
- name: identical-branches
- name: identical-ifelseif-branches
- name: identical-ifelseif-conditions
- name: identical-switch-branches
- name: identical-switch-conditions
- name: if-return
- name: import-alias-naming
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: inefficient-map-lookup
- name: modifies-parameter
- name: modifies-value-receiver
- name: optimize-operands-order
- name: package-comments
- name: package-directory-mismatch
- name: range
- name: range-val-address
- name: range-val-in-closure
- name: receiver-naming
- name: redefines-builtin-id
- name: redundant-build-tag
- name: redundant-import-alias
- name: redundant-test-main-exit
- name: string-of-int
- name: struct-tag
- name: superfluous-else
- name: time-date
- name: time-equal
- name: time-naming
- name: unconditional-recursion
Expand All @@ -114,34 +214,25 @@ linters:
- name: unhandled-error
arguments:
- fmt.(Fp|P)rint(f|ln|)
- name: unnecessary-if
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: unused-receiver
- name: use-fmt-print
- name: useless-break
- name: useless-fallthrough
- name: var-declaration
- name: var-naming
- name: waitgroup-by-value
severity: error

exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

issues:
max-issues-per-linter: 0
max-same-issues: 0
output:
formats:
tab:
path: stdout
colors: false

formatters:
enable:
- gofmt
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
run:
modules-download-mode: readonly
relative-path-mode: wd
34 changes: 18 additions & 16 deletions api.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// The OTS Server
package main

import (
Expand All @@ -8,11 +9,12 @@ import (
"strings"
"time"

"github.com/Luzifer/ots/pkg/metrics"
"github.com/Luzifer/ots/pkg/storage"
"github.com/gofrs/uuid"
"github.com/gorilla/mux"
"github.com/sirupsen/logrus"

"github.com/Luzifer/ots/pkg/metrics"
"github.com/Luzifer/ots/pkg/storage"
)

const (
Expand Down Expand Up @@ -58,12 +60,25 @@ func (a apiServer) Register(r *mux.Router) {
r.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })
}

func (a apiServer) errorResponse(res http.ResponseWriter, status int, err error, desc string) {
errID := uuid.Must(uuid.NewV4()).String()

if desc != "" {
// No description: Nothing interesting for the server log
logrus.WithField("err_id", errID).WithError(err).Error(desc)
}

a.jsonResponse(res, status, apiResponse{
Error: errID,
})
}

func (a apiServer) handleCreate(res http.ResponseWriter, r *http.Request) {
if cust.MaxSecretSize > 0 {
// As a safeguard against HUGE payloads behind a misconfigured
// proxy we take double the maximum secret size after which we
// just close the read and cut the connection to the sender.
r.Body = http.MaxBytesReader(res, r.Body, cust.MaxSecretSize*2) //nolint:mnd
r.Body = http.MaxBytesReader(res, r.Body, cust.MaxSecretSize*2)
}

var (
Expand Down Expand Up @@ -166,19 +181,6 @@ func (a apiServer) handleSettings(w http.ResponseWriter, _ *http.Request) {
a.jsonResponse(w, http.StatusOK, cust)
}

func (a apiServer) errorResponse(res http.ResponseWriter, status int, err error, desc string) {
errID := uuid.Must(uuid.NewV4()).String()

if desc != "" {
// No description: Nothing interesting for the server log
logrus.WithField("err_id", errID).WithError(err).Error(desc)
}

a.jsonResponse(res, status, apiResponse{
Error: errID,
})
}

func (apiServer) jsonResponse(res http.ResponseWriter, status int, response any) {
res.Header().Set("Content-Type", "application/json")
res.Header().Set("Cache-Control", "no-store, max-age=0")
Expand Down
5 changes: 3 additions & 2 deletions api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/Luzifer/ots/pkg/customization"
"github.com/Luzifer/ots/pkg/metrics"
"github.com/Luzifer/ots/pkg/storage"
"github.com/Luzifer/ots/pkg/storage/memory"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var testCollector = metrics.New()
Expand Down
3 changes: 2 additions & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"net"
"net/http"

"github.com/sirupsen/logrus"

"github.com/Luzifer/ots/pkg/metrics"
"github.com/Luzifer/ots/pkg/storage"
"github.com/sirupsen/logrus"
)

func requestInSubnetList(r *http.Request, subnets []string) bool {
Expand Down
7 changes: 6 additions & 1 deletion i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ translations:
tooltip-download-as-file: Télécharger en tant que fichier
it:
deeplLanguage: it
translators: []
translators:
- wd006
translations:
alert-secret-not-found: Questo non è il secret che stai cercando… - Se ti aspettavi di vedere il secret allora potrebbe essere stato compromesso poichè qualcun altro potrebbe aver già aperto il link.
alert-something-went-wrong: Qualcosa non ha funzionato. Mi dispiace davvero…
Expand Down Expand Up @@ -350,6 +351,10 @@ translations:
title-secret-created: Secret creato!
tooltip-copy-to-clipboard: Copia nella clipboard
tooltip-download-as-file: Scarica come file
alert-insecure-environment: Stai accedendo a questa istanza tramite una connessione non sicura. Non potrai creare o leggere segreti.
btn-theme-switcher-auto: Auto
text-secret-burned: Il segreto è stato svelato con successo.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I translated that back correctly, svelato is "revealed", right? This should be "destroyed".

tooltip-burn-secret: Brucia il segreto ora!
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new translations use segreto instead of secret used by the existing ones. This feels like a break in translations. It would be better to stick to one style, wouldn't it?

lv:
deeplLanguage: lv
translators: []
Expand Down
Loading