mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Update framework forwarding logic to handle nil system views (#8114)
This commit is contained in:
@@ -228,16 +228,18 @@ func (b *Backend) HandleRequest(ctx context.Context, req *logical.Request) (*log
|
|||||||
if op, ok := path.Operations[req.Operation]; ok {
|
if op, ok := path.Operations[req.Operation]; ok {
|
||||||
|
|
||||||
// Check whether this operation should be forwarded
|
// Check whether this operation should be forwarded
|
||||||
replState := b.System().ReplicationState()
|
if sysView := b.System(); sysView != nil {
|
||||||
|
replState := sysView.ReplicationState()
|
||||||
props := op.Properties()
|
props := op.Properties()
|
||||||
|
|
||||||
if props.ForwardPerformanceStandby && replState.HasState(consts.ReplicationPerformanceStandby) {
|
if props.ForwardPerformanceStandby && replState.HasState(consts.ReplicationPerformanceStandby) {
|
||||||
return nil, logical.ErrReadOnly
|
return nil, logical.ErrReadOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
if props.ForwardPerformanceSecondary && !b.System().LocalMount() && replState.HasState(consts.ReplicationPerformanceSecondary) {
|
if props.ForwardPerformanceSecondary && !sysView.LocalMount() && replState.HasState(consts.ReplicationPerformanceSecondary) {
|
||||||
return nil, logical.ErrReadOnly
|
return nil, logical.ErrReadOnly
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
callback = op.Handler()
|
callback = op.Handler()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ func TestBackendHandleRequest_Forwarding(t *testing.T) {
|
|||||||
isStandby bool
|
isStandby bool
|
||||||
isSecondary bool
|
isSecondary bool
|
||||||
expectFwd bool
|
expectFwd bool
|
||||||
|
nilSysView bool
|
||||||
}{
|
}{
|
||||||
"no forward": {
|
"no forward": {
|
||||||
expectFwd: false,
|
expectFwd: false,
|
||||||
@@ -159,6 +160,10 @@ func TestBackendHandleRequest_Forwarding(t *testing.T) {
|
|||||||
isSecondary: true,
|
isSecondary: true,
|
||||||
expectFwd: false,
|
expectFwd: false,
|
||||||
},
|
},
|
||||||
|
"nil system view": {
|
||||||
|
nilSysView: true,
|
||||||
|
expectFwd: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, test := range tests {
|
for name, test := range tests {
|
||||||
@@ -193,6 +198,10 @@ func TestBackendHandleRequest_Forwarding(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if test.nilSysView {
|
||||||
|
b.system = nil
|
||||||
|
}
|
||||||
|
|
||||||
_, err := b.HandleRequest(context.Background(), &logical.Request{
|
_, err := b.HandleRequest(context.Background(), &logical.Request{
|
||||||
Operation: logical.ReadOperation,
|
Operation: logical.ReadOperation,
|
||||||
Path: "foo",
|
Path: "foo",
|
||||||
|
|||||||
6
vendor/github.com/hashicorp/vault/sdk/framework/backend.go
generated
vendored
6
vendor/github.com/hashicorp/vault/sdk/framework/backend.go
generated
vendored
@@ -228,16 +228,18 @@ func (b *Backend) HandleRequest(ctx context.Context, req *logical.Request) (*log
|
|||||||
if op, ok := path.Operations[req.Operation]; ok {
|
if op, ok := path.Operations[req.Operation]; ok {
|
||||||
|
|
||||||
// Check whether this operation should be forwarded
|
// Check whether this operation should be forwarded
|
||||||
replState := b.System().ReplicationState()
|
if sysView := b.System(); sysView != nil {
|
||||||
|
replState := sysView.ReplicationState()
|
||||||
props := op.Properties()
|
props := op.Properties()
|
||||||
|
|
||||||
if props.ForwardPerformanceStandby && replState.HasState(consts.ReplicationPerformanceStandby) {
|
if props.ForwardPerformanceStandby && replState.HasState(consts.ReplicationPerformanceStandby) {
|
||||||
return nil, logical.ErrReadOnly
|
return nil, logical.ErrReadOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
if props.ForwardPerformanceSecondary && !b.System().LocalMount() && replState.HasState(consts.ReplicationPerformanceSecondary) {
|
if props.ForwardPerformanceSecondary && !sysView.LocalMount() && replState.HasState(consts.ReplicationPerformanceSecondary) {
|
||||||
return nil, logical.ErrReadOnly
|
return nil, logical.ErrReadOnly
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
callback = op.Handler()
|
callback = op.Handler()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user