schema

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUndefinedLeafType = errors.New("undefined leaf type")
	ErrUnimplemented     = errors.New("unimplemented")
)

Functions

func GetAttributeByNameInEntityDefinition added in v0.5.0

func GetAttributeByNameInEntityDefinition(entityDefinition *base.EntityDefinition, name string) (attributeDefinition *base.AttributeDefinition, err error)

GetAttributeByNameInEntityDefinition retrieves an `AttributeDefinition` from an `EntityDefinition` by its name. It returns a pointer to the `AttributeDefinition` if it is found in the `EntityDefinition`. If the `AttributeDefinition` is not found, it returns an error with error code `ERROR_CODE_ATTRIBUTE_DEFINITION_NOT_FOUND`.

func GetEntityByName

func GetEntityByName(schema *base.SchemaDefinition, name string) (entityDefinition *base.EntityDefinition, err error)

GetEntityByName retrieves an `EntityDefinition` from a `SchemaDefinition` by its name. It returns a pointer to the `EntityDefinition` if it is found in the `SchemaDefinition`. If the `EntityDefinition` is not found, it returns an error with error code `ERROR_CODE_ENTITY_DEFINITION_NOT_FOUND`.

func GetPermissionByNameInEntityDefinition added in v0.3.9

func GetPermissionByNameInEntityDefinition(entityDefinition *base.EntityDefinition, name string) (permissionDefinition *base.PermissionDefinition, err error)

GetPermissionByNameInEntityDefinition retrieves an `PermissionDefinition` from an `EntityDefinition` by its name. It returns a pointer to the `PermissionDefinition` if it is found in the `EntityDefinition`. If the `PermissionDefinition` is not found, it returns an error with error code `ERROR_CODE_ACTION_DEFINITION_NOT_FOUND`.

func GetRelationByNameInEntityDefinition

func GetRelationByNameInEntityDefinition(entityDefinition *base.EntityDefinition, name string) (relationDefinition *base.RelationDefinition, err error)

GetRelationByNameInEntityDefinition retrieves a `RelationDefinition` from an `EntityDefinition` by its name. It returns a pointer to the `RelationDefinition` if it is found in the `EntityDefinition`. If the `RelationDefinition` is not found, it returns an error with error code `ERROR_CODE_RELATION_DEFINITION_NOT_FOUND`.

func GetRuleByName added in v0.5.0

func GetRuleByName(schema *base.SchemaDefinition, name string) (ruleDefinition *base.RuleDefinition, err error)

GetRuleByName retrieves the rule definition from the given schema by its name. It takes a pointer to a base.SchemaDefinition and the name of the rule to look for. If the rule with the specified name is found in the schema's RuleDefinitions map, it returns the rule definition and a nil error. If the rule is not found, it returns nil for the rule definition and an error indicating that the entity definition was not found.

func GetTypeOfReferenceByNameInEntityDefinition added in v0.5.0

func GetTypeOfReferenceByNameInEntityDefinition(entityDefinition *base.EntityDefinition, name string) (relationalDefinitionType base.EntityDefinition_Reference, err error)

GetTypeOfReferenceByNameInEntityDefinition retrieves the type of reference in an `EntityDefinition` by its name. It returns the type of the relational reference if it is found in the `EntityDefinition`. If the relational reference is not found, it returns an error with error code `ERROR_CODE_RELATION_DEFINITION_NOT_FOUND`.

func IsDirectlyRelated added in v0.3.5

func IsDirectlyRelated(target *base.RelationDefinition, source *base.Entrance) bool

IsDirectlyRelated checks if a source `RelationReference` is directly related to a target `RelationDefinition`. It returns true if the source and target have the same type and relation, false otherwise.

func NewEntityAndRuleDefinitionsFromStringDefinitions added in v0.5.0

func NewEntityAndRuleDefinitionsFromStringDefinitions(validation bool, definitions ...string) ([]*base.EntityDefinition, []*base.RuleDefinition, error)

func NewSchemaFromEntityAndRuleDefinitions added in v0.5.0

func NewSchemaFromEntityAndRuleDefinitions(entities []*base.EntityDefinition, rules []*base.RuleDefinition) *base.SchemaDefinition

NewSchemaFromEntityAndRuleDefinitions creates a new base.SchemaDefinition from entity and rule definitions. It takes two slices of pointers to base.EntityDefinition and base.RuleDefinition, representing the entities and rules to include in the schema. It returns a pointer to the created base.SchemaDefinition.

func NewSchemaFromStringDefinitions

func NewSchemaFromStringDefinitions(validation bool, definitions ...string) (*base.SchemaDefinition, error)

NewSchemaFromStringDefinitions creates a new `SchemaDefinition` from a list of string definitions. The `validation` argument determines whether to validate the input definitions before creating the schema. If the validation is successful, it returns a pointer to the newly created `SchemaDefinition`. If there's an error during validation or creating the schema, it returns an error.

Types

type LinkedEntrance added in v0.3.5

type LinkedEntrance struct {
	Kind             LinkedEntranceKind
	TargetEntrance   *base.Entrance
	TupleSetRelation string
}

LinkedEntrance represents an entry point into the LinkedSchemaGraph, which is used to resolve permissions and expand user sets for a given request. The object contains a kind that specifies the type of entry point (e.g. relation, tuple-to-user-set), an entry point reference that identifies the specific entry point in the graph, and a tuple set relation reference that specifies the relation to use when expanding user sets for the entry point.

Fields:

  • Kind: LinkedEntranceKind representing the type of entry point
  • LinkedEntrance: pointer to a base.RelationReference that identifies the entry point in the schema graph
  • TupleSetRelation: pointer to a base.RelationReference that specifies the relation to use when expanding user sets for the entry point

func (LinkedEntrance) LinkedEntranceKind added in v0.3.5

func (re LinkedEntrance) LinkedEntranceKind() LinkedEntranceKind

LinkedEntranceKind returns the kind of the LinkedEntrance object. The kind specifies the type of entry point (e.g. relation, tuple-to-user-set, computed user set).

Returns:

  • LinkedEntranceKind representing the type of entry point

type LinkedEntranceKind added in v0.3.5

type LinkedEntranceKind string

LinkedEntranceKind is a string type that represents the kind of LinkedEntrance object. An LinkedEntrance object defines an entry point into the LinkedSchemaGraph, which is used to resolve permissions and expand user sets for a given request.

Values:

  • RelationLinkedEntrance: represents an entry point into a relationship object in the schema graph
  • TupleToUserSetLinkedEntrance: represents an entry point into a tuple-to-user-set object in the schema graph
  • ComputedUserSetLinkedEntrance: represents an entry point into a computed user set object in the schema graph
const (
	RelationLinkedEntrance        LinkedEntranceKind = "relation"
	TupleToUserSetLinkedEntrance  LinkedEntranceKind = "tuple_to_user_set"
	ComputedUserSetLinkedEntrance LinkedEntranceKind = "computed_user_set"
	AttributeLinkedEntrance       LinkedEntranceKind = "attribute"
)

type LinkedSchemaGraph added in v0.3.5

type LinkedSchemaGraph struct {
	// contains filtered or unexported fields
}

LinkedSchemaGraph represents a graph of linked schema objects. The schema object contains definitions for entities, relationships, and permissions, and the graph is constructed by linking objects together based on their dependencies. The graph is used by the PermissionEngine to resolve permissions and expand user sets for a given request.

Fields:

  • schema: pointer to the base.SchemaDefinition that defines the schema objects in the graph

func NewLinkedGraph added in v0.3.5

func NewLinkedGraph(schema *base.SchemaDefinition) *LinkedSchemaGraph

NewLinkedGraph returns a new instance of LinkedSchemaGraph with the specified base.SchemaDefinition as its schema. The schema object contains definitions for entities, relationships, and permissions, and is used to construct a graph of linked schema objects. The graph is used by the PermissionEngine to resolve permissions and expand user sets for a given request.

Parameters:

  • schema: pointer to the base.SchemaDefinition that defines the schema objects in the graph

Returns:

  • pointer to a new instance of LinkedSchemaGraph with the specified schema object

func (*LinkedSchemaGraph) LinkedEntrances added in v1.1.0

func (g *LinkedSchemaGraph) LinkedEntrances(target, source *base.Entrance) ([]*LinkedEntrance, error)

RelationshipLinkedEntrances returns a slice of LinkedEntrance objects that represent entry points into the LinkedSchemaGraph for the specified target and source relations. The function recursively searches the graph for all entry points that can be reached from the target relation through the specified source relation. The resulting entry points contain a reference to the relation object in the schema graph and the relation used to expand user sets for the entry point. If the target or source relation does not exist in the schema graph, the function returns an error.

Parameters:

  • target: pointer to a base.RelationReference that identifies the target relation
  • source: pointer to a base.RelationReference that identifies the source relation used to reach the target relation

Returns:

  • slice of LinkedEntrance objects that represent entry points into the LinkedSchemaGraph, or an error if the target or source relation does not exist in the schema graph

type Walker added in v0.5.0

type Walker struct {
	// contains filtered or unexported fields
}

Walker is a struct used for traversing a schema

func NewWalker added in v0.5.0

func NewWalker(schema *base.SchemaDefinition) *Walker

NewWalker is a constructor for the Walker struct

func (*Walker) Walk added in v0.5.0

func (w *Walker) Walk(
	entityType string,
	permission string,
) error

Walk traverses the schema based on entity type and permission

func (*Walker) WalkComputedUserSet added in v1.0.1

func (w *Walker) WalkComputedUserSet(
	entityType string,
	cu *base.ComputedUserSet,
) error

WalkComputedUserSet walk the relation within the ComputedUserSet for the given entityType.

func (*Walker) WalkLeaf added in v0.5.0

func (w *Walker) WalkLeaf(
	entityType string,
	leaf *base.Leaf,
) error

WalkLeaf is a method that walks through the leaf part of the schema

func (*Walker) WalkRewrite added in v0.5.0

func (w *Walker) WalkRewrite(
	entityType string,
	rewrite *base.Rewrite,
) error

WalkRewrite is a method that walks through the rewrite part of the schema

Jump to

Keyboard shortcuts

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