Remove connection wide variables
This commit is contained in:
parent
0615896c0e
commit
c8980e2eac
7 changed files with 29 additions and 47 deletions
7
db/db.go
7
db/db.go
|
@ -203,13 +203,6 @@ func Process(fib *fibre.Context, ast *sql.Query, vars map[string]interface{}) (o
|
|||
|
||||
ctx = context.WithValue(ctx, ctxKeyId, id)
|
||||
|
||||
// Assign any global connection variables
|
||||
// to the context so that we can retrieve
|
||||
// the variables from within any queries.
|
||||
|
||||
keep := fib.Get(varKeyKeep)
|
||||
ctx = context.WithValue(ctx, ctxKeyKeep, keep)
|
||||
|
||||
// Assign the authentication data to the
|
||||
// context so that we can log the auth kind
|
||||
// and the auth variable data to the request.
|
||||
|
|
|
@ -117,7 +117,6 @@ func (e *executor) execute(ctx context.Context, ast *sql.Query) {
|
|||
"id": ctx.Value(ctxKeyId),
|
||||
"kind": ctx.Value(ctxKeyKind),
|
||||
"vars": ctx.Value(ctxKeyVars),
|
||||
"keep": ctx.Value(ctxKeyKeep),
|
||||
})
|
||||
|
||||
if stm, ok := stm.(sql.AuthableStatement); ok {
|
||||
|
|
|
@ -61,9 +61,6 @@ func (s *socket) ctx(ns, db string) (ctx context.Context) {
|
|||
ctx = context.WithValue(ctx, ctxKeyNs, ns)
|
||||
ctx = context.WithValue(ctx, ctxKeyDb, db)
|
||||
|
||||
keep := s.fibre.Get(ctxKeyKeep)
|
||||
ctx = context.WithValue(ctx, ctxKeyKeep, keep)
|
||||
|
||||
auth := s.fibre.Get(ctxKeyAuth).(*cnf.Auth)
|
||||
ctx = context.WithValue(ctx, ctxKeyAuth, auth.Data)
|
||||
ctx = context.WithValue(ctx, ctxKeyKind, auth.Kind)
|
||||
|
|
|
@ -49,7 +49,6 @@ const (
|
|||
ctxKeyVars = "vars"
|
||||
ctxKeySubs = "subs"
|
||||
ctxKeySpec = "spec"
|
||||
ctxKeyKeep = "keep"
|
||||
ctxKeyAuth = "auth"
|
||||
ctxKeyKind = "kind"
|
||||
ctxKeyScope = "scope"
|
||||
|
@ -62,7 +61,6 @@ const (
|
|||
varKeyIp = "ip"
|
||||
varKeyEnv = "ENV"
|
||||
varKeyAuth = "auth"
|
||||
varKeyKeep = "keep"
|
||||
varKeyThis = "this"
|
||||
varKeyScope = "scope"
|
||||
varKeyValue = "value"
|
||||
|
@ -108,5 +106,5 @@ var (
|
|||
|
||||
// paramSearchKeys specifies the order in which context
|
||||
// variables should be checked for any specified value.
|
||||
paramSearchKeys = []string{ctxKeySpec, ctxKeySubs, ctxKeyVars, ctxKeyKeep}
|
||||
paramSearchKeys = []string{ctxKeySpec, ctxKeySubs, ctxKeyVars}
|
||||
)
|
||||
|
|
25
web/auth.go
25
web/auth.go
|
@ -31,30 +31,12 @@ import (
|
|||
"github.com/abcum/surreal/sql"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"github.com/abcum/surreal/util/data"
|
||||
)
|
||||
|
||||
var ignore = func() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
varKeyIp = "ip"
|
||||
varKeyNs = "NS"
|
||||
varKeyDb = "DB"
|
||||
varKeySc = "SC"
|
||||
varKeyTk = "TK"
|
||||
varKeyUs = "US"
|
||||
varKeyTb = "TB"
|
||||
varKeyId = "ID"
|
||||
varKeyAuth = "auth"
|
||||
varKeyKeep = "keep"
|
||||
varKeyUser = "user"
|
||||
varKeyPass = "pass"
|
||||
varKeyOrigin = "origin"
|
||||
)
|
||||
|
||||
func cidr(ip net.IP, networks []*net.IPNet) bool {
|
||||
for _, network := range networks {
|
||||
if network.Contains(ip) {
|
||||
|
@ -68,13 +50,6 @@ func auth() fibre.MiddlewareFunc {
|
|||
return func(h fibre.HandlerFunc) fibre.HandlerFunc {
|
||||
return func(c *fibre.Context) (err error) {
|
||||
|
||||
// Initialise any session level variables
|
||||
// which will be valid across all requests
|
||||
// which are made over this connection.
|
||||
|
||||
vars := new(data.Doc)
|
||||
c.Set(varKeyKeep, vars)
|
||||
|
||||
// Initialise the connection authentication
|
||||
// information which will store whether the
|
||||
// connection has authenticated or not.
|
||||
|
|
|
@ -19,8 +19,6 @@ import (
|
|||
"github.com/abcum/surreal/cnf"
|
||||
"github.com/abcum/surreal/db"
|
||||
"github.com/abcum/surreal/sql"
|
||||
"github.com/abcum/surreal/util/data"
|
||||
"github.com/abcum/surreal/util/rand"
|
||||
)
|
||||
|
||||
type rpc struct{}
|
||||
|
@ -29,8 +27,6 @@ type rpc struct{}
|
|||
// Methods for authentication
|
||||
// --------------------------------------------------
|
||||
|
||||
func (r *rpc) Uniq(c *fibre.Context) (interface{}, error) {
|
||||
return rand.String(64), nil
|
||||
func (r *rpc) Ping(c *fibre.Context) (interface{}, error) {
|
||||
return "OK", nil
|
||||
}
|
||||
|
@ -75,10 +71,6 @@ func (r *rpc) Live(c *fibre.Context, class string) (interface{}, error) {
|
|||
// Methods for static queries
|
||||
// --------------------------------------------------
|
||||
|
||||
func (r *rpc) Let(c *fibre.Context, key string, val interface{}) (interface{}, error) {
|
||||
return c.Get("keep").(*data.Doc).Set(val, key)
|
||||
}
|
||||
|
||||
func (r *rpc) Query(c *fibre.Context, sql string, vars map[string]interface{}) (interface{}, error) {
|
||||
return db.Execute(c, sql, vars)
|
||||
}
|
||||
|
|
28
web/vars.go
Normal file
28
web/vars.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright © 2016 Abcum Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package web
|
||||
|
||||
const (
|
||||
varKeyNs = "NS"
|
||||
varKeyDb = "DB"
|
||||
varKeySc = "SC"
|
||||
varKeyTk = "TK"
|
||||
varKeyUs = "US"
|
||||
varKeyTb = "TB"
|
||||
varKeyId = "ID"
|
||||
varKeyAuth = "auth"
|
||||
varKeyUser = "user"
|
||||
varKeyPass = "pass"
|
||||
)
|
Loading…
Reference in a new issue