core: add generic request forwarding bits to oss (#6866)
This commit is contained in:
parent
e2e5e16ff2
commit
08e17cc111
|
@ -72,6 +72,7 @@ type SystemView interface {
|
|||
|
||||
type ExtendedSystemView interface {
|
||||
Auditor() Auditor
|
||||
ForwardGenericRequest(context.Context, *Request) (*Response, error)
|
||||
}
|
||||
|
||||
type StaticSystemView struct {
|
||||
|
|
|
@ -16,6 +16,12 @@ import (
|
|||
"github.com/hashicorp/vault/sdk/version"
|
||||
)
|
||||
|
||||
type ctxKeyForwardedRequestMountAccessor struct{}
|
||||
|
||||
func (c ctxKeyForwardedRequestMountAccessor) String() string {
|
||||
return "forwarded-req-mount-accessor"
|
||||
}
|
||||
|
||||
type dynamicSystemView struct {
|
||||
core *Core
|
||||
mountEntry *MountEntry
|
||||
|
@ -33,6 +39,17 @@ func (e extendedSystemView) Auditor() logical.Auditor {
|
|||
}
|
||||
}
|
||||
|
||||
func (e extendedSystemView) ForwardGenericRequest(ctx context.Context, req *logical.Request) (*logical.Response, error) {
|
||||
// Forward the request if allowed
|
||||
if couldForward(e.core) {
|
||||
ctx = namespace.ContextWithNamespace(ctx, e.mountEntry.Namespace())
|
||||
ctx = context.WithValue(ctx, ctxKeyForwardedRequestMountAccessor{}, e.mountEntry.Accessor)
|
||||
return forward(ctx, e.core, req)
|
||||
}
|
||||
|
||||
return nil, logical.ErrReadOnly
|
||||
}
|
||||
|
||||
func (d dynamicSystemView) DefaultLeaseTTL() time.Duration {
|
||||
def, _ := d.fetchTTLs()
|
||||
return def
|
||||
|
|
Loading…
Reference in New Issue