mirror of
https://github.com/hashicorp/vault.git
synced 2026-06-08 16:24:51 -04:00
Move some handle request functions up a level (#5889)
* Move some handle request functions up a level Add clearing of token entry from request, fixing a test * Update request_handling.go
This commit is contained in:
parent
6ce32bca48
commit
5bc9dc85b9
1 changed files with 19 additions and 9 deletions
|
|
@ -345,17 +345,16 @@ func (c *Core) checkToken(ctx context.Context, req *logical.Request, unauth bool
|
|||
// HandleRequest is used to handle a new incoming request
|
||||
func (c *Core) HandleRequest(httpCtx context.Context, req *logical.Request) (resp *logical.Response, err error) {
|
||||
c.stateLock.RLock()
|
||||
defer c.stateLock.RUnlock()
|
||||
if c.Sealed() {
|
||||
c.stateLock.RUnlock()
|
||||
return nil, consts.ErrSealed
|
||||
}
|
||||
if c.standby && !c.perfStandby {
|
||||
c.stateLock.RUnlock()
|
||||
return nil, consts.ErrStandby
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(c.activeContext)
|
||||
defer cancel()
|
||||
|
||||
go func(ctx context.Context, httpCtx context.Context) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
|
@ -364,6 +363,23 @@ func (c *Core) HandleRequest(httpCtx context.Context, req *logical.Request) (res
|
|||
}
|
||||
}(ctx, httpCtx)
|
||||
|
||||
ns, err := namespace.FromContext(httpCtx)
|
||||
if err != nil {
|
||||
cancel()
|
||||
c.stateLock.RUnlock()
|
||||
return nil, errwrap.Wrapf("could not parse namespace from http context: {{err}}", err)
|
||||
}
|
||||
ctx = namespace.ContextWithNamespace(ctx, ns)
|
||||
|
||||
resp, err = c.handleCancelableRequest(ctx, ns, req)
|
||||
|
||||
req.SetTokenEntry(nil)
|
||||
cancel()
|
||||
c.stateLock.RUnlock()
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (c *Core) handleCancelableRequest(ctx context.Context, ns *namespace.Namespace, req *logical.Request) (resp *logical.Response, err error) {
|
||||
// Allowing writing to a path ending in / makes it extremely difficult to
|
||||
// understand user intent for the filesystem-like backends (kv,
|
||||
// cubbyhole) -- did they want a key named foo/ or did they want to write
|
||||
|
|
@ -381,12 +397,6 @@ func (c *Core) HandleRequest(httpCtx context.Context, req *logical.Request) (res
|
|||
return nil, err
|
||||
}
|
||||
|
||||
ns, err := namespace.FromContext(httpCtx)
|
||||
if err != nil {
|
||||
return nil, errwrap.Wrapf("could not parse namespace from http context: {{err}}", err)
|
||||
}
|
||||
ctx = namespace.ContextWithNamespace(ctx, ns)
|
||||
|
||||
if !hasNamespaces(c) && ns.Path != "" {
|
||||
return nil, logical.CodedError(403, "namespaces feature not enabled")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue