Skip to content

Commit b92a440

Browse files
authored
Merge pull request #137 from authzed/add-linter
chore: add basic linter rules
2 parents db5d81e + 5900e77 commit b92a440

26 files changed

+204
-143
lines changed

.golangci.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
version: "2"
3+
run:
4+
allow-parallel-runners: true
5+
linters:
6+
enable:
7+
- "bidichk"
8+
- "bodyclose"
9+
- "errcheck"
10+
- "errname"
11+
- "errorlint"
12+
# - "gocritic"
13+
- "goprintffuncname"
14+
# - "gosec"
15+
- "govet"
16+
- "importas"
17+
- "ineffassign"
18+
- "makezero"
19+
- "prealloc"
20+
- "predeclared"
21+
- "promlinter"
22+
# - "revive"
23+
- "rowserrcheck"
24+
- "spancheck"
25+
- "staticcheck"
26+
- "tagalign"
27+
- "testifylint"
28+
- "tparallel"
29+
- "unconvert"
30+
- "usetesting"
31+
- "wastedassign"
32+
- "whitespace"
33+
- "unused"
34+
settings:
35+
staticcheck:
36+
checks:
37+
- "all"
38+
- "-ST1000" # at least one file in a package should have a package comment
39+
- "-ST1003" # poorly chosen identifier
40+
formatters:
41+
enable:
42+
- "gci"
43+
- "gofmt"
44+
- "gofumpt"
45+
- "goimports"
46+
settings:
47+
gci:
48+
sections:
49+
- "standard"
50+
- "default"
51+
- "prefix(github.com/authzed)"
52+
- "localmodule"
53+
goimports:
54+
local-prefixes:
55+
- "github.com/authzed/spicedb-kubeapi-proxy"

pkg/authz/authz.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55
"fmt"
66
"net/http"
77

8+
"github.com/cschleiden/go-workflows/client"
89
"github.com/samber/lo"
910
"k8s.io/apimachinery/pkg/api/meta"
11+
"k8s.io/apimachinery/pkg/types"
12+
"k8s.io/apiserver/pkg/endpoints/request"
1013
"k8s.io/klog/v2"
1114

1215
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
13-
"github.com/cschleiden/go-workflows/client"
14-
"k8s.io/apimachinery/pkg/types"
15-
"k8s.io/apiserver/pkg/endpoints/request"
1616

1717
"github.com/authzed/spicedb-kubeapi-proxy/pkg/rules"
1818
)

pkg/authz/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"errors"
66
"fmt"
77

8+
"golang.org/x/sync/errgroup"
89
"k8s.io/klog/v2"
910

1011
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
11-
"golang.org/x/sync/errgroup"
1212

1313
"github.com/authzed/spicedb-kubeapi-proxy/pkg/rules"
1414
)

pkg/authz/distributedtx/activity.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"io"
88
"net/http"
99

10-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
1110
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1211
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1312
"k8s.io/apiserver/pkg/endpoints/request"
1413
"k8s.io/client-go/rest"
1514

15+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
16+
1617
"github.com/authzed/spicedb-kubeapi-proxy/pkg/failpoints"
1718
)
1819

@@ -111,7 +112,8 @@ func (h *ActivityHandler) WriteToKube(ctx context.Context, req *KubeReqInput) (*
111112
resp := KubeResp{}
112113
body, err := res.Raw()
113114
var nonKerr error
114-
if kerr, ok := err.(*k8serrors.StatusError); ok {
115+
kerr := &k8serrors.StatusError{}
116+
if errors.As(err, &kerr) {
115117
resp.Err = *kerr
116118
resp.StatusCode = int(kerr.Status().Code)
117119
} else {

pkg/authz/distributedtx/activity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestWriteToKube(t *testing.T) {
5959
})
6060

6161
require.NoError(t, err)
62-
require.Equal(t, `{"hi":"bye"}`, string(resp.Body))
62+
require.JSONEq(t, `{"hi":"bye"}`, string(resp.Body))
6363
require.Equal(t, http.StatusCreated, resp.StatusCode)
6464
}
6565

pkg/authz/distributedtx/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"context"
55
"log/slog"
66

7-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
87
"github.com/cschleiden/go-workflows/backend"
98
"github.com/cschleiden/go-workflows/backend/monoprocess"
109
"github.com/cschleiden/go-workflows/backend/sqlite"
1110
"github.com/cschleiden/go-workflows/client"
1211
"github.com/cschleiden/go-workflows/worker"
1312
"k8s.io/client-go/rest"
1413
"k8s.io/klog/v2"
14+
15+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
1516
)
1617

1718
func SetupWithMemoryBackend(ctx context.Context, permissionClient v1.PermissionsServiceClient, kubeClient rest.Interface) (*client.Client, *Worker, error) {

pkg/authz/distributedtx/log.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package distributedtx
22

33
import (
44
"context"
5-
"k8s.io/klog/v2"
65
"log/slog"
6+
7+
"k8s.io/klog/v2"
78
)
89

910
type klogToSlogAdapter struct {

pkg/authz/distributedtx/workflow.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ import (
55
"net/http"
66
"time"
77

8-
"k8s.io/klog/v2"
9-
8+
"github.com/cespare/xxhash/v2"
9+
"github.com/cschleiden/go-workflows/workflow"
1010
"google.golang.org/grpc/codes"
1111
"google.golang.org/grpc/status"
12+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
"k8s.io/apimachinery/pkg/runtime/schema"
15+
"k8s.io/apimachinery/pkg/util/json"
16+
"k8s.io/apimachinery/pkg/util/wait"
1317
"k8s.io/apiserver/pkg/authentication/user"
1418
"k8s.io/apiserver/pkg/endpoints/request"
19+
"k8s.io/klog/v2"
1520

1621
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
17-
"github.com/cespare/xxhash/v2"
18-
"github.com/cschleiden/go-workflows/workflow"
19-
k8serrors "k8s.io/apimachinery/pkg/api/errors"
20-
"k8s.io/apimachinery/pkg/runtime/schema"
21-
"k8s.io/apimachinery/pkg/util/json"
22-
"k8s.io/apimachinery/pkg/util/wait"
2322
)
2423

2524
const (

pkg/authz/distributedtx/workflow_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import (
77
"strings"
88
"testing"
99

10-
"github.com/authzed/spicedb-kubeapi-proxy/pkg/spicedb"
11-
12-
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
1310
"github.com/cschleiden/go-workflows/client"
1411
"github.com/cschleiden/go-workflows/workflow"
1512
"github.com/google/uuid"
@@ -20,6 +17,10 @@ import (
2017
"k8s.io/apiserver/pkg/authentication/user"
2118
"k8s.io/apiserver/pkg/endpoints/request"
2219
"k8s.io/client-go/rest/fake"
20+
21+
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
22+
23+
"github.com/authzed/spicedb-kubeapi-proxy/pkg/spicedb"
2324
)
2425

2526
func TestWorkflow(t *testing.T) {
@@ -34,7 +35,7 @@ func TestWorkflow(t *testing.T) {
3435
srv, err := spicedb.NewServer(ctx, "")
3536
require.NoError(t, err)
3637
go func() {
37-
require.NoError(t, srv.Run(ctx))
38+
require.NoError(t, srv.Run(ctx)) // nolint:testifylint
3839
}()
3940

4041
dialCtx, err := srv.GRPCDialContext(ctx)
@@ -93,7 +94,7 @@ func TestWorkflow(t *testing.T) {
9394
require.NoError(t, err)
9495
require.NotNil(t, resp)
9596
require.Empty(t, resp.Err, "workflow returned error: %s", resp.Err)
96-
require.Equal(t, `{"hi":"myfriend"}`, string(resp.Body))
97+
require.JSONEq(t, `{"hi":"myfriend"}`, string(resp.Body))
9798
require.Equal(t, http.StatusCreated, resp.StatusCode)
9899
require.Equal(t, runtime.ContentTypeJSON, resp.ContentType)
99100

@@ -117,5 +118,4 @@ func TestWorkflow(t *testing.T) {
117118
require.Equal(t, v1.CheckPermissionResponse_PERMISSIONSHIP_HAS_PERMISSION, cpr.Permissionship)
118119
})
119120
}
120-
121121
}

pkg/authz/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"io"
88
"slices"
99

10+
"k8s.io/apimachinery/pkg/types"
1011
"k8s.io/klog/v2"
1112

1213
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
13-
"k8s.io/apimachinery/pkg/types"
1414

1515
"github.com/authzed/spicedb-kubeapi-proxy/pkg/config/proxyrule"
1616
"github.com/authzed/spicedb-kubeapi-proxy/pkg/rules"

0 commit comments

Comments
 (0)