Nullify DreamDaemonController

This commit is contained in:
Jordan Dominion
2023-12-20 14:09:56 -05:00
parent 523b3aa86e
commit 62d5dcb7cc
2 changed files with 25 additions and 21 deletions
@@ -25,8 +25,6 @@ using Tgstation.Server.Host.Utils;
#pragma warning disable API1001 // Action method returns a success result without a corresponding ProducesResponseType. Somehow this happens ONLY IN THIS CONTROLLER???
#nullable disable
namespace Tgstation.Server.Host.Controllers
{
/// <summary>
@@ -174,7 +172,7 @@ namespace Tgstation.Server.Host.Controllers
if (current == default)
return this.Gone();
if (model.Port.HasValue && model.Port.Value != current.Port.Value)
if (model.Port.HasValue && model.Port.Value != current.Port!.Value)
{
var verifiedPort = await portAllocator
.GetAvailablePort(
@@ -203,14 +201,15 @@ namespace Tgstation.Server.Host.Controllers
return false;
}
var ddRights = InstancePermissionSet.DreamDaemonRights!.Value;
if (CheckModified(x => x.AllowWebClient, DreamDaemonRights.SetWebClient)
|| CheckModified(x => x.AutoStart, DreamDaemonRights.SetAutoStart)
|| CheckModified(x => x.Port, DreamDaemonRights.SetPort)
|| CheckModified(x => x.SecurityLevel, DreamDaemonRights.SetSecurity)
|| CheckModified(x => x.Visibility, DreamDaemonRights.SetVisibility)
|| (model.SoftRestart.HasValue && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.SoftRestart))
|| (model.SoftShutdown.HasValue && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.SoftShutdown))
|| (!String.IsNullOrWhiteSpace(model.BroadcastMessage) && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.BroadcastMessage))
|| (model.SoftRestart.HasValue && !ddRights.HasFlag(DreamDaemonRights.SoftRestart))
|| (model.SoftShutdown.HasValue && !ddRights.HasFlag(DreamDaemonRights.SoftShutdown))
|| (!String.IsNullOrWhiteSpace(model.BroadcastMessage) && !ddRights.HasFlag(DreamDaemonRights.BroadcastMessage))
|| CheckModified(x => x.StartupTimeout, DreamDaemonRights.SetStartupTimeout)
|| CheckModified(x => x.HealthCheckSeconds, DreamDaemonRights.SetHealthCheckInterval)
|| CheckModified(x => x.DumpOnHealthCheckRestart, DreamDaemonRights.CreateDump)
@@ -310,7 +309,7 @@ namespace Tgstation.Server.Host.Controllers
/// <param name="knownForcedReboot">If there was a settings change made that forced a switch to <see cref="RebootState.Restart"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="IActionResult"/> of the operation.</returns>
ValueTask<IActionResult> ReadImpl(DreamDaemonSettings settings, bool knownForcedReboot, CancellationToken cancellationToken)
ValueTask<IActionResult> ReadImpl(DreamDaemonSettings? settings, bool knownForcedReboot, CancellationToken cancellationToken)
=> WithComponentInstance(async instance =>
{
var dd = instance.Watchdog;
@@ -324,7 +323,7 @@ namespace Tgstation.Server.Host.Controllers
.Instances
.AsQueryable()
.Where(x => x.Id == Instance.Id)
.Select(x => x.DreamDaemonSettings)
.Select(x => x.DreamDaemonSettings!)
.FirstOrDefaultAsync(cancellationToken);
if (settings == default)
return this.Gone();
@@ -336,13 +335,13 @@ namespace Tgstation.Server.Host.Controllers
var alphaActive = dd.AlphaIsActive;
var llp = dd.LastLaunchParameters;
var rstate = dd.RebootState;
result.AutoStart = settings.AutoStart.Value;
result.CurrentPort = llp?.Port.Value;
result.CurrentSecurity = llp?.SecurityLevel.Value;
result.CurrentVisibility = llp?.Visibility.Value;
result.CurrentAllowWebclient = llp?.AllowWebClient.Value;
result.Port = settings.Port.Value;
result.AllowWebClient = settings.AllowWebClient.Value;
result.AutoStart = settings.AutoStart!.Value;
result.CurrentPort = llp?.Port!.Value;
result.CurrentSecurity = llp?.SecurityLevel!.Value;
result.CurrentVisibility = llp?.Visibility!.Value;
result.CurrentAllowWebclient = llp?.AllowWebClient!.Value;
result.Port = settings.Port!.Value;
result.AllowWebClient = settings.AllowWebClient!.Value;
var firstIteration = true;
do
@@ -359,18 +358,18 @@ namespace Tgstation.Server.Host.Controllers
}
while (result.Status == WatchdogStatus.Online && !result.SessionId.HasValue); // this is the one invalid combo, it's not that racy
result.SecurityLevel = settings.SecurityLevel.Value;
result.Visibility = settings.Visibility.Value;
result.SecurityLevel = settings.SecurityLevel!.Value;
result.Visibility = settings.Visibility!.Value;
result.SoftRestart = rstate == RebootState.Restart;
result.SoftShutdown = rstate == RebootState.Shutdown;
if (rstate == RebootState.Normal && knownForcedReboot)
result.SoftRestart = true;
result.StartupTimeout = settings.StartupTimeout.Value;
result.HealthCheckSeconds = settings.HealthCheckSeconds.Value;
result.DumpOnHealthCheckRestart = settings.DumpOnHealthCheckRestart.Value;
result.TopicRequestTimeout = settings.TopicRequestTimeout.Value;
result.StartupTimeout = settings.StartupTimeout!.Value;
result.HealthCheckSeconds = settings.HealthCheckSeconds!.Value;
result.DumpOnHealthCheckRestart = settings.DumpOnHealthCheckRestart!.Value;
result.TopicRequestTimeout = settings.TopicRequestTimeout!.Value;
result.AdditionalParameters = settings.AdditionalParameters;
result.StartProfiler = settings.StartProfiler;
result.LogOutput = settings.LogOutput;
@@ -19,6 +19,11 @@ namespace Tgstation.Server.Host.Controllers
/// </summary>
protected new Models.Instance Instance => base.Instance!;
/// <summary>
/// The <see cref="Models.InstancePermissionSet"/> for the request.
/// </summary>
protected Models.InstancePermissionSet InstancePermissionSet => AuthenticationContext.InstancePermissionSet!;
/// <summary>
/// Initializes a new instance of the <see cref="InstanceRequiredController"/> class.
/// </summary>