From 52487ce7f5c905361b2ae20d5a8d727397ed5332 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 20 Aug 2018 17:56:30 -0400 Subject: [PATCH 1/2] 201 for created instance, 200 for attached instance --- docs/API.dox | 2 ++ .../Controllers/InstanceController.cs | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/API.dox b/docs/API.dox index 4d5c8a51fc..5361caf7db 100644 --- a/docs/API.dox +++ b/docs/API.dox @@ -186,6 +186,8 @@ Instances are DreamDaemon server configurations, they live in their own director PUT "/Instance" @ref Tgstation.Server.Api.Models.Instance => @ref Tgstation.Server.Api.Models.Instance +This normally returns 201 BUT, in the case of attaching an existing instance, 200 will instead be returned + The user that creates an instance will be given full @ref Tgstation.Server.Api.Models.InstanceUser permission. The path must not exist at the time of creation. Support for attaching instances from backups is yet to come. A specific Instance may be retrieved with: diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index a417dbe86c..d9dbae9001 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -111,9 +111,12 @@ namespace Tgstation.Server.Host.Controllers NormalizeModelPath(model, out var rawPath); var dirExistsTask = ioManager.DirectoryExists(model.Path, cancellationToken); + bool attached = false; if (await ioManager.FileExists(model.Path, cancellationToken).ConfigureAwait(false) || await dirExistsTask.ConfigureAwait(false)) - if(!await ioManager.FileExists(ioManager.ConcatPath(model.Path, InstanceAttachFileName), cancellationToken).ConfigureAwait(false)) + if (!await ioManager.FileExists(ioManager.ConcatPath(model.Path, InstanceAttachFileName), cancellationToken).ConfigureAwait(false)) return Conflict(new ErrorMessage { Message = "Path not empty!" }); + else + attached = true; var newInstance = new Models.Instance { @@ -181,9 +184,10 @@ namespace Tgstation.Server.Host.Controllers return Conflict(new ErrorMessage{ Message = e.Message }); } - Logger.LogInformation("{0} created instance {1}: {2}", AuthenticationContext.User.Name, newInstance.Name, newInstance.Id); - - return StatusCode((int)HttpStatusCode.Created, newInstance.ToApi()); + Logger.LogInformation("{0} {1} instance {2}: {3} ({4})", AuthenticationContext.User.Name, attached ? "attached" : "created", newInstance.Name, newInstance.Id, newInstance.Path); + + var api = newInstance.ToApi(); + return attached ? (IActionResult)Json(api) : StatusCode((int)HttpStatusCode.Created, api); } /// From 59b5dd3c49656f365303ccdacdcb26edf3e813a6 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 20 Aug 2018 18:47:37 -0400 Subject: [PATCH 2/2] Fix custom chat commands --- src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs index bec6c74822..ee7dc6e07c 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs @@ -866,7 +866,7 @@ namespace Tgstation.Server.Host.Components.Watchdog User = sender }; - var json = JsonConvert.SerializeObject(arguments, new JsonSerializerSettings + var json = JsonConvert.SerializeObject(commandObject, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });