Skip to content

Commit 4dbdc17

Browse files
committed
update deps
Signed-off-by: Dennis Buduev <dbuduev@users.noreply.github.com>
1 parent a86fb05 commit 4dbdc17

File tree

6 files changed

+365
-633
lines changed

6 files changed

+365
-633
lines changed

pgx-adapter/adapter.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"fmt"
99
"strings"
1010

11-
responsev1 "github.com/cerbos/cerbos/api/genpb/cerbos/response/v1"
11+
enginev1 "github.com/cerbos/cerbos/api/genpb/cerbos/engine/v1"
1212
"github.com/iancoleman/strcase"
1313
)
1414

@@ -31,13 +31,18 @@ var toSQLField = map[string]string{}
3131

3232
var ErrExpressionExpected = errors.New("expected expression")
3333

34-
type BuildPredicateType func(e *responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression) (where string, args []interface{}, err error)
34+
type filterOpExpression = enginev1.PlanResourcesFilter_Expression_Operand_Expression
35+
type filterOpValue = enginev1.PlanResourcesFilter_Expression_Operand_Value
36+
type filterOpVariable = enginev1.PlanResourcesFilter_Expression_Operand_Variable
37+
type filterOp = enginev1.PlanResourcesFilter_Expression_Operand
3538

36-
func (t BuildPredicateType) BuildPredicate(e *responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression) (where string, args []interface{}, err error) {
39+
type BuildPredicateType func(e *filterOpExpression) (where string, args []interface{}, err error)
40+
41+
func (t BuildPredicateType) BuildPredicate(e *filterOpExpression) (where string, args []interface{}, err error) {
3742
return t(e)
3843
}
3944

40-
func buildPredicateImpl(e *responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression, b *strings.Builder, args *[]interface{}) (err error) {
45+
func buildPredicateImpl(e *filterOpExpression, b *strings.Builder, args *[]interface{}) (err error) {
4146
switch e.Expression.Operator {
4247
case "or", "and":
4348
b.WriteRune('(')
@@ -49,7 +54,7 @@ func buildPredicateImpl(e *responsev1.ResourcesQueryPlanResponse_Expression_Oper
4954
b.WriteString(op)
5055
b.WriteRune(' ')
5156
}
52-
if oe, ok := o.GetNode().(*responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression); ok {
57+
if oe, ok := o.GetNode().(*filterOpExpression); ok {
5358
err = buildPredicateImpl(oe, b, args)
5459
if err != nil {
5560
return err
@@ -64,7 +69,7 @@ func buildPredicateImpl(e *responsev1.ResourcesQueryPlanResponse_Expression_Oper
6469
o := e.Expression.Operands[0]
6570
b.WriteRune('(')
6671
b.WriteString("NOT ")
67-
if oe, ok := o.GetNode().(*responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression); ok {
72+
if oe, ok := o.GetNode().(*filterOpExpression); ok {
6873
err = buildPredicateImpl(oe, b, args)
6974
if err != nil {
7075
return err
@@ -84,16 +89,16 @@ func buildPredicateImpl(e *responsev1.ResourcesQueryPlanResponse_Expression_Oper
8489
b.WriteRune('(')
8590
for i, operand := range e.Expression.Operands {
8691
switch eo := operand.Node.(type) {
87-
case *responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression:
92+
case *filterOpExpression:
8893
err = buildPredicateImpl(eo, b, args)
8994
if err != nil {
9095
return err
9196
}
92-
case *responsev1.ResourcesQueryPlanResponse_Expression_Operand_Variable:
97+
case *filterOpVariable:
9398
b.WriteRune('"')
9499
b.WriteString(getFieldName(eo.Variable))
95100
b.WriteRune('"')
96-
case *responsev1.ResourcesQueryPlanResponse_Expression_Operand_Value:
101+
case *filterOpValue:
97102
*args = append(*args, eo.Value.AsInterface())
98103
b.WriteString(fmt.Sprintf("$%d", len(*args)))
99104
}
@@ -109,7 +114,7 @@ func buildPredicateImpl(e *responsev1.ResourcesQueryPlanResponse_Expression_Oper
109114
return nil
110115
}
111116

112-
func BuildPredicate(e *responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression) (where string, args []interface{}, err error) {
117+
func BuildPredicate(e *filterOpExpression) (where string, args []interface{}, err error) {
113118
if e == nil {
114119
return "", nil, nil
115120
}

pgx-adapter/adapter_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"testing"
1717
"time"
1818

19-
responsev1 "github.com/cerbos/cerbos/api/genpb/cerbos/response/v1"
20-
cerbos "github.com/cerbos/cerbos/client"
19+
"github.com/cerbos/cerbos-sdk-go/cerbos"
20+
enginev1 "github.com/cerbos/cerbos/api/genpb/cerbos/engine/v1"
2121
"github.com/ghodss/yaml"
2222
"github.com/jackc/pgx/v4"
2323
"github.com/ory/dockertest/v3"
@@ -47,10 +47,10 @@ func Test_BuildPredicate(t *testing.T) {
4747
for _, tt := range tests {
4848
t.Run(tt.SQL, func(t *testing.T) {
4949
is := require.New(t)
50-
e := new(responsev1.ResourcesQueryPlanResponse_Expression_Operand)
50+
e := new(enginev1.PlanResourcesFilter_Expression_Operand)
5151
err := protojson.Unmarshal(tt.Input, e)
5252
is.NoError(err)
53-
q, args, err := BuildPredicate(e.Node.(*responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression))
53+
q, args, err := BuildPredicate(e.Node.(*enginev1.PlanResourcesFilter_Expression_Operand_Expression))
5454
is.NoError(err)
5555
is.Equal(tt.SQL, q)
5656
is.Equal(tt.Args, args)
@@ -74,7 +74,7 @@ func runCerbos(ctx context.Context, t *testing.T) string {
7474

7575
options := &dockertest.RunOptions{
7676
Repository: "ghcr.io/cerbos/cerbos",
77-
Tag: "0.12.0",
77+
Tag: "0.47.0",
7878
Cmd: []string{"server", "--config=/config/conf.yaml"},
7979
WorkingDir: srcDir,
8080
}
@@ -197,7 +197,7 @@ func TestIntegration(t *testing.T) {
197197
WithRoles(user.Role).
198198
WithAttr("department", user.Department)
199199

200-
queryPlan, err := c.ResourcesQueryPlan(ctx, principal, cerbos.NewResource("contact", ""), "read")
200+
queryPlan, err := c.PlanResources(ctx, principal, cerbos.NewResource("contact", ""), "read")
201201
is.NoError(err)
202202

203203
filter := queryPlan.GetFilter()

pgx-adapter/db/db.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"errors"
1111
"fmt"
1212

13-
responsev1 "github.com/cerbos/cerbos/api/genpb/cerbos/response/v1"
13+
enginev1 "github.com/cerbos/cerbos/api/genpb/cerbos/engine/v1"
1414
"github.com/georgysavva/scany/pgxscan"
1515
"github.com/jackc/pgx/v4"
1616
)
@@ -19,7 +19,7 @@ import (
1919
var seed []byte
2020

2121
type predicateBuilder interface {
22-
BuildPredicate(e *responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression) (where string, args []interface{}, err error)
22+
BuildPredicate(e *enginev1.PlanResourcesFilter_Expression_Operand_Expression) (where string, args []interface{}, err error)
2323
}
2424

2525
type Client struct {
@@ -35,17 +35,17 @@ func (cli *Client) GetAllContacts(ctx context.Context) (res []*Contact, err erro
3535
return res, nil
3636
}
3737

38-
func (cli *Client) GetContacts(ctx context.Context, filter *responsev1.ResourcesQueryPlanResponse_Filter) (res []*Contact, err error) {
38+
func (cli *Client) GetContacts(ctx context.Context, filter *enginev1.PlanResourcesFilter) (res []*Contact, err error) {
3939
if filter == nil {
4040
return nil, errors.New("\"filter\" is nil")
4141
}
4242
switch filter.Kind {
43-
case responsev1.ResourcesQueryPlanResponse_Filter_KIND_ALWAYS_DENIED:
43+
case enginev1.PlanResourcesFilter_KIND_ALWAYS_DENIED:
4444
return nil, nil
45-
case responsev1.ResourcesQueryPlanResponse_Filter_KIND_ALWAYS_ALLOWED:
45+
case enginev1.PlanResourcesFilter_KIND_ALWAYS_ALLOWED:
4646
return cli.GetAllContacts(ctx)
47-
case responsev1.ResourcesQueryPlanResponse_Filter_KIND_CONDITIONAL:
48-
where, args, err := cli.predicateBuilder.BuildPredicate(filter.Condition.GetNode().(*responsev1.ResourcesQueryPlanResponse_Expression_Operand_Expression))
47+
case enginev1.PlanResourcesFilter_KIND_CONDITIONAL:
48+
where, args, err := cli.predicateBuilder.BuildPredicate(filter.Condition.GetNode().(*enginev1.PlanResourcesFilter_Expression_Operand_Expression))
4949
if err != nil {
5050
return nil, err
5151
}

pgx-adapter/db/schema.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ CREATE TABLE IF NOT EXISTS contacts (
2929
active BOOLEAN default false,
3030
marketing_opt_in BOOLEAN default false
3131
);
32-
33-
CREATE USER cerbforce_user WITH PASSWORD 'cerb';
32+
DO $$
33+
BEGIN
34+
CREATE USER cerbforce_user WITH PASSWORD 'cerb';
35+
EXCEPTION WHEN duplicate_object THEN
36+
END$$;
3437
GRANT CONNECT ON DATABASE postgres TO cerbforce_user;
3538
GRANT USAGE ON SCHEMA cerbforce TO cerbforce_user;
3639
GRANT SELECT,INSERT,UPDATE,DELETE ON cerbforce.users, cerbforce.companies, cerbforce.contacts TO cerbforce_user;

pgx-adapter/go.mod

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,114 @@
11
module github.com/cerbos/cerbos-go-adapters/pgx-adapter
22

3-
go 1.23.0
3+
go 1.24.4
44

55
require (
6-
github.com/cerbos/cerbos v0.12.0
7-
github.com/fergusstrange/embedded-postgres v1.14.0
8-
github.com/georgysavva/scany v0.3.0
6+
github.com/cerbos/cerbos-sdk-go v0.3.13
7+
github.com/cerbos/cerbos/api/genpb v0.47.0
8+
github.com/fergusstrange/embedded-postgres v1.33.0
9+
github.com/georgysavva/scany v1.2.3
910
github.com/ghodss/yaml v1.0.0
10-
github.com/iancoleman/strcase v0.2.0
11-
github.com/jackc/pgx/v4 v4.18.2
12-
github.com/ory/dockertest/v3 v3.8.1
13-
github.com/stretchr/testify v1.8.4
14-
google.golang.org/protobuf v1.33.0
11+
github.com/iancoleman/strcase v0.3.0
12+
github.com/jackc/pgx/v4 v4.18.3
13+
github.com/ory/dockertest/v3 v3.12.0
14+
github.com/stretchr/testify v1.11.1
15+
google.golang.org/protobuf v1.36.10
1516
)
1617

1718
require (
18-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
19-
github.com/Microsoft/go-winio v0.5.2 // indirect
19+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.10-20250912141014-52f32327d4b0.1 // indirect
20+
buf.build/go/protovalidate v1.0.0 // indirect
21+
cel.dev/expr v0.24.0 // indirect
22+
connectrpc.com/connect v1.19.1 // indirect
23+
connectrpc.com/otelconnect v0.8.0 // indirect
24+
dario.cat/mergo v1.0.1 // indirect
25+
filippo.io/age v1.2.1 // indirect
26+
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
27+
github.com/Microsoft/go-winio v0.6.2 // indirect
2028
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
21-
github.com/bluele/gcache v0.0.2 // indirect
22-
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
23-
github.com/cespare/xxhash v1.1.0 // indirect
24-
github.com/containerd/continuity v0.2.2 // indirect
25-
github.com/davecgh/go-spew v1.1.1 // indirect
26-
github.com/docker/cli v20.10.12+incompatible // indirect
27-
github.com/docker/docker v28.0.0+incompatible // indirect
28-
github.com/docker/go-connections v0.4.0 // indirect
29+
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
30+
github.com/bits-and-blooms/bitset v1.24.0 // indirect
31+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
32+
github.com/cerbos/cloud-api v0.1.62 // indirect
33+
github.com/containerd/continuity v0.4.5 // indirect
34+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
35+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
36+
github.com/docker/cli v27.4.1+incompatible // indirect
37+
github.com/docker/docker v28.3.3+incompatible // indirect
38+
github.com/docker/go-connections v0.5.0 // indirect
2939
github.com/docker/go-units v0.5.0 // indirect
30-
github.com/envoyproxy/protoc-gen-validate v0.10.1 // indirect
31-
github.com/gobwas/glob v0.2.3 // indirect
40+
github.com/failsafe-go/failsafe-go v0.9.1 // indirect
41+
github.com/go-logr/logr v1.4.3 // indirect
42+
github.com/go-logr/stdr v1.2.2 // indirect
43+
github.com/go-sql-driver/mysql v1.9.3 // indirect
44+
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
45+
github.com/goccy/go-json v0.10.5 // indirect
3246
github.com/gogo/protobuf v1.3.2 // indirect
33-
github.com/golang/protobuf v1.5.3 // indirect
34-
github.com/google/go-cmp v0.6.0 // indirect
47+
github.com/google/cel-go v0.26.1 // indirect
48+
github.com/google/go-cmp v0.7.0 // indirect
3549
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
36-
github.com/google/uuid v1.3.0 // indirect
37-
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
38-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.2 // indirect
39-
github.com/imdario/mergo v0.3.12 // indirect
50+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 // indirect
51+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
52+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
53+
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
4054
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
4155
github.com/jackc/pgconn v1.14.3 // indirect
4256
github.com/jackc/pgio v1.0.0 // indirect
4357
github.com/jackc/pgpassfile v1.0.0 // indirect
4458
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
45-
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
46-
github.com/jackc/pgtype v1.14.0 // indirect
59+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
60+
github.com/jackc/pgtype v1.14.4 // indirect
4761
github.com/jackc/puddle v1.3.0 // indirect
48-
github.com/jdxcode/netrc v0.0.0-20210204082910-926c7f70242a // indirect
49-
github.com/kr/text v0.2.0 // indirect
50-
github.com/lib/pq v1.10.4 // indirect
51-
github.com/mitchellh/mapstructure v1.4.3 // indirect
62+
github.com/jdx/go-netrc v1.0.0 // indirect
63+
github.com/klauspost/cpuid/v2 v2.2.11 // indirect
64+
github.com/lestrrat-go/blackmagic v1.0.4 // indirect
65+
github.com/lestrrat-go/dsig v1.0.0 // indirect
66+
github.com/lestrrat-go/dsig-secp256k1 v1.0.0 // indirect
67+
github.com/lestrrat-go/httpcc v1.0.1 // indirect
68+
github.com/lestrrat-go/httprc/v3 v3.0.1 // indirect
69+
github.com/lestrrat-go/jwx/v3 v3.0.12 // indirect
70+
github.com/lestrrat-go/option v1.0.1 // indirect
71+
github.com/lestrrat-go/option/v2 v2.0.0 // indirect
72+
github.com/lib/pq v1.10.9 // indirect
73+
github.com/minio/sha256-simd v1.0.1 // indirect
5274
github.com/moby/docker-image-spec v1.3.1 // indirect
5375
github.com/moby/sys/user v0.3.0 // indirect
54-
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
76+
github.com/moby/term v0.5.2 // indirect
5577
github.com/opencontainers/go-digest v1.0.0 // indirect
56-
github.com/opencontainers/image-spec v1.0.2 // indirect
78+
github.com/opencontainers/image-spec v1.1.1 // indirect
5779
github.com/opencontainers/runc v1.2.8 // indirect
5880
github.com/pkg/errors v0.9.1 // indirect
59-
github.com/pmezard/go-difflib v1.0.0 // indirect
81+
github.com/planetscale/vtprotobuf v0.6.1-0.20250313105119-ba97887b0a25 // indirect
82+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
83+
github.com/prometheus/client_golang v1.23.2 // indirect
84+
github.com/prometheus/procfs v0.17.0 // indirect
85+
github.com/rogpeppe/go-internal v1.14.1 // indirect
86+
github.com/rs/xid v1.6.0 // indirect
87+
github.com/segmentio/asm v1.2.1 // indirect
88+
github.com/shopspring/decimal v1.4.0 // indirect
6089
github.com/sirupsen/logrus v1.9.3 // indirect
90+
github.com/sourcegraph/conc v0.3.0 // indirect
91+
github.com/stoewer/go-strcase v1.3.1 // indirect
92+
github.com/valyala/fastjson v1.6.4 // indirect
6193
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
6294
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
6395
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
6496
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
65-
go.uber.org/atomic v1.9.0 // indirect
66-
go.uber.org/multierr v1.7.0 // indirect
67-
go.uber.org/zap v1.20.0 // indirect
68-
golang.org/x/crypto v0.36.0 // indirect
69-
golang.org/x/net v0.38.0 // indirect
70-
golang.org/x/sys v0.31.0 // indirect
71-
golang.org/x/text v0.23.0 // indirect
72-
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
73-
google.golang.org/grpc v1.56.3 // indirect
97+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
98+
go.opentelemetry.io/otel v1.38.0 // indirect
99+
go.opentelemetry.io/otel/metric v1.38.0 // indirect
100+
go.opentelemetry.io/otel/sdk v1.38.0 // indirect
101+
go.opentelemetry.io/otel/sdk/metric v1.38.0 // indirect
102+
go.opentelemetry.io/otel/trace v1.38.0 // indirect
103+
go.uber.org/multierr v1.11.0 // indirect
104+
golang.org/x/crypto v0.43.0 // indirect
105+
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
106+
golang.org/x/net v0.46.0 // indirect
107+
golang.org/x/sys v0.37.0 // indirect
108+
golang.org/x/text v0.30.0 // indirect
109+
google.golang.org/genproto/googleapis/api v0.0.0-20251014184007-4626949a642f // indirect
110+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251007200510-49b9836ed3ff // indirect
111+
google.golang.org/grpc v1.76.0 // indirect
74112
gopkg.in/yaml.v2 v2.4.0 // indirect
75113
gopkg.in/yaml.v3 v3.0.1 // indirect
76114
)

0 commit comments

Comments
 (0)