Misc lint fixes

This commit is contained in:
David Stotijn 2022-02-28 16:21:01 +01:00
parent af26987601
commit 857aa0c49e
No known key found for this signature in database
GPG key ID: B23243A9C47CEE2D
12 changed files with 41 additions and 12 deletions

View file

@ -12,6 +12,7 @@ linters:
- test
- unused
disable:
- dupl
- exhaustive
- exhaustivestruct
- gochecknoglobals
@ -21,9 +22,11 @@ linters:
- gomnd
- interfacer
- maligned
- nilnil
- nlreturn
- scopelint
- testpackage
- varnamelen
- wrapcheck
linters-settings:
@ -31,6 +34,8 @@ linters-settings:
local-prefixes: github.com/dstotijn/hetty
godot:
capital: true
ireturn:
allow: "error,empty,anon,stdlib,.*(or|er)$,github.com/99designs/gqlgen/graphql.Marshaler,github.com/dstotijn/hetty/pkg/api.QueryResolver,github.com/dstotijn/hetty/pkg/search.Expression"
issues:
exclude-rules:

View file

@ -162,7 +162,8 @@ func NewCertUninstallCommand(rootConfig *Config) *ffcli.Command {
fs.StringVar(&cmd.cert, "cert", "~/.hetty/hetty_cert.pem", "Path to certificate.")
fs.BoolVar(&cmd.firefox, "firefox", false, "Uninstall certificate from Firefox trust store. (Default: false)")
fs.BoolVar(&cmd.java, "java", false, "Uninstall certificate from Java trust store. (Default: false)")
fs.BoolVar(&cmd.skipSystem, "skip-system", false, "Skip uninstalling certificate from system trust store (Default: false)")
fs.BoolVar(&cmd.skipSystem, "skip-system", false,
"Skip uninstalling certificate from system trust store (Default: false)")
cmd.config.RegisterFlags(fs)

View file

@ -288,6 +288,7 @@ func (cmd *HettyCommand) Exec(ctx context.Context, _ []string) error {
// Note: We expect httpServer.Handler to handle timeouts, thus, we don't
// need a context value with deadline here.
//nolint:contextcheck
err = httpServer.Shutdown(context.Background())
if err != nil {
return fmt.Errorf("failed to shutdown HTTP server: %w", err)

View file

@ -23,6 +23,7 @@ func main() {
if err != nil {
llog.Fatal(err)
}
//nolint:errcheck
defer logger.Sync()
cfg.logger = logger

View file

@ -408,7 +408,10 @@ func (r *mutationResolver) SetSenderRequestFilter(
return findReqFilterToSenderReqFilter(filter), nil
}
func (r *mutationResolver) CreateOrUpdateSenderRequest(ctx context.Context, input SenderRequestInput) (*SenderRequest, error) {
func (r *mutationResolver) CreateOrUpdateSenderRequest(
ctx context.Context,
input SenderRequestInput,
) (*SenderRequest, error) {
req := sender.Request{
URL: input.URL,
Header: make(http.Header),
@ -449,7 +452,10 @@ func (r *mutationResolver) CreateOrUpdateSenderRequest(ctx context.Context, inpu
return &senderReq, nil
}
func (r *mutationResolver) CreateSenderRequestFromHTTPRequestLog(ctx context.Context, id ulid.ULID) (*SenderRequest, error) {
func (r *mutationResolver) CreateSenderRequestFromHTTPRequestLog(
ctx context.Context,
id ulid.ULID,
) (*SenderRequest, error) {
req, err := r.SenderService.CloneFromRequestLog(ctx, id)
if errors.Is(err, proj.ErrNoProject) {
return nil, noActiveProjectErr(ctx)
@ -473,10 +479,13 @@ func (r *mutationResolver) SendRequest(ctx context.Context, id ulid.ULID) (*Send
var sendErr *sender.SendError
//nolint:contextcheck
req, err := r.SenderService.SendRequest(ctx2, id)
if errors.Is(err, proj.ErrNoProject) {
switch {
case errors.Is(err, proj.ErrNoProject):
return nil, noActiveProjectErr(ctx)
} else if errors.As(err, &sendErr) {
case errors.As(err, &sendErr):
return nil, &gqlerror.Error{
Path: graphql.GetPath(ctx),
Message: fmt.Sprintf("Sending request failed: %v", sendErr.Unwrap()),
@ -484,7 +493,7 @@ func (r *mutationResolver) SendRequest(ctx context.Context, id ulid.ULID) (*Send
"code": "send_request_failed",
},
}
} else if err != nil {
case err != nil:
return nil, fmt.Errorf("could not send request: %w", err)
}

View file

@ -24,6 +24,7 @@ type Config struct {
// with an allocated Chrome browser.
func NewExecAllocator(ctx context.Context, cfg Config) (context.Context, context.CancelFunc) {
proxyBypass := strings.Join(append([]string{"<-loopback"}, cfg.ProxyBypassHosts...), ";")
//nolint:gocritic
opts := append(defaultOpts,
chromedp.ProxyServer(cfg.ProxyServer),
chromedp.Flag("proxy-bypass-list", proxyBypass),

View file

@ -14,7 +14,11 @@ import (
"github.com/dstotijn/hetty/pkg/scope"
)
func (db *Database) FindRequestLogs(ctx context.Context, filter reqlog.FindRequestsFilter, scope *scope.Scope) ([]reqlog.RequestLog, error) {
func (db *Database) FindRequestLogs(
ctx context.Context,
filter reqlog.FindRequestsFilter,
scope *scope.Scope) ([]reqlog.RequestLog, error,
) {
if filter.ProjectID.Compare(ulid.ULID{}) == 0 {
return nil, reqlog.ErrProjectIDMustBeSet
}

View file

@ -63,7 +63,11 @@ func (db *Database) FindSenderRequestByID(ctx context.Context, senderReqID ulid.
return req, nil
}
func (db *Database) FindSenderRequests(ctx context.Context, filter sender.FindRequestsFilter, scope *scope.Scope) ([]sender.Request, error) {
func (db *Database) FindSenderRequests(
ctx context.Context,
filter sender.FindRequestsFilter,
scope *scope.Scope,
) ([]sender.Request, error) {
if filter.ProjectID.Compare(ulid.ULID{}) == 0 {
return nil, sender.ErrProjectIDMustBeSet
}

View file

@ -88,7 +88,7 @@ func LoadOrCreateCA(caKeyFile, caCertFile string) (*x509.Certificate, *rsa.Priva
keyDir, _ := filepath.Split(caKeyFile)
if keyDir != "" {
if _, err := os.Stat(keyDir); os.IsNotExist(err) {
if err := os.MkdirAll(keyDir, 0755); err != nil {
if err := os.MkdirAll(keyDir, 0o755); err != nil {
return nil, nil, fmt.Errorf("proxy: could not create directory for CA key: %w", err)
}
}
@ -97,7 +97,7 @@ func LoadOrCreateCA(caKeyFile, caCertFile string) (*x509.Certificate, *rsa.Priva
keyDir, _ = filepath.Split(caCertFile)
if keyDir != "" {
if _, err := os.Stat("keyDir"); os.IsNotExist(err) {
if err := os.MkdirAll(keyDir, 0755); err != nil {
if err := os.MkdirAll(keyDir, 0o755); err != nil {
return nil, nil, fmt.Errorf("proxy: could not create directory for CA cert: %w", err)
}
}
@ -115,7 +115,7 @@ func LoadOrCreateCA(caKeyFile, caCertFile string) (*x509.Certificate, *rsa.Priva
return nil, nil, fmt.Errorf("proxy: could not open cert file for writing: %w", err)
}
keyOut, err := os.OpenFile(caKeyFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
keyOut, err := os.OpenFile(caKeyFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
if err != nil {
return nil, nil, fmt.Errorf("proxy: could not open key file for writing: %w", err)
}

View file

@ -141,6 +141,7 @@ func (p *Proxy) handleConnect(w http.ResponseWriter) {
p.logger.Errorw("Securing client connection failed.",
"error", err,
"remoteAddr", clientConn.RemoteAddr().String())
return
}

View file

@ -270,6 +270,7 @@ func ParseHTTPResponse(res *http.Response) (ResponseLog, error) {
buf := &bytes.Buffer{}
//nolint:gosec
if _, err := io.Copy(buf, gzipReader); err != nil {
return ResponseLog{}, fmt.Errorf("reqlog: could not read gzipped response body: %w", err)
}

View file

@ -117,7 +117,8 @@ func TestResponseModifier(t *testing.T) {
t.Run("called repository with request log id", func(t *testing.T) {
got := repoMock.StoreResponseLogCalls()[0].ReqLogID
if exp := reqLogID; exp.Compare(got) != 0 {
t.Fatalf("incorrect `reqLogID` argument for `Repository.AddResponseLogCalls` (expected: %v, got: %v)", exp.String(), got.String())
t.Fatalf("incorrect `reqLogID` argument for `Repository.AddResponseLogCalls` (expected: %v, got: %v)",
exp.String(), got.String())
}
})
})