BREAKING CHANGE: super-graph/core now defaults to allow all in anon role

This commit is contained in:
Vikram Rangnekar
2020-05-28 00:07:01 -04:00
parent 2241364d00
commit 1fb7f0e6c8
15 changed files with 465 additions and 291 deletions

View File

@ -55,19 +55,6 @@ func TestSuperGraph(t *testing.T, db *sql.DB, before func(t *testing.T)) {
config.AllowListFile = "./allow.list"
config.RolesQuery = `SELECT * FROM users WHERE id = $user_id`
blockFalse := false
config.Roles = []core.Role{
core.Role{
Name: "anon",
Tables: []core.RoleTable{
core.RoleTable{Name: "users", ReadOnly: &blockFalse, Query: core.Query{Limit: 100}},
core.RoleTable{Name: "product", ReadOnly: &blockFalse, Query: core.Query{Limit: 100}},
core.RoleTable{Name: "line_item", ReadOnly: &blockFalse, Query: core.Query{Limit: 100}},
},
},
}
sg, err := core.NewSuperGraph(&config, db)
require.NoError(t, err)
ctx := context.Background()

View File

@ -6,7 +6,8 @@ import (
)
type Config struct {
Blocklist []string
DefaultBlock bool
Blocklist []string
}
type QueryConfig struct {

View File

@ -172,6 +172,8 @@ const (
type Compiler struct {
tr map[string]map[string]*trval
bl map[string]struct{}
defBlock bool
}
var expPool = sync.Pool{
@ -179,7 +181,7 @@ var expPool = sync.Pool{
}
func NewCompiler(c Config) (*Compiler, error) {
co := &Compiler{}
co := &Compiler{defBlock: c.DefaultBlock}
co.tr = make(map[string]map[string]*trval)
co.bl = make(map[string]struct{}, len(c.Blocklist))
@ -358,7 +360,7 @@ func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error {
}
} else if role == "anon" {
skipRender = true
skipRender = com.defBlock
}
selects = append(selects, Select{