Skip to content

Commit

Permalink
Misc lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dstotijn committed Feb 28, 2022
1 parent af26987 commit 857aa0c
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ linters:
- test
- unused
disable:
- dupl
- exhaustive
- exhaustivestruct
- gochecknoglobals
Expand All @@ -21,16 +22,20 @@ linters:
- gomnd
- interfacer
- maligned
- nilnil
- nlreturn
- scopelint
- testpackage
- varnamelen
- wrapcheck

linters-settings:
gci:
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:
Expand Down
3 changes: 2 additions & 1 deletion cmd/hetty/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions cmd/hetty/hetty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cmd/hetty/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func main() {
if err != nil {
llog.Fatal(err)
}
//nolint:errcheck
defer logger.Sync()

cfg.logger = logger
Expand Down
19 changes: 14 additions & 5 deletions pkg/api/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand All @@ -473,18 +479,21 @@ 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()),
Extensions: map[string]interface{}{
"code": "send_request_failed",
},
}
} else if err != nil {
case err != nil:
return nil, fmt.Errorf("could not send request: %w", err)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/chrome/chrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 5 additions & 1 deletion pkg/db/badger/reqlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/db/badger/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/proxy/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions pkg/reqlog/reqlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/reqlog/reqlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})
})
Expand Down

0 comments on commit 857aa0c

Please sign in to comment.