Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement definition requests #2121

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
definition user {}

definition resource {
relation viewer: user
permission view = viewer
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .user import user

definition resource {
relation viewer: user
permission view = viewer
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
definition user {}

// This shouldn't be present in the output
definition persona {}

// Nor should this
caveat only_on_tuesday(day_of_week string) {
day_of_week == 'tuesday'
}
1 change: 1 addition & 0 deletions pkg/composableschemadsl/compiler/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/authzed/spicedb/pkg/composableschemadsl/compiler"

Check failure on line 12 in pkg/composableschemadsl/compiler/importer_test.go

View workflow job for this annotation

GitHub Actions / Lint Go

could not import github.com/authzed/spicedb/pkg/composableschemadsl/compiler (-: # github.com/authzed/spicedb/pkg/composableschemadsl/compiler [github.com/authzed/spicedb/pkg/composableschemadsl/compiler.test]
"github.com/authzed/spicedb/pkg/composableschemadsl/generator"
"github.com/authzed/spicedb/pkg/composableschemadsl/input"
)
Expand Down Expand Up @@ -55,6 +55,7 @@
importerTests := []importerTest{
{"simple local import", "simple-local"},
{"simple local import with transitive hop", "simple-local-with-hop"},
{"simple local import with extra def", "simple-local-with-extra-def"},
{"nested local import", "nested-local"},
{"nested local import with transitive hop", "nested-local-with-hop"},
{"nested local two layers deep import", "nested-two-layer-local"},
Expand Down
19 changes: 15 additions & 4 deletions pkg/composableschemadsl/compiler/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,10 @@
}

func translateImport(tctx translationContext, importNode *dslNode, names *mapz.Set[string]) (*CompiledSchema, error) {
// NOTE: this function currently just grabs everything that's in the target file.
// TODO: only grab the requested definitions
// TODO: import cycle tracking
// Get the filepath segments out of the AST nodes
pathNodes := importNode.List(dslshape.NodeImportPredicatePathSegment)
pathSegments := make([]string, 0, len(pathNodes))

// Get the filepath segments out of the AST nodes
for _, pathSegmentNode := range pathNodes {
segment, err := pathSegmentNode.GetString(dslshape.NodeIdentiferPredicateValue)
if err != nil {
Expand All @@ -709,9 +706,23 @@
pathSegments = append(pathSegments, segment)
}

// Get requested definitions out of the AST nodes
requestedDefinitionNodes := importNode.List(dslshape.NodeImportPredicateDefinitionName)
requestedDefinitions := make([]string, 0, len(requestedDefinitionNodes))

for _, requestedDefinitionNode := range requestedDefinitionNodes {
requested, err := requestedDefinitionNode.GetString(dslshape.NodeIdentiferPredicateValue)
if err != nil {
return nil, err
}
requestedDefinitions = append(requestedDefinitions, requested)
}


return importFile(importContext{
names: names,
pathSegments: pathSegments,

Check failure on line 724 in pkg/composableschemadsl/compiler/translator.go

View workflow job for this annotation

GitHub Actions / Lint Go

unknown field requestedDefinitions in struct literal of type importContext

Check failure on line 724 in pkg/composableschemadsl/compiler/translator.go

View workflow job for this annotation

GitHub Actions / Lint Go

unknown field requestedDefinitions in struct literal of type importContext

Check failure on line 724 in pkg/composableschemadsl/compiler/translator.go

View workflow job for this annotation

GitHub Actions / Lint Go

unknown field requestedDefinitions in struct literal of type importContext

Check failure on line 724 in pkg/composableschemadsl/compiler/translator.go

View workflow job for this annotation

GitHub Actions / Lint Go

unknown field requestedDefinitions in struct literal of type importContext (typecheck)

Check failure on line 724 in pkg/composableschemadsl/compiler/translator.go

View workflow job for this annotation

GitHub Actions / Lint Go

unknown field requestedDefinitions in struct literal of type importContext) (typecheck)

Check failure on line 724 in pkg/composableschemadsl/compiler/translator.go

View workflow job for this annotation

GitHub Actions / Lint Go

unknown field requestedDefinitions in struct literal of type importContext) (typecheck)
requestedDefinitions: requestedDefinitions,

Check failure on line 725 in pkg/composableschemadsl/compiler/translator.go

View workflow job for this annotation

GitHub Actions / Unit

unknown field requestedDefinitions in struct literal of type importContext
sourceFolder: tctx.sourceFolder,
})
}
Loading