Skip to content

chore: add basic linter rules #137

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

Merged
merged 1 commit into from
Jul 21, 2025
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
55 changes: 55 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
version: "2"
run:
allow-parallel-runners: true
linters:
enable:
- "bidichk"
- "bodyclose"
- "errcheck"
- "errname"
- "errorlint"
# - "gocritic"
- "goprintffuncname"
# - "gosec"
- "govet"
- "importas"
- "ineffassign"
- "makezero"
- "prealloc"
- "predeclared"
- "promlinter"
# - "revive"
- "rowserrcheck"
- "spancheck"
- "staticcheck"
- "tagalign"
- "testifylint"
- "tparallel"
- "unconvert"
- "usetesting"
- "wastedassign"
- "whitespace"
- "unused"
settings:
staticcheck:
checks:
- "all"
- "-ST1000" # at least one file in a package should have a package comment
- "-ST1003" # poorly chosen identifier
formatters:
enable:
- "gci"
- "gofmt"
- "gofumpt"
- "goimports"
settings:
gci:
sections:
- "standard"
- "default"
- "prefix(github.com/authzed)"
- "localmodule"
goimports:
local-prefixes:
- "github.com/authzed/spicedb-kubeapi-proxy"
6 changes: 3 additions & 3 deletions pkg/authz/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"
"net/http"

"github.com/cschleiden/go-workflows/client"
"github.com/samber/lo"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/klog/v2"

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

"github.com/authzed/spicedb-kubeapi-proxy/pkg/rules"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/authz/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"errors"
"fmt"

"golang.org/x/sync/errgroup"
"k8s.io/klog/v2"

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

"github.com/authzed/spicedb-kubeapi-proxy/pkg/rules"
)
Expand Down
6 changes: 4 additions & 2 deletions pkg/authz/distributedtx/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import (
"io"
"net/http"

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

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"

"github.com/authzed/spicedb-kubeapi-proxy/pkg/failpoints"
)

Expand Down Expand Up @@ -111,7 +112,8 @@ func (h *ActivityHandler) WriteToKube(ctx context.Context, req *KubeReqInput) (*
resp := KubeResp{}
body, err := res.Raw()
var nonKerr error
if kerr, ok := err.(*k8serrors.StatusError); ok {
kerr := &k8serrors.StatusError{}
if errors.As(err, &kerr) {
resp.Err = *kerr
resp.StatusCode = int(kerr.Status().Code)
} else {
Expand Down
2 changes: 1 addition & 1 deletion pkg/authz/distributedtx/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestWriteToKube(t *testing.T) {
})

require.NoError(t, err)
require.Equal(t, `{"hi":"bye"}`, string(resp.Body))
require.JSONEq(t, `{"hi":"bye"}`, string(resp.Body))
require.Equal(t, http.StatusCreated, resp.StatusCode)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/authz/distributedtx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"log/slog"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/cschleiden/go-workflows/backend"
"github.com/cschleiden/go-workflows/backend/monoprocess"
"github.com/cschleiden/go-workflows/backend/sqlite"
"github.com/cschleiden/go-workflows/client"
"github.com/cschleiden/go-workflows/worker"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
)

func SetupWithMemoryBackend(ctx context.Context, permissionClient v1.PermissionsServiceClient, kubeClient rest.Interface) (*client.Client, *Worker, error) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/authz/distributedtx/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package distributedtx

import (
"context"
"k8s.io/klog/v2"
"log/slog"

"k8s.io/klog/v2"
)

type klogToSlogAdapter struct {
Expand Down
15 changes: 7 additions & 8 deletions pkg/authz/distributedtx/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ import (
"net/http"
"time"

"k8s.io/klog/v2"

"github.com/cespare/xxhash/v2"
"github.com/cschleiden/go-workflows/workflow"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/klog/v2"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/cespare/xxhash/v2"
"github.com/cschleiden/go-workflows/workflow"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/wait"
)

const (
Expand Down
12 changes: 6 additions & 6 deletions pkg/authz/distributedtx/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import (
"strings"
"testing"

"github.com/authzed/spicedb-kubeapi-proxy/pkg/spicedb"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/cschleiden/go-workflows/client"
"github.com/cschleiden/go-workflows/workflow"
"github.com/google/uuid"
Expand All @@ -20,6 +17,10 @@ import (
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/client-go/rest/fake"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"

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

func TestWorkflow(t *testing.T) {
Expand All @@ -34,7 +35,7 @@ func TestWorkflow(t *testing.T) {
srv, err := spicedb.NewServer(ctx, "")
require.NoError(t, err)
go func() {
require.NoError(t, srv.Run(ctx))
require.NoError(t, srv.Run(ctx)) // nolint:testifylint
}()

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

Expand All @@ -117,5 +118,4 @@ func TestWorkflow(t *testing.T) {
require.Equal(t, v1.CheckPermissionResponse_PERMISSIONSHIP_HAS_PERMISSION, cpr.Permissionship)
})
}

}
2 changes: 1 addition & 1 deletion pkg/authz/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"io"
"slices"

"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"

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

"github.com/authzed/spicedb-kubeapi-proxy/pkg/config/proxyrule"
"github.com/authzed/spicedb-kubeapi-proxy/pkg/rules"
Expand Down
5 changes: 3 additions & 2 deletions pkg/authz/postfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"encoding/json"
"fmt"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"

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

Expand Down Expand Up @@ -61,7 +62,7 @@ func filterItemsWithBulkPermissions(ctx context.Context, items []interface{}, fi

// Build bulk permission check requests
var bulkItems []*v1.CheckBulkPermissionsRequestItem
var itemToRequestMap = make(map[int][]int) // maps item index to request indices
itemToRequestMap := make(map[int][]int) // maps item index to request indices

for itemIndex, item := range items {
itemMap, ok := item.(map[string]interface{})
Expand Down
7 changes: 4 additions & 3 deletions pkg/authz/postfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"encoding/json"
"testing"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/endpoints/request"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"

"github.com/authzed/spicedb-kubeapi-proxy/pkg/config/proxyrule"
"github.com/authzed/spicedb-kubeapi-proxy/pkg/rules"
)
Expand All @@ -33,7 +34,7 @@ func (m *mockPermissionsClient) CheckPermission(ctx context.Context, req *v1.Che
}

func (m *mockPermissionsClient) CheckBulkPermissions(ctx context.Context, req *v1.CheckBulkPermissionsRequest, opts ...grpc.CallOption) (*v1.CheckBulkPermissionsResponse, error) {
var pairs []*v1.CheckBulkPermissionsPair
pairs := make([]*v1.CheckBulkPermissionsPair, 0, len(req.Items))

for _, item := range req.Items {
// Create a key from the request item to match against responses
Expand Down Expand Up @@ -318,7 +319,7 @@ func TestFilterItemsWithBulkPermissions(t *testing.T) {
// Test with empty items
emptyItems, err := filterItemsWithBulkPermissions(context.Background(), []interface{}{}, []*rules.RunnableRule{filteredRules}, input, mockClient)
require.NoError(t, err)
require.Len(t, emptyItems, 0)
require.Empty(t, emptyItems)
}

func TestShouldRunPostFilters(t *testing.T) {
Expand Down
Loading
Loading