diff --git a/docs/API.dox b/docs/API.dox index 759c73ff56..c05ca4243d 100644 --- a/docs/API.dox +++ b/docs/API.dox @@ -24,7 +24,6 @@ Last off, if anything in this API doesn't seem to hold true when tested against 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. - The first letter of every field name will/must be lowercase in JSON models -- Fields in the C# model marked with "DenyWrite = true" cannot be changed using POST requests - Fields marked 'Required' should be ignored, this is a semantic for the backing SQL database - Id fields must be specified when making POST requests - All other fields are optional and may be absent from responses or requests unless otherwise specified @@ -37,7 +36,7 @@ TGS4 expects this set of headers. Failure to provide them may result in 400 erro - Accept: application/json - Api: Another product header value representing the version of the API to use. Currently this must be: Tgstation.Server.Api/4.0.0.0 -For POST and PUT requests you must also include the content type. Currently only json is supported +For POST, PATCH, and PUT requests you must also include the content type. Currently only json is supported - Content-Type: application/json @@ -448,7 +447,11 @@ 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 restart the watchdog use the following request: + +I PATCH "/DreamDaemon" Empty => @ref Tgstation.Server.Api.Models.Job + +The returned jobs represents the startup process for the watchdog To stop the watchdog use the following request: diff --git a/src/Tgstation.Server.Client/ApiClient.cs b/src/Tgstation.Server.Client/ApiClient.cs index 66a2609031..8107fc1913 100644 --- a/src/Tgstation.Server.Client/ApiClient.cs +++ b/src/Tgstation.Server.Client/ApiClient.cs @@ -216,6 +216,9 @@ namespace Tgstation.Server.Client /// public Task Create(string route, long instanceId, CancellationToken cancellationToken) => RunRequest(route, new object(), HttpMethod.Put, instanceId, cancellationToken); + /// + public Task Patch(string route, long instanceId, CancellationToken cancellationToken) => RunRequest(route, new object(), new HttpMethod("PATCH"), instanceId, cancellationToken); + /// public void AddRequestLogger(IRequestLogger requestLogger) => requestLoggers.Add(requestLogger ?? throw new ArgumentNullException(nameof(requestLogger))); } diff --git a/src/Tgstation.Server.Client/Components/DreamDaemonClient.cs b/src/Tgstation.Server.Client/Components/DreamDaemonClient.cs index 10f72d0ffe..e077ea142d 100644 --- a/src/Tgstation.Server.Client/Components/DreamDaemonClient.cs +++ b/src/Tgstation.Server.Client/Components/DreamDaemonClient.cs @@ -35,6 +35,9 @@ namespace Tgstation.Server.Client.Components /// public Task Start(CancellationToken cancellationToken) => apiClient.Create(Routes.DreamDaemon, instance.Id, cancellationToken); + /// + public Task Restart(CancellationToken cancellationToken) => apiClient.Patch(Routes.DreamDaemon, instance.Id, cancellationToken); + /// public Task Read(CancellationToken cancellationToken) => apiClient.Read(Routes.DreamDaemon, instance.Id, cancellationToken); diff --git a/src/Tgstation.Server.Client/Components/IDreamDaemonClient.cs b/src/Tgstation.Server.Client/Components/IDreamDaemonClient.cs index 764ddfbc23..7b858cba6b 100644 --- a/src/Tgstation.Server.Client/Components/IDreamDaemonClient.cs +++ b/src/Tgstation.Server.Client/Components/IDreamDaemonClient.cs @@ -20,9 +20,16 @@ namespace Tgstation.Server.Client.Components /// Start /// /// The for the operation - /// A resulting in the information + /// A resulting in the of the running operation Task Start(CancellationToken cancellationToken); + /// + /// Restart + /// + /// The for the operation + /// A resulting in the of the running operation + Task Restart(CancellationToken cancellationToken); + /// /// Shutdown /// diff --git a/src/Tgstation.Server.Client/IApiClient.cs b/src/Tgstation.Server.Client/IApiClient.cs index 82b1298122..48c7d93234 100644 --- a/src/Tgstation.Server.Client/IApiClient.cs +++ b/src/Tgstation.Server.Client/IApiClient.cs @@ -32,6 +32,7 @@ namespace Tgstation.Server.Client Task Create(string route, TBody body, long instanceId, CancellationToken cancellationToken); Task Create(string route, long instanceId, CancellationToken cancellationToken); + Task Patch(string route, long instanceId, CancellationToken cancellationToken); Task Read(string route, long instanceId, CancellationToken cancellationToken); Task Update(string route, TBody body, long instanceId, CancellationToken cancellationToken); Task Delete(string route, long instanceId, CancellationToken cancellationToken); diff --git a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj index 054656e7df..6bb5253884 100644 --- a/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj +++ b/src/Tgstation.Server.Client/Tgstation.Server.Client.csproj @@ -3,7 +3,7 @@ netstandard2.0 Full - 4.0.0.0-preview9108 + 4.0.0.0-preview9109 true Cyberboss /tg/station 13 diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 5d06822f1f..34d8158a05 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -209,5 +209,29 @@ namespace Tgstation.Server.Host.Controllers return await ReadImpl(current, cancellationToken).ConfigureAwait(false); } + + /// + /// Handle a HTTP PATCH to the + /// + /// The for the operation + /// A resulting in the of the request + [HttpPatch] + [TgsAuthorize(DreamDaemonRights.Restart)] + public async Task Restart(CancellationToken cancellationToken) + { + var job = new Models.Job + { + Instance = Instance, + CancelRightsType = RightsType.DreamDaemon, + CancelRight = (ulong)DreamDaemonRights.Shutdown, + StartedBy = AuthenticationContext.User, + Description = "Restart Watchdog" + }; + + var watchdog = instanceManager.GetInstance(Instance).Watchdog; + + await jobManager.RegisterOperation(job, (paramJob, serviceProvider, progressReporter, ct) => watchdog.Restart(false, ct), cancellationToken).ConfigureAwait(false); + return Accepted(job.ToApi()); + } } }