From 6c240e21b41b6199f3c6beffe217239eb76a44fa Mon Sep 17 00:00:00 2001 From: Vikram Rangnekar Date: Fri, 6 Mar 2020 15:38:54 +0530 Subject: [PATCH] Fix bug related to 'anon' role prepared statements --- psql/query.go | 6 +++++- serv/core_build.go | 3 ++- serv/prepare.go | 4 ++++ serv/reload.go | 6 +++++- tmpl/prod.yml | 6 +++++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/psql/query.go b/psql/query.go index 90df1eb..ed01627 100644 --- a/psql/query.go +++ b/psql/query.go @@ -17,6 +17,10 @@ const ( closeBlock = 500 ) +var ( + ErrAllTablesSkipped = errors.New("all tables skipped. cannot render query") +) + type Variables map[string]json.RawMessage type Config struct { @@ -107,7 +111,7 @@ func (co *Compiler) compileQuery(qc *qcode.QCode, w io.Writer, vars Variables) ( io.WriteString(c.w, `) as "__root" FROM `) if i == 0 { - return 0, errors.New("all tables skipped. cannot render query") + return 0, ErrAllTablesSkipped } var ignored uint32 diff --git a/serv/core_build.go b/serv/core_build.go index dd090f5..1efd622 100644 --- a/serv/core_build.go +++ b/serv/core_build.go @@ -90,7 +90,7 @@ func buildMultiStmt(gql, vars []byte) ([]stmt, error) { } if len(conf.RolesQuery) == 0 { - return buildRoleStmt(gql, vars, "user") + return nil, errors.New("roles_query not defined") } stmts := make([]stmt, 0, len(conf.Roles)) @@ -99,6 +99,7 @@ func buildMultiStmt(gql, vars []byte) ([]stmt, error) { for i := 0; i < len(conf.Roles); i++ { role := &conf.Roles[i] + // skip anon as it's not included in the combined multi-statement if role.Name == "anon" { continue } diff --git a/serv/prepare.go b/serv/prepare.go index 3f04e1d..1681ac8 100644 --- a/serv/prepare.go +++ b/serv/prepare.go @@ -7,6 +7,7 @@ import ( "io" "github.com/dosco/super-graph/allow" + "github.com/dosco/super-graph/psql" "github.com/dosco/super-graph/qcode" "github.com/jackc/pgconn" "github.com/jackc/pgx/v4" @@ -120,6 +121,9 @@ func prepareStmt(item allow.Item) error { logger.Debug().Msg("Prepared statement for role: anon") stmts2, err := buildRoleStmt(q, vars, "anon") + if err == psql.ErrAllTablesSkipped { + return nil + } if err != nil { return err } diff --git a/serv/reload.go b/serv/reload.go index 05a027b..ef1c8dd 100644 --- a/serv/reload.go +++ b/serv/reload.go @@ -108,7 +108,11 @@ func Do(log func(string, ...interface{}), additional ...dir) error { // Ensure that we use the correct events, as they are not uniform across // platforms. See https://github.com/fsnotify/fsnotify/issues/74 - if conf != nil && !conf.Production && strings.HasSuffix(event.Name, "/allow.list") { + if conf != nil && strings.HasSuffix(event.Name, "/allow.list") { + continue + } + + if conf.Production { continue } diff --git a/tmpl/prod.yml b/tmpl/prod.yml index ca1ea41..63a8360 100644 --- a/tmpl/prod.yml +++ b/tmpl/prod.yml @@ -24,7 +24,11 @@ auth_fail_block: true # Latency tracing for database queries and remote joins # the resulting latency information is returned with the # response -enable_tracing: true +enable_tracing: false + +# Watch the config folder and reload Super Graph +# with the new configs when a change is detected +reload_on_config_change: false # File that points to the database seeding script # seed_file: seed.js