tuple

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Ellipsis is the Ellipsis relation in v0 style subjects.
	Ellipsis = "..."

	// PublicWildcard is the wildcard value for subject object IDs that indicates public access
	// for the subject type.
	PublicWildcard = "*"
)

Variables

This section is empty.

Functions

func CanonicalBytes added in v0.0.3

func CanonicalBytes(tpl *core.RelationTuple) ([]byte, error)

CanonicalBytes converts a tuple to a canonical set of bytes. If the tuple is nil or empty, returns nil. Can be used for hashing purposes.

func CopyRelationTupleToRelationship

func CopyRelationTupleToRelationship(
	src *core.RelationTuple,
	dst *v1.Relationship,
	dstCaveat *v1.ContextualizedCaveat,
)

CopyRelationTupleToRelationship copies a source core.RelationTuple to a destination v1.Relationship without allocating new memory. It requires that the structure for the destination be pre-allocated for the fixed parts, and an optional caveat context be provided for use when the source contains a caveat.

func CopyRelationshipToRelationTuple

func CopyRelationshipToRelationTuple[T objectReference, S subjectReference[T], C caveat](r relationship[T, S, C], dst *core.RelationTuple)

func Equal

func Equal(lhs, rhs *core.RelationTuple) bool

Equal returns true if the two relationships are exactly the same.

func FromRelationship

func FromRelationship[T objectReference, S subjectReference[T], C caveat](r relationship[T, S, C]) *core.RelationTuple

FromRelationship converts a Relationship into a RelationTuple.

func JoinObjectRef

func JoinObjectRef(namespace, objectID string) string

JoinObject joins the namespace and the objectId together into the standard format.

This function assumes that the provided values have already been validated.

func JoinRelRef

func JoinRelRef(namespace, relation string) string

JoinRelRef joins the namespace and relation together into the same format as `StringRR()`.

func MustFromRelationship

func MustFromRelationship[R objectReference, S subjectReference[R], C caveat](r relationship[R, S, C]) *core.RelationTuple

MustFromRelationship converts a Relationship into a RelationTuple.

func MustFromRelationships

func MustFromRelationships[R objectReference, S subjectReference[R], C caveat](rels []relationship[R, S, C]) []*core.RelationTuple

MustFromRelationships converts a slice of Relationship's into a slice of RelationTuple's.

func MustParse

func MustParse(tpl string) *core.RelationTuple

MustParse wraps Parse such that any failures panic rather than returning nil.

func MustRelString

func MustRelString(rel *v1.Relationship) string

MustRelString converts a relationship into a string. Will panic if the Relationship does not validate.

func MustSplitRelRef

func MustSplitRelRef(relRef string) (namespace, relation string)

MustSplitRelRef splits a string produced by `JoinRelRef()` and panics if it fails.

func MustString

func MustString(tpl *core.RelationTuple) string

MustString converts a tuple to a string. If the tuple is nil or empty, returns empty string.

func MustStringCaveat

func MustStringCaveat(caveat *core.ContextualizedCaveat) string

func MustStringRelationship

func MustStringRelationship(rel *v1.Relationship) string

MustStringRelationship converts a v1.Relationship to a string.

func MustToFilter

func MustToFilter(tpl *core.RelationTuple) *v1.RelationshipFilter

MustToFilter converts a RelationTuple into a RelationshipFilter. Will panic if the RelationTuple does not validate.

func MustToRelationship

func MustToRelationship(tpl *core.RelationTuple) *v1.Relationship

MustToRelationship converts a RelationTuple into a Relationship. Will panic if the RelationTuple does not validate.

func MustToRelationshipMutating

func MustToRelationshipMutating(source *core.RelationTuple, targetRel *v1.Relationship, targetCaveat *v1.ContextualizedCaveat)

MustToRelationshipMutating sets target relationship to all the values provided in the source tuple.

func MustWithCaveat

func MustWithCaveat(tpl *core.RelationTuple, caveatName string, contexts ...map[string]any) *core.RelationTuple

MustWithCaveat adds the given caveat name to the tuple. This is for testing only.

func NewRelationship

func NewRelationship() *v1.Relationship

NewRelationship creates a new Relationship value with all its required child structures allocated

func ObjectAndRelation

func ObjectAndRelation(ns, oid, rel string) *core.ObjectAndRelation

ObjectAndRelation creates an ONR from string pieces.

func OnrEqual

func OnrEqual(lhs, rhs *core.ObjectAndRelation) bool

func OnrEqualOrWildcard

func OnrEqualOrWildcard(tpl, target *core.ObjectAndRelation) bool

func Parse

func Parse(tpl string) *core.RelationTuple

Parse unmarshals the string form of a Tuple and returns nil if there is a failure.

This function treats both missing and Ellipsis relations equally.

func ParseONR

func ParseONR(onr string) *core.ObjectAndRelation

ParseONR converts a string representation of an ONR to a proto object.

func ParseRel

func ParseRel(rel string) *v1.Relationship

func ParseSubjectONR

func ParseSubjectONR(subjectOnr string) *core.ObjectAndRelation

ParseSubjectONR converts a string representation of a Subject ONR to a proto object. Unlike ParseONR, this method allows for objects without relations. If an object without a relation is given, the relation will be set to ellipsis.

func RelToFilter

func RelToFilter(rel *v1.Relationship) *v1.RelationshipFilter

RelToFilter converts a Relationship into a RelationshipFilter.

func RelationReference

func RelationReference(namespaceName string, relationName string) *core.RelationReference

RelationReference creates a RelationReference from the string pieces.

func String

func String(tpl *core.RelationTuple) (string, error)

String converts a tuple to a string. If the tuple is nil or empty, returns empty string.

func StringCaveat

func StringCaveat(caveat *core.ContextualizedCaveat) (string, error)

StringCaveat converts a contextualized caveat to a string. If the caveat is nil or empty, returns empty string.

func StringCaveatContext

func StringCaveatContext(context *structpb.Struct) (string, error)

StringCaveatContext converts the context of a caveat to a string. If the context is nil or empty, returns an empty string.

func StringCaveatRef

func StringCaveatRef(caveat *v1.ContextualizedCaveat) (string, error)

StringCaveatRef converts a v1.ContextualizedCaveat to a string.

func StringONR

func StringONR(onr *core.ObjectAndRelation) string

StringONR converts an ONR object to a string.

func StringONRStrings added in v0.0.3

func StringONRStrings(namespace, objectID, relation string) string

func StringObjectRef

func StringObjectRef(ref *v1.ObjectReference) string

StringObjectRef marshals a *v1.ObjectReference into a string.

This function assumes that the provided values have already been validated.

func StringRR

func StringRR(rr *core.RelationReference) string

StringRR converts a RR object to a string.

func StringRelationship

func StringRelationship(rel *v1.Relationship) (string, error)

StringRelationship converts a v1.Relationship to a string.

func StringRelationshipWithoutCaveat

func StringRelationshipWithoutCaveat(rel *v1.Relationship) string

StringRelationshipWithoutCaveat converts a v1.Relationship to a string, excluding any caveat.

func StringSubjectRef

func StringSubjectRef(ref *v1.SubjectReference) string

StringSubjectRef marshals a *v1.SubjectReference into a string.

This function assumes that the provided values have already been validated.

func StringWithoutCaveat

func StringWithoutCaveat(tpl *core.RelationTuple) string

StringWithoutCaveat converts a tuple to a string, without its caveat included.

func StringsONRs

func StringsONRs(onrs []*core.ObjectAndRelation) []string

StringsONRs converts ONR objects to a string slice, sorted.

func ToFilter

func ToFilter(tpl *core.RelationTuple) *v1.RelationshipFilter

ToFilter converts a RelationTuple into a RelationshipFilter.

func ToRelationship

func ToRelationship(tpl *core.RelationTuple) *v1.Relationship

ToRelationship converts a RelationTuple into a Relationship.

func UpdateFromRelationshipUpdate

func UpdateFromRelationshipUpdate(update *v1.RelationshipUpdate) *core.RelationTupleUpdate

UpdateFromRelationshipUpdate converts a RelationshipUpdate into a RelationTupleUpdate.

func UpdateFromRelationshipUpdates

func UpdateFromRelationshipUpdates(updates []*v1.RelationshipUpdate) []*core.RelationTupleUpdate

func UpdateToRelationshipUpdate

func UpdateToRelationshipUpdate(update *core.RelationTupleUpdate) *v1.RelationshipUpdate

UpdateToRelationshipUpdate converts a RelationTupleUpdate into a RelationshipUpdate.

func UpdatesToRelationshipUpdates

func UpdatesToRelationshipUpdates(updates []*core.RelationTupleUpdate) []*v1.RelationshipUpdate

UpdatesToRelationshipUpdates converts a slice of RelationTupleUpdate into a slice of RelationshipUpdate.

func UsersetToSubjectFilter

func UsersetToSubjectFilter(userset *core.ObjectAndRelation) *v1.SubjectFilter

UsersetToSubjectFilter converts a userset to the equivalent exact SubjectFilter.

func ValidateResourceID

func ValidateResourceID(objectID string) error

ValidateResourceID ensures that the given resource ID is valid. Returns an error if not.

func ValidateSubjectID

func ValidateSubjectID(subjectID string) error

ValidateSubjectID ensures that the given object ID (under a subject reference) is valid. Returns an error if not.

func WithCaveat

func WithCaveat(tpl *core.RelationTuple, caveatName string, contexts ...map[string]any) (*core.RelationTuple, error)

WithCaveat adds the given caveat name to the tuple. This is for testing only.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL