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/tuple/comparison.go | |
| parent | 44e0d272c040cdc53a98b9f1dc58ae7da67752e6 (diff) | |
feat: connect to spicedb
Diffstat (limited to 'vendor/github.com/authzed/spicedb/pkg/tuple/comparison.go')
| -rw-r--r-- | vendor/github.com/authzed/spicedb/pkg/tuple/comparison.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/vendor/github.com/authzed/spicedb/pkg/tuple/comparison.go b/vendor/github.com/authzed/spicedb/pkg/tuple/comparison.go new file mode 100644 index 0000000..159edd9 --- /dev/null +++ b/vendor/github.com/authzed/spicedb/pkg/tuple/comparison.go @@ -0,0 +1,48 @@ +package tuple + +import ( + "time" + + "google.golang.org/protobuf/proto" + + core "github.com/authzed/spicedb/pkg/proto/core/v1" +) + +// ONREqual checks if two ObjectAndRelation instances are equal. +func ONREqual(lhs, rhs ObjectAndRelation) bool { + return lhs == rhs +} + +// ONREqualOrWildcard checks if an ObjectAndRelation matches another ObjectAndRelation or is a wildcard. +func ONREqualOrWildcard(onr, target ObjectAndRelation) bool { + return ONREqual(onr, target) || (onr.ObjectID == PublicWildcard && onr.ObjectType == target.ObjectType) +} + +// Equal returns true if the two relationships are exactly the same. +func Equal(lhs, rhs Relationship) bool { + return ONREqual(lhs.Resource, rhs.Resource) && ONREqual(lhs.Subject, rhs.Subject) && caveatEqual(lhs.OptionalCaveat, rhs.OptionalCaveat) && expirationEqual(lhs.OptionalExpiration, rhs.OptionalExpiration) +} + +func expirationEqual(lhs, rhs *time.Time) bool { + if lhs == nil && rhs == nil { + return true + } + + if lhs == nil || rhs == nil { + return false + } + + return lhs.Equal(*rhs) +} + +func caveatEqual(lhs, rhs *core.ContextualizedCaveat) bool { + if lhs == nil && rhs == nil { + return true + } + + if lhs == nil || rhs == nil { + return false + } + + return lhs.CaveatName == rhs.CaveatName && proto.Equal(lhs.Context, rhs.Context) +} |
