From 72b9a6edbc2494aa458f57e62a732954b015dbfa Mon Sep 17 00:00:00 2001 From: Stepanyuk Vladislav Date: Mon, 13 Jan 2025 19:09:14 +0700 Subject: [PATCH] issue-2732: correct allowlist and enums --- ...disk_registry_actor_change_agent_state.cpp | 37 +++++++------- ...isk_registry_actor_change_device_state.cpp | 51 +++++++++---------- .../disk_registry_actor_monitoring.cpp | 8 +-- 3 files changed, 45 insertions(+), 51 deletions(-) diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_change_agent_state.cpp b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_change_agent_state.cpp index 2a779f9242..12d4973698 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_change_agent_state.cpp +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_change_agent_state.cpp @@ -200,14 +200,13 @@ void TDiskRegistryActor::HandleHttpInfo_ChangeAgentState( return; } - static const THashSet NewStateAllowlist{ - NProto::EAgentState::AGENT_STATE_ONLINE, - NProto::EAgentState::AGENT_STATE_WARNING, - }; - - if (!NewStateAllowlist.contains(newState)) { - RejectHttpRequest(ctx, *requestInfo, "Invalid new state"); - return; + switch (newState) { + case NProto::AGENT_STATE_ONLINE: + case NProto::AGENT_STATE_WARNING: + break; + default: + RejectHttpRequest(ctx, *requestInfo, "Invalid new state"); + return; } const auto agentState = State->GetAgentState(agentId); @@ -216,17 +215,17 @@ void TDiskRegistryActor::HandleHttpInfo_ChangeAgentState( return; } - static const THashSet OldStateAllowlist = { - NProto::EAgentState::AGENT_STATE_ONLINE, - NProto::EAgentState::AGENT_STATE_WARNING, - }; - - if (!OldStateAllowlist.contains(*agentState.Get())) { - RejectHttpRequest( - ctx, - *requestInfo, - "Can't change agent state from " + - EAgentState_Name(*agentState.Get())); + switch (newState) { + case NProto::AGENT_STATE_ONLINE: + case NProto::AGENT_STATE_WARNING: + break; + default: + RejectHttpRequest( + ctx, + *requestInfo, + "Can't change agent state from " + + EAgentState_Name(*agentState.Get())); + return; } LOG_INFO( diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_change_device_state.cpp b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_change_device_state.cpp index 8598c3b6ba..f6652f5e1a 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_change_device_state.cpp +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_change_device_state.cpp @@ -199,37 +199,32 @@ void TDiskRegistryActor::HandleHttpInfo_ChangeDeviseState( return; } - static const THashSet NewStateAllowlist = { - NProto::EDeviceState::DEVICE_STATE_ONLINE, - NProto::EDeviceState::DEVICE_STATE_WARNING, - }; - if (!NewStateAllowlist.contains(newState)) { - RejectHttpRequest(ctx, *requestInfo, "Invalid new state"); - return; + switch (newState) { + case NProto::DEVICE_STATE_ONLINE: + case NProto::DEVICE_STATE_WARNING: + break; + default: + RejectHttpRequest(ctx, *requestInfo, "Invalid new state"); + return; } - static const auto OldStateAllowlist = [&]() - { - THashSet allowlist = { - NProto::EDeviceState::DEVICE_STATE_ONLINE, - NProto::EDeviceState::DEVICE_STATE_WARNING, - }; - - if (Config->GetEnableToChangeErrorStatesFromDiskRegistryMonpage()) { - allowlist.emplace(NProto::EDeviceState::DEVICE_STATE_ERROR); - } - - return allowlist; - }(); - const auto& device = State->GetDevice(deviceUUID); - if (!OldStateAllowlist.contains(device.GetState())) { - RejectHttpRequest( - ctx, - *requestInfo, - "Can't change device state from " + - EDeviceState_Name(device.GetState())); - return; + switch (device.GetState()) { + case NProto::DEVICE_STATE_ONLINE: + case NProto::DEVICE_STATE_WARNING: + break; + case NProto::DEVICE_STATE_ERROR: + if (Config->GetEnableToChangeErrorStatesFromDiskRegistryMonpage()) { + break; + } + [[fallthrough]]; + default: + RejectHttpRequest( + ctx, + *requestInfo, + "Can't change device state from " + + EDeviceState_Name(device.GetState())); + return; } LOG_INFO( diff --git a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_monitoring.cpp b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_monitoring.cpp index de21790e46..41cdddc4e3 100644 --- a/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_monitoring.cpp +++ b/cloud/blockstore/libs/storage/disk_registry/disk_registry_actor_monitoring.cpp @@ -122,8 +122,8 @@ void BuildChangeDeviceStateButton( )", deviceUUID.c_str(), - EDeviceState_Name(NProto::EDeviceState::DEVICE_STATE_ONLINE).c_str(), - EDeviceState_Name(NProto::EDeviceState::DEVICE_STATE_WARNING).c_str(), + EDeviceState_Name(NProto::DEVICE_STATE_ONLINE).c_str(), + EDeviceState_Name(NProto::DEVICE_STATE_WARNING).c_str(), deviceUUID.c_str(), tabletId); } @@ -147,8 +147,8 @@ void BuildChangeAgentStateButton( )", agentId.c_str(), - EAgentState_Name(NProto::EAgentState::AGENT_STATE_ONLINE).c_str(), - EAgentState_Name(NProto::EAgentState::AGENT_STATE_WARNING).c_str(), + EAgentState_Name(NProto::AGENT_STATE_ONLINE).c_str(), + EAgentState_Name(NProto::AGENT_STATE_WARNING).c_str(), agentId.c_str(), tabletId); }