Ensure query variables are consistent
All request variables which are assigned to an sql query are now specified in one location, ensuring that they are consistent and always present for all queries.
This commit is contained in:
parent
ad4adbd986
commit
b4a8f10cdc
4 changed files with 27 additions and 62 deletions
|
@ -31,12 +31,12 @@ type Auth struct {
|
|||
// Reset resets the authentication data.
|
||||
func (a *Auth) Reset() *Auth {
|
||||
|
||||
// Remove any saved session data
|
||||
a.Data = nil
|
||||
|
||||
// Reset the authentication level
|
||||
a.Kind = AuthNO
|
||||
|
||||
// Remove any saved session data
|
||||
a.Data = nil
|
||||
|
||||
// Clear any authenticated scope
|
||||
a.Scope = ""
|
||||
|
||||
|
|
59
db/db.go
59
db/db.go
|
@ -106,41 +106,6 @@ func Execute(fib *fibre.Context, txt interface{}, vars map[string]interface{}) (
|
|||
fib = fib.WithContext(nctx)
|
||||
defer span.Finish()
|
||||
|
||||
// If no preset variables have been defined
|
||||
// then ensure that the variables is
|
||||
// instantiated for future use.
|
||||
|
||||
if vars == nil {
|
||||
vars = make(map[string]interface{})
|
||||
}
|
||||
|
||||
// Ensure that we have a unique id assigned
|
||||
// to this fibre connection, as we need it
|
||||
// to detect unique websocket notifications.
|
||||
|
||||
if fib.Get(ctxKeyId) == nil {
|
||||
fib.Set(ctxKeyId, uuid.New().String())
|
||||
}
|
||||
|
||||
// Ensure that the IP address of the
|
||||
// user signing in is available so that
|
||||
// it can be used within signin queries.
|
||||
|
||||
vars[varKeyIp] = fib.IP().String()
|
||||
|
||||
// Ensure that the website origin of the
|
||||
// user signing in is available so that
|
||||
// it can be used within signin queries.
|
||||
|
||||
vars[varKeyOrigin] = fib.Origin()
|
||||
|
||||
// Ensure that the current authentication data
|
||||
// is made available as a runtime variable to
|
||||
// the query layer.
|
||||
|
||||
vars[varKeyAuth] = fib.Get(varKeyAuth).(*cnf.Auth).Data
|
||||
vars[varKeyScope] = fib.Get(varKeyAuth).(*cnf.Auth).Scope
|
||||
|
||||
// Parse the received SQL batch query strings
|
||||
// into SQL ASTs, using any immutable preset
|
||||
// variables if set.
|
||||
|
@ -183,6 +148,30 @@ func Process(fib *fibre.Context, ast *sql.Query, vars map[string]interface{}) (o
|
|||
fib.Set(ctxKeyId, uuid.New().String())
|
||||
}
|
||||
|
||||
// Ensure that the IP address of the
|
||||
// user signing in is available so that
|
||||
// it can be used within signin queries.
|
||||
|
||||
vars[varKeyIp] = fib.IP().String()
|
||||
|
||||
// Ensure that the website origin of the
|
||||
// user signing in is available so that
|
||||
// it can be used within signin queries.
|
||||
|
||||
vars[varKeyOrigin] = fib.Origin()
|
||||
|
||||
// Ensure that the current authentication
|
||||
// data is made available as a runtime
|
||||
// variable to the query layer.
|
||||
|
||||
vars[varKeyAuth] = fib.Get(varKeyAuth).(*cnf.Auth).Data
|
||||
|
||||
// Ensure that the current authentication
|
||||
// scope is made available as a runtime
|
||||
// variable to the query layer.
|
||||
|
||||
vars[varKeyScope] = fib.Get(varKeyAuth).(*cnf.Auth).Scope
|
||||
|
||||
// Create a new context so that we can quit
|
||||
// all goroutine workers if the http client
|
||||
// itself is closed before finishing.
|
||||
|
|
|
@ -69,18 +69,6 @@ func signinInternal(c *fibre.Context, vars map[string]interface{}) (str string,
|
|||
d, dok := vars[varKeyDb].(string)
|
||||
s, sok := vars[varKeySc].(string)
|
||||
|
||||
// Ensure that the IP address of the
|
||||
// user signing in is available so that
|
||||
// it can be used within signin queries.
|
||||
|
||||
vars[varKeyIp] = c.IP().String()
|
||||
|
||||
// Ensure that the website origin of the
|
||||
// user signing in is available so that
|
||||
// it can be used within signin queries.
|
||||
|
||||
vars[varKeyOrigin] = c.Origin()
|
||||
|
||||
// If we have a namespace, database, and
|
||||
// scope defined, then we are logging in
|
||||
// to the scope level.
|
||||
|
|
|
@ -68,18 +68,6 @@ func signupInternal(c *fibre.Context, vars map[string]interface{}) (str string,
|
|||
d, dok := vars[varKeyDb].(string)
|
||||
s, sok := vars[varKeySc].(string)
|
||||
|
||||
// Ensure that the IP address of the
|
||||
// user signing up is available so that
|
||||
// it can be used within signup queries.
|
||||
|
||||
vars[varKeyIp] = c.IP().String()
|
||||
|
||||
// Ensure that the website origin of the
|
||||
// user signing up is available so that
|
||||
// it can be used within signup queries.
|
||||
|
||||
vars[varKeyOrigin] = c.Origin()
|
||||
|
||||
// If we have a namespace, database, and
|
||||
// scope defined, then we are logging in
|
||||
// to the scope level.
|
||||
|
|
Loading…
Reference in a new issue