Skip to content

Commit

Permalink
issue-2732: correct allowlist and enums
Browse files Browse the repository at this point in the history
  • Loading branch information
vladstepanyuk committed Jan 13, 2025
1 parent 6dcd139 commit 72b9a6e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,13 @@ void TDiskRegistryActor::HandleHttpInfo_ChangeAgentState(
return;
}

static const THashSet<NProto::EAgentState> 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);
Expand All @@ -216,17 +215,17 @@ void TDiskRegistryActor::HandleHttpInfo_ChangeAgentState(
return;
}

static const THashSet<NProto::EAgentState> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,37 +199,32 @@ void TDiskRegistryActor::HandleHttpInfo_ChangeDeviseState(
return;
}

static const THashSet<NProto::EDeviceState> 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<NProto::EDeviceState> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void BuildChangeDeviceStateButton(
<input type='hidden' name='TabletID' value='%lu'/>
</form>)",
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);
}
Expand All @@ -147,8 +147,8 @@ void BuildChangeAgentStateButton(
<input type='hidden' name='TabletID' value='%lu'/>
</form>)",
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);
}
Expand Down

0 comments on commit 72b9a6e

Please sign in to comment.