mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-07-14 09:33:22 +01:00
Various things:
Remove rights => int conversions Clean up DreamDaemonController Watchdog API docs
This commit is contained in:
+25
-1
@@ -17,6 +17,8 @@ The TGS4 API's canonical definitions are provided as a .NET Standard library in
|
||||
|
||||
An all inclusive TAP interface for using the API is also provided in this package: https://www.nuget.org/packages/Tgstation.Server.Client
|
||||
|
||||
Last off, if anything in this API doesn't seem to hold true when tested against the server, please open an issue on the repository.
|
||||
|
||||
@subsection api_interp Interpreting C# Models
|
||||
|
||||
This document will reference the canonical C# models in the @ref Tgstation.Server.Api.Models namespace. Note that these models are built to mirror the JSON requests and responses with a couple caveats.
|
||||
@@ -404,4 +406,26 @@ When creating a file, only @ref Tgstation.Server.Api.Models.ConfigurationFile.Pa
|
||||
|
||||
If the file already exists, the @ref Tgstation.Server.Api.Models.ConfigurationFile.LastReadHash field must also be present with the last version recieved from the server for that file. If this does not match at the time of the request, 409 will be returned, indicating the file has changed since it was last viewed by the client.
|
||||
|
||||
To delete a file set @ref Tgstation.Server.Api.Models.ConfigurationFile.Content to null in the request. If deleting a file leaves a directory empty, they too will be deleted.
|
||||
To delete a file set @ref Tgstation.Server.Api.Models.ConfigurationFile.Content to null in the request. If deleting a file leaves a directory empty, they too will be deleted.
|
||||
|
||||
@subsection api_dog Watchdog
|
||||
|
||||
To read watchdog status use the following request:
|
||||
|
||||
I GET "/DreamDaemon" => @ref Tgstation.Server.Api.Models.DreamDaemon
|
||||
|
||||
To update watchdog settings use the following request:
|
||||
|
||||
I POST "/DreamDaemon" => @ref Tgstation.Server.Api.Models.DreamDaemon
|
||||
|
||||
Note that soft restart/shutdown operations cannot be cancelled via this method, they can be changed from one to another however.
|
||||
|
||||
To start the watchdog use the following request:
|
||||
|
||||
I PUT "/DreamDaemon" Empty => @ref Tgstation.Server.Api.Models.Job
|
||||
|
||||
The returned job represents the startup process for the watchdog
|
||||
|
||||
To stop the watchdog use the following request:
|
||||
|
||||
I DELETE "/DreamDaemon" => OK
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
Description = String.Format(CultureInfo.InvariantCulture, "Install BYOND version {0}", installingVersion),
|
||||
StartedBy = AuthenticationContext.User,
|
||||
CancelRightsType = RightsType.Byond,
|
||||
CancelRight = (int)ByondRights.CancelInstall,
|
||||
CancelRight = (ulong)ByondRights.CancelInstall,
|
||||
Instance = Instance
|
||||
};
|
||||
await jobManager.RegisterOperation(job, (paramJob, serviceProvicer, progressHandler, ct) => byondManager.ChangeVersion(installingVersion, ct), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
var results = await query.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatBots) & (int)ChatBotRights.ReadConnectionString) != 0;
|
||||
var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatBots) & (ulong)ChatBotRights.ReadConnectionString) != 0;
|
||||
|
||||
if (!connectionStrings)
|
||||
foreach (var I in results)
|
||||
@@ -172,7 +172,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
if (results == default)
|
||||
return NotFound();
|
||||
|
||||
var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatBots) & (int)ChatBotRights.ReadConnectionString) != 0;
|
||||
var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatBots) & (ulong)ChatBotRights.ReadConnectionString) != 0;
|
||||
|
||||
if (!connectionStrings)
|
||||
results.ConnectionString = null;
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
var job = new Models.Job
|
||||
{
|
||||
Description = "Launch DreamDaemon",
|
||||
CancelRight = (int)DreamDaemonRights.Shutdown,
|
||||
CancelRight = (ulong)DreamDaemonRights.Shutdown,
|
||||
CancelRightsType = RightsType.DreamDaemon,
|
||||
Instance = Instance,
|
||||
StartedBy = AuthenticationContext.User
|
||||
@@ -72,8 +72,6 @@ namespace Tgstation.Server.Host.Controllers
|
||||
var result = await instance.Watchdog.Launch(innerCt).ConfigureAwait(false);
|
||||
if (result == null)
|
||||
throw new InvalidOperationException("Watchdog already running!");
|
||||
if (!instance.Watchdog.Running)
|
||||
throw new Exception("Failed to launch watchdog!");
|
||||
},
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
return Json(job);
|
||||
@@ -81,20 +79,30 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
/// <inheritdoc />
|
||||
[TgsAuthorize(DreamDaemonRights.ReadMetadata | DreamDaemonRights.ReadRevision)]
|
||||
public override async Task<IActionResult> Read(CancellationToken cancellationToken)
|
||||
{
|
||||
public override Task<IActionResult> Read(CancellationToken cancellationToken) => ReadImpl(null, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of <see cref="Read(CancellationToken)"/>
|
||||
/// </summary>
|
||||
/// <param name="settings">The <see cref="DreamDaemonSettings"/> to operate on if any</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="IActionResult"/> of the operation</returns>
|
||||
async Task<IActionResult> ReadImpl(DreamDaemonSettings settings, CancellationToken cancellationToken)
|
||||
{
|
||||
var instance = instanceManager.GetInstance(Instance);
|
||||
var dd = instance.Watchdog;
|
||||
|
||||
var metadata = (AuthenticationContext.GetRight(RightsType.DreamDaemon) & (int)DreamDaemonRights.ReadMetadata) != 0;
|
||||
var revision = (AuthenticationContext.GetRight(RightsType.DreamDaemon) & (int)DreamDaemonRights.ReadRevision) != 0;
|
||||
var metadata = (AuthenticationContext.GetRight(RightsType.DreamDaemon) & (ulong)DreamDaemonRights.ReadMetadata) != 0;
|
||||
var revision = (AuthenticationContext.GetRight(RightsType.DreamDaemon) & (ulong)DreamDaemonRights.ReadRevision) != 0;
|
||||
|
||||
var settings = await DatabaseContext.Instances.Where(x => x.Id == Instance.Id).Select(x => x.DreamDaemonSettings).FirstAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (settings == null)
|
||||
settings = await DatabaseContext.Instances.Where(x => x.Id == Instance.Id).Select(x => x.DreamDaemonSettings).FirstAsync(cancellationToken).ConfigureAwait(false);
|
||||
var result = new DreamDaemon();
|
||||
if(metadata)
|
||||
{
|
||||
var alphaActive = dd.AlphaIsActive;
|
||||
var llp = dd.LastLaunchParameters;
|
||||
var rstate = dd.RebootState;
|
||||
result.AutoStart = settings.AutoStart;
|
||||
result.CurrentPort = alphaActive ? llp.PrimaryPort : llp.SecondaryPort;
|
||||
result.CurrentSecurity = llp.SecurityLevel;
|
||||
@@ -102,9 +110,8 @@ namespace Tgstation.Server.Host.Controllers
|
||||
result.PrimaryPort = dd.ActiveLaunchParameters.PrimaryPort;
|
||||
result.AllowWebClient = dd.ActiveLaunchParameters.AllowWebClient;
|
||||
result.Running = dd.Running;
|
||||
result.SecondaryPort = dd.LastLaunchParameters.SecondaryPort;
|
||||
result.SecurityLevel = dd.LastLaunchParameters.SecurityLevel;
|
||||
var rstate = dd.RebootState;
|
||||
result.SecondaryPort = llp.SecondaryPort;
|
||||
result.SecurityLevel = llp.SecurityLevel;
|
||||
result.SoftRestart = rstate == RebootState.Restart;
|
||||
result.SoftShutdown = rstate == RebootState.Shutdown;
|
||||
};
|
||||
@@ -126,10 +133,6 @@ namespace Tgstation.Server.Host.Controllers
|
||||
{
|
||||
//alias for stopping DD
|
||||
var instance = instanceManager.GetInstance(Instance);
|
||||
|
||||
if (!instance.Watchdog.Running)
|
||||
return StatusCode((int)HttpStatusCode.Gone);
|
||||
|
||||
await instance.Watchdog.Terminate(false, cancellationToken).ConfigureAwait(false);
|
||||
return Ok();
|
||||
}
|
||||
@@ -178,21 +181,18 @@ namespace Tgstation.Server.Host.Controllers
|
||||
return BadRequest(new ErrorMessage { Message = "TGS does not support the ultrasafe DreamDaemon configuration!" });
|
||||
|
||||
var wd = instanceManager.GetInstance(Instance).Watchdog;
|
||||
|
||||
var changeSettingsTask = wd.ChangeSettings(current, cancellationToken);
|
||||
|
||||
//run these in parallel because they are equally as important
|
||||
await Task.WhenAll(DatabaseContext.Save(cancellationToken), wd.ChangeSettings(current, cancellationToken)).ConfigureAwait(false);
|
||||
|
||||
//soft shutdown/restart can't be cancelled because of how many things rely on them
|
||||
//They can be alternated though
|
||||
if (!oldSoftRestart.Value && current.SoftRestart.Value)
|
||||
await Task.WhenAll(changeSettingsTask, wd.Restart(true, cancellationToken)).ConfigureAwait(false);
|
||||
await wd.Restart(true, cancellationToken).ConfigureAwait(false);
|
||||
else if (!oldSoftShutdown.Value && current.SoftShutdown.Value)
|
||||
await Task.WhenAll(changeSettingsTask, wd.Terminate(true, cancellationToken)).ConfigureAwait(false);
|
||||
else
|
||||
await changeSettingsTask.ConfigureAwait(false);
|
||||
await wd.Terminate(true, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
await DatabaseContext.Save(default).ConfigureAwait(false);
|
||||
|
||||
return Ok();
|
||||
return await ReadImpl(current, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
Description = "Compile active repository code",
|
||||
StartedBy = AuthenticationContext.User,
|
||||
CancelRightsType = RightsType.DreamMaker,
|
||||
CancelRight = (int)DreamMakerRights.CancelCompile,
|
||||
CancelRight = (ulong)DreamMakerRights.CancelCompile,
|
||||
Instance = Instance
|
||||
};
|
||||
await jobManager.RegisterOperation(job, (paramJob, serviceProvider, progressReporter, ct) => RunCompile(paramJob, serviceProvider, Instance, ct), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
Description = String.Format(CultureInfo.InvariantCulture, "Move instance ID {0} from {1} to {2}", Instance.Id, Instance.Path, rawPath),
|
||||
Instance = Instance,
|
||||
CancelRightsType = RightsType.InstanceManager,
|
||||
CancelRight = (int)InstanceManagerRights.CancelMove,
|
||||
CancelRight = (ulong)InstanceManagerRights.CancelMove,
|
||||
StartedBy = AuthenticationContext.User
|
||||
};
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
Description = String.Format(CultureInfo.InvariantCulture, "Clone branch {1} of repository {0}", origin, cloneBranch ?? "master"),
|
||||
StartedBy = AuthenticationContext.User,
|
||||
CancelRightsType = RightsType.Repository,
|
||||
CancelRight = (int)RepositoryRights.CancelClone,
|
||||
CancelRight = (ulong)RepositoryRights.CancelClone,
|
||||
Instance = Instance
|
||||
};
|
||||
var api = currentModel.ToApi();
|
||||
@@ -307,7 +307,7 @@ namespace Tgstation.Server.Host.Controllers
|
||||
StartedBy = AuthenticationContext.User,
|
||||
Instance = Instance,
|
||||
CancelRightsType = RightsType.Repository,
|
||||
CancelRight = (int)RepositoryRights.CancelPendingChanges,
|
||||
CancelRight = (ulong)RepositoryRights.CancelPendingChanges,
|
||||
};
|
||||
|
||||
await jobManager.RegisterOperation(job, async (paramJob, serviceProvider, progressReporter, ct) =>
|
||||
|
||||
Reference in New Issue
Block a user