Skip to content

Commit 5050123

Browse files
authored
Update buf and use protovalidate (#2596)
1 parent c16c1c3 commit 5050123

File tree

32 files changed

+276
-16158
lines changed

32 files changed

+276
-16158
lines changed

buf.gen.yaml

100755100644
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
#!/usr/bin/env -S buf generate -o pkg/proto proto/internal --template
21
---
3-
version: "v1"
2+
version: "v2"
43
managed:
54
enabled: true
6-
go_package_prefix:
7-
default: "github.com/authzed/spicedb/pkg/proto"
8-
except:
9-
- "buf.build/envoyproxy/protoc-gen-validate"
10-
- "buf.build/authzed/api"
11-
- "buf.build/googleapis/googleapis"
5+
disable:
6+
- file_option: "go_package"
7+
module: "buf.build/authzed/api"
8+
- file_option: "go_package"
9+
module: "buf.build/googleapis/googleapis"
10+
- file_option: "go_package"
11+
module: "buf.build/bufbuild/protovalidate"
12+
override:
13+
- file_option: "go_package_prefix"
14+
value: "github.com/authzed/spicedb/pkg/proto"
1215
plugins:
13-
- name: "go"
14-
path: ["go", "run", "google.golang.org/protobuf/cmd/protoc-gen-go"]
15-
out: "."
16+
- remote: "buf.build/protocolbuffers/go:v1.36.10"
17+
out: "pkg/proto"
1618
opt: "paths=source_relative"
17-
- name: "go-grpc"
18-
out: "."
19-
path: ["go", "run", "google.golang.org/grpc/cmd/protoc-gen-go-grpc"]
19+
- remote: "buf.build/grpc/go:v1.5.1"
20+
out: "pkg/proto"
2021
opt: "paths=source_relative"
21-
- name: "go-vtproto"
22-
path:
22+
# NOTE: we use the local vs remote here because we use a more recent version of vtproto than is available
23+
# in the buf registry.
24+
- local:
2325
[
2426
"go",
2527
"run",
2628
"github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto",
2729
]
28-
out: "."
29-
# To generate pooling methods, you must add an additional `pool=fully/qualified.ProtoMessageType`
30+
out: "pkg/proto"
3031
opt: "paths=source_relative,features=marshal+unmarshal+size+clone+pool+equal"
31-
- name: "validate"
32-
path: ["go", "run", "github.com/envoyproxy/protoc-gen-validate"]
33-
out: "."
34-
opt: "paths=source_relative,lang=go"

buf.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by buf. DO NOT EDIT.
2+
version: v2
3+
deps:
4+
- name: buf.build/authzed/api
5+
commit: 53f3e981ed3346bab8c050c597f74602
6+
digest: b5:fb42f996d63c02edd4d890058000bae6a6fc5a07b984bd8f8544a203a295506254170a89dfad32f973190753f7f8f0b9b45edab9c13e5f5485e293933f26f014
7+
- name: buf.build/bufbuild/protovalidate
8+
commit: 52f32327d4b045a79293a6ad4e7e1236
9+
digest: b5:cbabc98d4b7b7b0447c9b15f68eeb8a7a44ef8516cb386ac5f66e7fd4062cd6723ed3f452ad8c384b851f79e33d26e7f8a94e2b807282b3def1cd966c7eace97
10+
- name: buf.build/envoyproxy/protoc-gen-validate
11+
commit: 45685e052c7e406b9fbd441fc7a568a5
12+
digest: b5:63939effe0c64a94cd3151770b73007e43c9aeff31dcb24737fb11750dcaaca99338df3c1e5513828a685c743712e59ce283e046c27725e96928d200492bb6ec
13+
- name: buf.build/googleapis/googleapis
14+
commit: 711e289f6a384c4caeebaff7c6931ade
15+
digest: b5:968b318852fd6a5275af38047f71727d2406fb4a401912069359cd5551ee22fe4397d0e397d5e4a952eb4c96c467b82bd3c0a564fb9a48d7dfe668e4c0047c61
16+
- name: buf.build/grpc-ecosystem/grpc-gateway
17+
commit: bc28b723cd774c32b6fbc77621518765
18+
digest: b5:a613f827fa6ff35a4f5e87e80e35ac6b35e5792cc9c5a658351072777d88c6d4df785a0c14889090db11667cf5463d122c7193b3719c7861d3e5747c22ce1381

buf.work.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
---
2-
version: "v1"
2+
version: "v2"
3+
modules:
4+
- path: "proto/internal"
35
deps:
4-
- "buf.build/envoyproxy/protoc-gen-validate:bb405eae115246f0b5ccf8997136e3d8"
56
- "buf.build/authzed/api:53f3e981ed3346bab8c050c597f74602"
7+
- "buf.build/bufbuild/protovalidate:v1.0.0"
68
- "buf.build/googleapis/googleapis:4d230ddc6b6d28ad7d2503926a97c6f7fa15483d"
79
lint:
810
except:
911
- "ENUM_VALUE_PREFIX"
1012
- "ENUM_ZERO_VALUE_SUFFIX"
1113
ignore_only:
1214
FIELD_LOWER_SNAKE_CASE:
13-
- "core/v1/core.proto" # TODO: Remove after v0 api removed
15+
- "proto/internal/core/v1/core.proto"
16+
disallow_comment_ignores: true
1417
breaking:
1518
use:
1619
- "WIRE"
20+
except:
21+
- "FIELD_SAME_DEFAULT"
1722
ignore_only:
1823
FIELD_WIRE_COMPATIBLE_TYPE:
19-
- "dispatch/v1/dispatch.proto" # TODO: Remove after core v1 is merged
24+
- "proto/internal/dispatch/v1/dispatch.proto"

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ replace github.com/influxdata/tdigest => github.com/hdrodz/tdigest v0.0.0-202304
1818
replace github.com/docker/docker => github.com/docker/docker v28.0.0+incompatible
1919

2020
require (
21+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20251209175733-2a1774d88802.1
2122
buf.build/gen/go/prometheus/prometheus/protocolbuffers/go v1.36.10-20251118093737-4105057cc7d4.1
2223
buf.build/go/protovalidate v1.1.0
2324
cloud.google.com/go/spanner v1.86.1
@@ -48,7 +49,6 @@ require (
4849
github.com/dlmiddlecote/sqlstats v1.0.2
4950
github.com/dustin/go-humanize v1.0.1
5051
github.com/emirpasic/gods v1.18.1
51-
github.com/envoyproxy/protoc-gen-validate v1.3.0
5252
github.com/ettle/strcase v0.2.0
5353
github.com/exaring/otelpgx v0.9.3
5454
github.com/fatih/color v1.18.0
@@ -149,7 +149,6 @@ tool (
149149
require (
150150
4d63.com/gocheckcompilerdirectives v1.3.0 // indirect
151151
4d63.com/gochecknoglobals v0.2.2 // indirect
152-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20251209175733-2a1774d88802.1 // indirect
153152
buf.build/gen/go/gogo/protobuf/protocolbuffers/go v1.36.10-20240617172848-e1dbca2775a7.1 // indirect
154153
cel.dev/expr v0.24.0 // indirect
155154
cloud.google.com/go v0.122.0 // indirect
@@ -243,6 +242,7 @@ require (
243242
github.com/ecordell/optgen v0.2.3 // indirect
244243
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
245244
github.com/envoyproxy/go-control-plane/envoy v1.35.0 // indirect
245+
github.com/envoyproxy/protoc-gen-validate v1.3.0 // indirect
246246
github.com/fatih/structtag v1.2.0 // indirect
247247
github.com/felixge/httpsnoop v1.0.4 // indirect
248248
github.com/firefart/nonamedreturns v1.0.6 // indirect

internal/services/steelthreadtesting/testdata/real-schema-and-data-with-many-relations.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
schema: |+
23
use expiration
34

internal/testfixtures/validating.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"fmt"
66

7+
"buf.build/go/protovalidate"
8+
79
v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
810

911
"github.com/authzed/spicedb/pkg/datastore"
@@ -61,7 +63,7 @@ func (vsr validatingSnapshotReader) LegacyListAllNamespaces(
6163
}
6264

6365
for _, ns := range read {
64-
err := ns.Definition.Validate()
66+
err := protovalidate.Validate(ns.Definition)
6567
if err != nil {
6668
return nil, err
6769
}
@@ -80,7 +82,7 @@ func (vsr validatingSnapshotReader) LegacyLookupNamespacesWithNames(
8082
}
8183

8284
for _, ns := range read {
83-
err := ns.Definition.Validate()
85+
err := protovalidate.Validate(ns.Definition)
8486
if err != nil {
8587
return nil, err
8688
}
@@ -118,7 +120,7 @@ func (vsr validatingSnapshotReader) LegacyReadNamespaceByName(
118120
return read, createdAt, err
119121
}
120122

121-
err = read.Validate()
123+
err = protovalidate.Validate(read)
122124
return read, createdAt, err
123125
}
124126

@@ -149,7 +151,7 @@ func (vsr validatingSnapshotReader) LegacyReadCaveatByName(ctx context.Context,
149151
return read, createdAt, err
150152
}
151153

152-
err = read.Validate()
154+
err = protovalidate.Validate(read)
153155
return read, createdAt, err
154156
}
155157

@@ -160,7 +162,7 @@ func (vsr validatingSnapshotReader) LegacyLookupCaveatsWithNames(ctx context.Con
160162
}
161163

162164
for _, caveat := range read {
163-
err := caveat.Definition.Validate()
165+
err := protovalidate.Validate(caveat.Definition)
164166
if err != nil {
165167
return nil, err
166168
}
@@ -176,7 +178,7 @@ func (vsr validatingSnapshotReader) LegacyListAllCaveats(ctx context.Context) ([
176178
}
177179

178180
for _, caveat := range read {
179-
err := caveat.Definition.Validate()
181+
err := protovalidate.Validate(caveat.Definition)
180182
if err != nil {
181183
return nil, err
182184
}
@@ -191,7 +193,7 @@ type validatingReadWriteTransaction struct {
191193
}
192194

193195
func (vrwt validatingReadWriteTransaction) RegisterCounter(ctx context.Context, name string, filter *core.RelationshipFilter) error {
194-
if err := filter.Validate(); err != nil {
196+
if err := protovalidate.Validate(filter); err != nil {
195197
return err
196198
}
197199

@@ -208,7 +210,7 @@ func (vrwt validatingReadWriteTransaction) StoreCounterValue(ctx context.Context
208210

209211
func (vrwt validatingReadWriteTransaction) LegacyWriteNamespaces(ctx context.Context, newConfigs ...*core.NamespaceDefinition) error {
210212
for _, newConfig := range newConfigs {
211-
if err := newConfig.Validate(); err != nil {
213+
if err := protovalidate.Validate(newConfig); err != nil {
212214
return err
213215
}
214216
}
@@ -236,7 +238,7 @@ func (vrwt validatingReadWriteTransaction) WriteRelationships(ctx context.Contex
236238
}
237239

238240
func (vrwt validatingReadWriteTransaction) DeleteRelationships(ctx context.Context, filter *v1.RelationshipFilter, options ...options.DeleteOptionsOption) (uint64, bool, error) {
239-
if err := filter.Validate(); err != nil {
241+
if err := protovalidate.Validate(filter); err != nil {
240242
return 0, false, err
241243
}
242244

magefiles/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (Gen) Go() error {
2828
func (Gen) Proto() error {
2929
fmt.Println("generating buf")
3030
return RunSh("go", Tool())("run", "github.com/bufbuild/buf/cmd/buf",
31-
"generate", "-o", "../pkg/proto", "../proto/internal", "--template", "../buf.gen.yaml")
31+
"generate", "--template", "../buf.gen.yaml", "-o", "..", "..")
3232
}
3333

3434
func (Gen) Completions() error {

pkg/composableschemadsl/compiler/compiler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ func TestCompile(t *testing.T) {
769769
"invalid definition name",
770770
nilPrefix,
771771
`definition someTenant/fo {}`,
772-
"parse error in `invalid definition name`, line 1, column 1: error in object definition someTenant/fo: invalid NamespaceDefinition.Name: value does not match regex pattern \"^([a-z][a-z0-9_]{1,62}[a-z0-9]/)*[a-z][a-z0-9_]{1,62}[a-z0-9]$\"",
772+
"parse error in `invalid definition name`, line 1, column 1: error in object definition someTenant/fo: validation error: name: value does not match regex pattern `^([a-z][a-z0-9_]{1,62}[a-z0-9]/)*[a-z][a-z0-9_]{1,62}[a-z0-9]$`",
773773
[]SchemaDefinition{},
774774
},
775775
{
@@ -778,7 +778,7 @@ func TestCompile(t *testing.T) {
778778
`definition some_tenant/foos {
779779
relation ab: some_tenant/foos
780780
}`,
781-
"parse error in `invalid relation name`, line 2, column 5: error in relation ab: invalid Relation.Name: value does not match regex pattern \"^[a-z][a-z0-9_]{1,62}[a-z0-9]$\"",
781+
"parse error in `invalid relation name`, line 2, column 5: error in relation ab: validation error: name: value does not match regex pattern `^[a-z][a-z0-9_]{1,62}[a-z0-9]$`",
782782
[]SchemaDefinition{},
783783
},
784784
{

pkg/composableschemadsl/compiler/translator.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path/filepath"
1010
"strings"
1111

12+
"buf.build/go/protovalidate"
1213
"github.com/ccoveille/go-safecast/v2"
1314
"github.com/jzelinskie/stringz"
1415

@@ -265,7 +266,7 @@ func translateObjectDefinition(tctx *translationContext, defNode *dslNode) (*cor
265266
ns.SourcePosition = getSourcePosition(defNode, tctx.mapper)
266267

267268
if !tctx.skipValidate {
268-
if err = ns.Validate(); err != nil {
269+
if err = protovalidate.Validate(ns); err != nil {
269270
return nil, defNode.Errorf("error in object definition %s: %w", nspath, err)
270271
}
271272
}
@@ -278,7 +279,7 @@ func translateObjectDefinition(tctx *translationContext, defNode *dslNode) (*cor
278279
ns.SourcePosition = getSourcePosition(defNode, tctx.mapper)
279280

280281
if !tctx.skipValidate {
281-
if err := ns.Validate(); err != nil {
282+
if err := protovalidate.Validate(ns); err != nil {
282283
return nil, defNode.Errorf("error in object definition %s: %w", nspath, err)
283284
}
284285
}
@@ -418,7 +419,7 @@ func translateRelation(tctx *translationContext, relationNode *dslNode) (*core.R
418419
}
419420

420421
if !tctx.skipValidate {
421-
if err := relation.Validate(); err != nil {
422+
if err := protovalidate.Validate(relation); err != nil {
422423
return nil, relationNode.Errorf("error in relation %s: %w", relationName, err)
423424
}
424425
}
@@ -448,7 +449,7 @@ func translatePermission(tctx *translationContext, permissionNode *dslNode) (*co
448449
}
449450

450451
if !tctx.skipValidate {
451-
if err := permission.Validate(); err != nil {
452+
if err := protovalidate.Validate(permission); err != nil {
452453
return nil, permissionNode.Errorf("error in permission %s: %w", permissionName, err)
453454
}
454455
}
@@ -704,7 +705,7 @@ func translateSpecificTypeReference(tctx *translationContext, typeRefNode *dslNo
704705
}
705706

706707
if !tctx.skipValidate {
707-
if err := ref.Validate(); err != nil {
708+
if err := protovalidate.Validate(ref); err != nil {
708709
return nil, typeRefNode.Errorf("invalid type relation: %w", err)
709710
}
710711
}

0 commit comments

Comments
 (0)