diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-22 17:35:49 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-22 17:35:49 -0600 |
| commit | 20ef0d92694465ac86b550df139e8366a0a2b4fa (patch) | |
| tree | 3f14589e1ce6eb9306a3af31c3a1f9e1af5ed637 /vendor/github.com/authzed/spicedb/pkg/development/check.go | |
| parent | 44e0d272c040cdc53a98b9f1dc58ae7da67752e6 (diff) | |
feat: connect to spicedb
Diffstat (limited to 'vendor/github.com/authzed/spicedb/pkg/development/check.go')
| -rw-r--r-- | vendor/github.com/authzed/spicedb/pkg/development/check.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/vendor/github.com/authzed/spicedb/pkg/development/check.go b/vendor/github.com/authzed/spicedb/pkg/development/check.go new file mode 100644 index 0000000..292a1ea --- /dev/null +++ b/vendor/github.com/authzed/spicedb/pkg/development/check.go @@ -0,0 +1,53 @@ +package development + +import ( + v1api "github.com/authzed/authzed-go/proto/authzed/api/v1" + + "github.com/authzed/spicedb/internal/graph/computed" + v1 "github.com/authzed/spicedb/internal/services/v1" + caveattypes "github.com/authzed/spicedb/pkg/caveats/types" + v1dispatch "github.com/authzed/spicedb/pkg/proto/dispatch/v1" + "github.com/authzed/spicedb/pkg/tuple" +) + +const defaultWasmDispatchChunkSize = 100 + +// CheckResult is the result of a RunCheck operation. +type CheckResult struct { + Permissionship v1dispatch.ResourceCheckResult_Membership + MissingCaveatFields []string + DispatchDebugInfo *v1dispatch.DebugInformation + V1DebugInfo *v1api.DebugInformation +} + +// RunCheck performs a check against the data in the development context. +// +// Note that it is up to the caller to call DistinguishGraphError on the error +// if they want to distinguish between user errors and internal errors. +func RunCheck(devContext *DevContext, resource tuple.ObjectAndRelation, subject tuple.ObjectAndRelation, caveatContext map[string]any) (CheckResult, error) { + ctx := devContext.Ctx + cr, meta, err := computed.ComputeCheck(ctx, devContext.Dispatcher, + caveattypes.Default.TypeSet, + computed.CheckParameters{ + ResourceType: resource.RelationReference(), + Subject: subject, + CaveatContext: caveatContext, + AtRevision: devContext.Revision, + MaximumDepth: maxDispatchDepth, + DebugOption: computed.TraceDebuggingEnabled, + }, + resource.ObjectID, + defaultWasmDispatchChunkSize, + ) + if err != nil { + return CheckResult{v1dispatch.ResourceCheckResult_NOT_MEMBER, nil, nil, nil}, err + } + + reader := devContext.Datastore.SnapshotReader(devContext.Revision) + converted, err := v1.ConvertCheckDispatchDebugInformation(ctx, caveattypes.Default.TypeSet, caveatContext, meta.DebugInfo, reader) + if err != nil { + return CheckResult{v1dispatch.ResourceCheckResult_NOT_MEMBER, nil, nil, nil}, err + } + + return CheckResult{cr.Membership, cr.MissingExprFields, meta.DebugInfo, converted}, nil +} |
