rel

package
v0.0.0-...-d9f17b9 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidResource is a catch-all error when a resource is invalid.
	ErrInvalidResource = errors.New("invalid resource")

	// ErrInvalidRelation is a catch-all error when a relation is invalid.
	ErrInvalidRelation = errors.New("invalid relation")

	// ErrInvalidSubject is a catch-all error when a subject is invalid.
	ErrInvalidSubject = errors.New("invalid subject")
)

Functions

This section is empty.

Types

type Filter

type Filter struct {
	V1Filter *v1.RelationshipFilter
}

Filter represents a filter to match against relationships.

func NewFilter

func NewFilter(resourceType, optionalID, optionalRelation string) *Filter

NewFilter creates a Filter used to match against the Resource of relationships.

Filters must provide a Resource Type, but empty string can be used to forego any filtering on the Resource ID or Relation.

func (*Filter) WithSubjectFilter

func (f *Filter) WithSubjectFilter(subjectType, optionalID, optionalRelation string)

WithSubjectFilter modifies a Filter to also include matching against the Subject of relationships.

type Func

type Func func(r *Relationship) error

type Interface

type Interface interface{ Relationship() Relationship }

type Object

type Object struct {
	Typ      string
	ID       string
	Relation string
}

func (Object) Object

func (o Object) Object() Object

type Objecter

type Objecter interface{ Object() Object }

type PreconditionedFilter

type PreconditionedFilter struct {
	V1Filter   *v1.RelationshipFilter
	V1Preconds []*v1.Precondition
}

PreconditionedFilter represents a filter used to match or not match against relationships used as a precondition to performing another action.

func NewPreconditionedFilter

func NewPreconditionedFilter(f *Filter) *PreconditionedFilter

NewPreconditionedFilter creates a PreconditionedFilter from an existing Filter that will only apply an action if all the preconditions are met.

func (*PreconditionedFilter) MustMatch

func (pf *PreconditionedFilter) MustMatch(f *Filter)

MustMatch modifies a PreconditionedFilter to only apply if the provided precondition is met.

func (*PreconditionedFilter) MustNotMatch

func (pf *PreconditionedFilter) MustNotMatch(f *Filter)

MustNotMatch modifies a PreconditionedFilter to only apply if the provided precondition is not met.

type Relationship

type Relationship struct {
	ResourceType     string
	ResourceID       string
	ResourceRelation string
	SubjectType      string
	SubjectID        string
	SubjectRelation  string
	CaveatName       string
	CaveatContext    map[string]any
}

func FromObjects

func FromObjects(resource, subject Objecter) Relationship

func FromTriple

func FromTriple(resource, relation, subject string) (Relationship, error)

func FromTuple

func FromTuple(resource, subject string) (Relationship, error)

func FromV1Proto

func FromV1Proto(r *v1.Relationship) *Relationship

func MustFromTriple

func MustFromTriple(resource, relation, subject string) Relationship

func MustFromTuple

func MustFromTuple(resource, subject string) Relationship

func (Relationship) Caveat

func (r Relationship) Caveat() (name string, context map[string]any, exists bool)

func (Relationship) Filter

func (r Relationship) Filter() *Filter

func (Relationship) HasCaveat

func (r Relationship) HasCaveat() bool

func (Relationship) MustV1ProtoCaveat

func (r Relationship) MustV1ProtoCaveat() *v1.ContextualizedCaveat

func (Relationship) Permission

func (r Relationship) Permission() string

func (Relationship) Relationship

func (r Relationship) Relationship() Relationship

func (Relationship) WithCaveat

func (r Relationship) WithCaveat(name string, context map[string]any) Relationship
Example
package main

import (
	"fmt"

	"github.com/jzelinskie/gochugaru/rel"
)

func main() {
	fmt.Println(rel.
		MustFromTriple("document:example", "viewer", "user:jzelinskie").
		WithCaveat("only_on_tuesday", map[string]any{"day_of_the_week": "wednesday"}),
	)
}
Output:

{document example viewer user jzelinskie  only_on_tuesday map[day_of_the_week:wednesday]}

type Txn

type Txn struct {
	V1Updates  []*v1.RelationshipUpdate
	V1Preconds []*v1.Precondition
}

Txn represents an atomic modification with option preconditions.

func (*Txn) Create

func (b *Txn) Create(r Relationship)

Create inserts a new relationship and fails if the relationship already exists.

func (*Txn) Delete

func (b *Txn) Delete(r Relationship)

Delete removes a relationship.

func (*Txn) MustMatch

func (b *Txn) MustMatch(f *Filter)

MustMatch modifies a transaction to only apply if the provided precondition is met.

func (*Txn) MustNotMatch

func (b *Txn) MustNotMatch(f *Filter)

MustNotMatch modifies a transaction to only apply if the provided precondition is not met.

func (*Txn) Touch

func (b *Txn) Touch(r Relationship)

Touch idempotently creates or updates a relationship.

The performance of this operation can vary based on the SpiceDB datastore.

type UpdateFunc

type UpdateFunc func(typ UpdateType, r *Relationship) error

type UpdateType

type UpdateType int
const (
	UpdateUnknown UpdateType = iota
	UpdateCreate
	UpdateDelete
	UpdateTouch
)

Jump to

Keyboard shortcuts

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