Documentation
¶
Index ¶
- Variables
- type Filter
- type Func
- type Interface
- type Object
- type Objecter
- type PreconditionedFilter
- type Relationship
- func FromObjects(resource, subject Objecter) Relationship
- func FromTriple(resource, relation, subject string) (Relationship, error)
- func FromTuple(resource, subject string) (Relationship, error)
- func FromV1Proto(r *v1.Relationship) *Relationship
- func MustFromTriple(resource, relation, subject string) Relationship
- func MustFromTuple(resource, subject string) Relationship
- func (r Relationship) Caveat() (name string, context map[string]any, exists bool)
- func (r Relationship) Filter() *Filter
- func (r Relationship) HasCaveat() bool
- func (r Relationship) MustV1ProtoCaveat() *v1.ContextualizedCaveat
- func (r Relationship) Permission() string
- func (r Relationship) Relationship() Relationship
- func (r Relationship) WithCaveat(name string, context map[string]any) Relationship
- type Txn
- type UpdateFunc
- type UpdateType
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 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) MustMatch ¶
MustMatch modifies a transaction to only apply if the provided precondition is met.
func (*Txn) MustNotMatch ¶
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 )