Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions pkg/schema/schemalog/definition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package schemalog

import (
"iter"

corev1 "github.com/authzed/spicedb/pkg/proto/core/v1"
)

type Definition struct {
schema *Schema
Proto *corev1.NamespaceDefinition
relations map[string]*Relation
permissions map[string]*Permission
}

var _ Entity = &Definition{}

// Name returns the full name of the Definition
func (d *Definition) Name() string {
return d.Proto.GetName()
}

func (d *Definition) Relations() iter.Seq2[string, *Relation] {
return func(yield func(string, *Relation) bool) {
for k, v := range d.relations {
if !yield(k, v) {
return
}
}
}
}

func (d *Definition) Permissions() iter.Seq2[string, *Permission] {
return func(yield func(string, *Permission) bool) {
for k, v := range d.permissions {
if !yield(k, v) {
return
}
}
}
}

func (d *Definition) Edges() iter.Seq2[string, Edge] {
return func(yield func(string, Edge) bool) {
for k, v := range d.permissions {
if !yield(k, v) {

Check failure on line 46 in pkg/schema/schemalog/definition.go

View workflow job for this annotation

GitHub Actions / Lint Go

cannot use v (variable of type *Permission) as Edge value in argument to yield: *Permission does not implement Edge (missing method ResourceType)

Check failure on line 46 in pkg/schema/schemalog/definition.go

View workflow job for this annotation

GitHub Actions / Unit

cannot use v (variable of type *Permission) as Edge value in argument to yield: *Permission does not implement Edge (missing method ResourceType)
return
}
}
for k, v := range d.relations {
if !yield(k, v) {

Check failure on line 51 in pkg/schema/schemalog/definition.go

View workflow job for this annotation

GitHub Actions / Lint Go

cannot use v (variable of type *Relation) as Edge value in argument to yield: *Relation does not implement Edge (missing method ResourceType)

Check failure on line 51 in pkg/schema/schemalog/definition.go

View workflow job for this annotation

GitHub Actions / Unit

cannot use v (variable of type *Relation) as Edge value in argument to yield: *Relation does not implement Edge (missing method ResourceType)
return
}
}
}
}
39 changes: 39 additions & 0 deletions pkg/schema/schemalog/edges.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package schemalog

type Edge interface {
Entity
Rule
Definition() *Definition
Rules() []Rule
}

var _ Edge = &Relation{}

Check failure on line 10 in pkg/schema/schemalog/edges.go

View workflow job for this annotation

GitHub Actions / Unit

cannot use &Relation{} (value of type *Relation) as Edge value in variable declaration: *Relation does not implement Edge (missing method ResourceType)
var _ Edge = &Permission{}

Check failure on line 11 in pkg/schema/schemalog/edges.go

View workflow job for this annotation

GitHub Actions / Lint Go

cannot use &Relation{} (value of type *Relation) as Edge value in variable declaration: *Relation does not implement Edge (missing method ResourceType)

Check failure on line 11 in pkg/schema/schemalog/edges.go

View workflow job for this annotation

GitHub Actions / Lint Go

cannot use &Relation{} (value of type *Relation) as Edge value in variable declaration: *Relation does not implement Edge (missing method ResourceType)

Check failure on line 11 in pkg/schema/schemalog/edges.go

View workflow job for this annotation

GitHub Actions / Unit

cannot use &Permission{} (value of type *Permission) as Edge value in variable declaration: *Permission does not implement Edge (missing method ResourceType)

Check failure on line 12 in pkg/schema/schemalog/edges.go

View workflow job for this annotation

GitHub Actions / Lint Go

cannot use &Permission{} (value of type *Permission) as Edge value in variable declaration: *Permission does not implement Edge (missing method ResourceType)

Check failure on line 12 in pkg/schema/schemalog/edges.go

View workflow job for this annotation

GitHub Actions / Lint Go

cannot use &Permission{} (value of type *Permission) as Edge value in variable declaration: *Permission does not implement Edge (missing method ResourceType)
type Relation struct {
definition *Definition
name string
body []Rule
}

func (r *Relation) Name() string {
return r.name
}

func (r *Relation) Definition() *Definition {
return r.definition
}

type Permission struct {
definition *Definition
name string
body []Rule
}

func (p *Permission) Name() string {
return p.name
}

func (p *Permission) Definition() *Definition {
return p.definition
}
29 changes: 29 additions & 0 deletions pkg/schema/schemalog/rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package schemalog

type Rule interface {
ResourceType() string
SubjectTypes() []string
}

type TypeRule struct {
Type string
}

type RelationRule struct {
Type string
Relation string
}

type ExpansionRule struct {
EdgeName string
}

type ArrowRule struct {
Type string
EdgeName string
}

type AllRule struct {
Type string
EdgeName string
}
17 changes: 17 additions & 0 deletions pkg/schema/schemalog/schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package schemalog

import corev1 "github.com/authzed/spicedb/pkg/proto/core/v1"

type Schema struct {
definitions map[string]*Definition
edges map[string]Edge
caveats map[string]*Caveat
}

type Caveat struct {
Proto *corev1.CaveatDefinition
}

type Entity interface {
Name() string
}
Loading