tuple

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: Apache-2.0 Imports: 5 Imported by: 6

Documentation

Overview

Package tuple contains code to manipulate tuples and errors related to tuples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildObject

func BuildObject(objectType, objectID string) string

func ConvertAssertionTupleKeyToTupleKey added in v1.3.10

func ConvertAssertionTupleKeyToTupleKey(tk *openfgav1.AssertionTupleKey) *openfgav1.TupleKey

func ConvertCheckRequestTupleKeyToTupleKey added in v1.3.8

func ConvertCheckRequestTupleKeyToTupleKey(tk *openfgav1.CheckRequestTupleKey) *openfgav1.TupleKey

func ConvertReadRequestTupleKeyToTupleKey added in v1.3.8

func ConvertReadRequestTupleKeyToTupleKey(tk *openfgav1.ReadRequestTupleKey) *openfgav1.TupleKey

func FromUserParts added in v1.6.1

func FromUserParts(userObjectType, userObjectID, userRelation string) string

func GetObjectRelationAsString added in v0.3.5

func GetObjectRelationAsString(objectRelation *openfgav1.ObjectRelation) string

GetObjectRelationAsString returns a string like "object#relation". If there is no relation it returns "object".

func GetRelation

func GetRelation(objectRelation string) string

GetRelation returns the 'relation' portion of an object relation string (e.g. `object#relation`), which may be empty if the input is malformed (or does not contain a relation).

func GetType

func GetType(objectID string) string

GetType returns the type from a supplied Object identifier or an empty string if the object id does not contain a type.

func IsObjectRelation

func IsObjectRelation(userset string) bool

IsObjectRelation returns true if the given string specifies a valid object and relation.

func IsSelfDefining added in v1.7.0

func IsSelfDefining(tuple *openfgav1.TupleKey) bool

IsSelfDefining returns true if the tuple is reflexive/self-defining. E.g. Document:1#viewer@document:1#viewer. See https://github.com/openfga/rfcs/blob/main/20240328-queries-with-usersets.md

func IsTypedWildcard added in v0.3.0

func IsTypedWildcard(s string) bool

IsTypedWildcard returns true if the string 's' is a typed wildcard. A typed wildcard has the form 'type:*'.

func IsValidObject

func IsValidObject(s string) bool

IsValidObject determines if a string s is a valid object. A valid object contains exactly one `:` and no `#` or spaces.

func IsValidRelation

func IsValidRelation(s string) bool

IsValidRelation determines if a string s is a valid relation. This means it does not contain any `:`, `#`, or spaces.

func IsValidUser

func IsValidUser(user string) bool

IsValidUser determines if a string is a valid user. A valid user contains at most one `:`, at most one `#` and no spaces.

func IsWildcard added in v0.3.0

func IsWildcard(s string) bool

IsWildcard returns true if the string 's' could be interpreted as a typed or untyped wildcard (e.g. '*' or 'type:*').

func MustParseTupleString added in v1.5.4

func MustParseTupleString(s string) *openfgav1.TupleKey

MustParseTupleString attempts to parse a relationship tuple specified in string notation and return the protobuf TupleKey for it. If parsing of the string fails this function will panic. It is meant for testing purposes.

Given string 'document:1#viewer@user:jon', return the protobuf TupleKey for it.

func MustParseTupleStrings added in v1.5.4

func MustParseTupleStrings(tupleStrs ...string) []*openfgav1.TupleKey

func NewAssertionTupleKey added in v1.3.10

func NewAssertionTupleKey(object, relation, user string) *openfgav1.AssertionTupleKey

func NewCheckRequestTupleKey added in v1.3.8

func NewCheckRequestTupleKey(object, relation, user string) *openfgav1.CheckRequestTupleKey

func NewExpandRequestTupleKey added in v1.3.8

func NewExpandRequestTupleKey(object, relation string) *openfgav1.ExpandRequestTupleKey

func NewRelationshipCondition added in v1.3.8

func NewRelationshipCondition(name string, context *structpb.Struct) *openfgav1.RelationshipCondition

func NewTupleKey

func NewTupleKey(object, relation, user string) *openfgav1.TupleKey

func NewTupleKeyWithCondition added in v1.3.8

func NewTupleKeyWithCondition(
	object, relation, user, conditionName string,
	context *structpb.Struct,
) *openfgav1.TupleKey

func ObjectKey added in v0.2.1

func ObjectKey(obj *openfgav1.Object) string

ObjectKey returns the canonical key for the provided Object. The ObjectKey of an object is the string 'objectType:objectId'.

func ParseTupleString added in v1.5.4

func ParseTupleString(s string) (*openfgav1.TupleKey, error)

ParseTupleString attempts to parse a relationship tuple specified in string notation and return the protobuf TupleKey for it. If parsing of the string fails this function returns an err.

Given string 'document:1#viewer@user:jon', return the protobuf TupleKey for it or an error.

func SplitObject

func SplitObject(object string) (string, string)

SplitObject splits an object into an objectType, an optional objectRelation, and an objectID. E.g.

  1. "group:fga" returns "group" and "fga".
  2. "group#member:fga" returns "group#member" and "fga".
  3. "anne" returns "" and "anne".

func SplitObjectRelation

func SplitObjectRelation(objectRelation string) (string, string)

SplitObjectRelation splits an object relation string into an object ID and relation name. If no relation is present, it returns the original string and an empty relation.

func StringToUserProto added in v1.5.4

func StringToUserProto(userKey UserString) *openfgav1.User

StringToUserProto returns a User proto from a string. Ex: 'user:maria#member'. It is the opposite of UserProtoToString function.

func ToObjectRelationString

func ToObjectRelationString(object, relation string) string

ToObjectRelationString formats an object/relation pair as an object#relation string. This is the inverse of SplitObjectRelation.

func ToUserParts added in v1.6.1

func ToUserParts(user string) (string, string, string)

func ToUserPartsFromObjectRelation added in v1.6.1

func ToUserPartsFromObjectRelation(u *openfgav1.ObjectRelation) (string, string, string)

func TupleKeyToString

func TupleKeyToString(tk TupleWithoutCondition) string

TupleKeyToString converts a tuple key into its string representation. It assumes the tupleKey is valid (i.e. no forbidden characters).

func TupleKeyToTupleKeyWithoutCondition added in v1.3.8

func TupleKeyToTupleKeyWithoutCondition(tk *openfgav1.TupleKey) *openfgav1.TupleKeyWithoutCondition

func TupleKeyWithConditionToString added in v1.3.8

func TupleKeyWithConditionToString(tk TupleWithCondition) string

TupleKeyWithConditionToString converts a tuple key with condition into its string representation. It assumes the tupleKey is valid (i.e. no forbidden characters).

func TupleKeyWithoutConditionToTupleKey added in v1.3.8

func TupleKeyWithoutConditionToTupleKey(tk *openfgav1.TupleKeyWithoutCondition) *openfgav1.TupleKey

func TupleKeysWithoutConditionToTupleKeys added in v1.3.8

func TupleKeysWithoutConditionToTupleKeys(tks ...*openfgav1.TupleKeyWithoutCondition) []*openfgav1.TupleKey

func TypedPublicWildcard added in v1.5.2

func TypedPublicWildcard(objectType string) string

TypedPublicWildcard returns the string tuple representation for a given object type (ex: "user:*").

func UsersetMatchTypeAndRelation added in v1.7.0

func UsersetMatchTypeAndRelation(userset, relation, typee string) bool

UsersetMatchTypeAndRelation returns true if the type and relation of a userset match the inputs.

Types

type InvalidConditionalTupleError added in v1.3.8

type InvalidConditionalTupleError struct {
	Cause    error
	TupleKey TupleWithCondition
}

InvalidConditionalTupleError is returned if the tuple's condition is invalid.

func (*InvalidConditionalTupleError) Error added in v1.3.8

func (*InvalidConditionalTupleError) Is added in v1.3.8

func (i *InvalidConditionalTupleError) Is(target error) bool

type InvalidTupleError

type InvalidTupleError struct {
	Cause    error
	TupleKey TupleWithoutCondition
}

InvalidTupleError is returned if the tuple is invalid.

func (*InvalidTupleError) Error

func (i *InvalidTupleError) Error() string

func (*InvalidTupleError) Is added in v0.3.0

func (i *InvalidTupleError) Is(target error) bool

type RelationNotFoundError

type RelationNotFoundError struct {
	TupleKey *openfgav1.TupleKey
	Relation string
	TypeName string
}

func (*RelationNotFoundError) Error

func (i *RelationNotFoundError) Error() string

func (*RelationNotFoundError) Is added in v0.3.0

func (i *RelationNotFoundError) Is(target error) bool

type Tuple added in v1.8.5

type Tuple openfgav1.TupleKey

func From added in v1.8.5

func From(tk *openfgav1.TupleKey) *Tuple

func (*Tuple) GetObject added in v1.8.5

func (t *Tuple) GetObject() string

func (*Tuple) GetRelation added in v1.8.5

func (t *Tuple) GetRelation() string

func (*Tuple) GetUser added in v1.8.5

func (t *Tuple) GetUser() string

func (*Tuple) String added in v1.8.5

func (t *Tuple) String() string

type TupleKeys added in v1.8.4

type TupleKeys []*openfgav1.TupleKey

func (TupleKeys) Len added in v1.8.4

func (tk TupleKeys) Len() int

Len is a method that is required to implement the sort.Interface interface. Len returns the number of elements in the slice.

func (TupleKeys) Less added in v1.8.4

func (tk TupleKeys) Less(i, j int) bool

Less is a method that is required to implement the sort.Interface interface. Less returns true when the value at index i is less than the value at index j. Tuples are compared first by their object, then their relation, then their user, and finally their condition. If Less(i, j) returns false and Less(j, i) returns false, then the tuples are equal.

func (TupleKeys) Swap added in v1.8.4

func (tk TupleKeys) Swap(i, j int)

Swap is a method that is required to implement the sort.Interface interface. Swap exchanges the values at slice indexes i and j.

type TupleWithCondition added in v1.3.8

type TupleWithCondition interface {
	TupleWithoutCondition
	GetCondition() *openfgav1.RelationshipCondition
}

type TupleWithoutCondition added in v1.3.8

type TupleWithoutCondition interface {
	GetUser() string
	GetObject() string
	GetRelation() string
	String() string
}

type TypeNotFoundError

type TypeNotFoundError struct {
	TypeName string
}

func (*TypeNotFoundError) Error

func (i *TypeNotFoundError) Error() string

func (*TypeNotFoundError) Is added in v0.3.0

func (i *TypeNotFoundError) Is(target error) bool

type UserString added in v1.5.4

type UserString = string

func UserProtoToString added in v1.5.4

func UserProtoToString(obj *openfgav1.User) UserString

UserProtoToString returns a string from a User proto. Ex: 'user:maria' or 'group:fga#member'. It is the opposite of StringToUserProto function.

type UserType

type UserType string
const (
	User     UserType = "user"
	UserSet  UserType = "userset"
	Wildcard          = "*"
)

func GetUserTypeFromUser

func GetUserTypeFromUser(user string) UserType

GetUserTypeFromUser returns the type of user (userset or user).

Jump to

Keyboard shortcuts

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