diff --git a/src/Tgstation.Server.Api/Models/ErrorCode.cs b/src/Tgstation.Server.Api/Models/ErrorCode.cs index 4f579c752e..1347fafed7 100644 --- a/src/Tgstation.Server.Api/Models/ErrorCode.cs +++ b/src/Tgstation.Server.Api/Models/ErrorCode.cs @@ -18,7 +18,7 @@ namespace Tgstation.Server.Api.Models /// /// Indicates an API upgrade was required by the server. /// - [Description("API Mismatch but no current API version provided!")] + [Description("API version mismatch!")] ApiMismatch, /// diff --git a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs index f2b05c7ea8..d11c29ba24 100644 --- a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs +++ b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs @@ -233,12 +233,14 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the for the operation. /// Update has been started successfully. + /// The requested release version could not be found in the target GitHub repository. /// Upgrade operations are unavailable due to the launch configuration of TGS. /// A GitHub rate limit was encountered. /// A GitHub API error occurred. [HttpPost] [TgsAuthorize(AdministrationRights.ChangeVersion)] [ProducesResponseType(typeof(Administration), 202)] + [ProducesResponseType(typeof(ErrorMessage), 410)] [ProducesResponseType(typeof(ErrorMessage), 422)] [ProducesResponseType(typeof(ErrorMessage), 424)] [ProducesResponseType(typeof(ErrorMessage), 429)] diff --git a/src/Tgstation.Server.Host/Controllers/ApiController.cs b/src/Tgstation.Server.Host/Controllers/ApiController.cs index 8c664fe4e0..5cd3865257 100644 --- a/src/Tgstation.Server.Host/Controllers/ApiController.cs +++ b/src/Tgstation.Server.Host/Controllers/ApiController.cs @@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; using Serilog.Context; using System; -using System.Globalization; using System.Linq; using System.Net; using System.Threading.Tasks; @@ -87,7 +86,7 @@ namespace Tgstation.Server.Host.Controllers /// Generic 404 response. /// /// An with . - protected new ObjectResult NotFound() => StatusCode((int)HttpStatusCode.NotFound, new ErrorMessage(ErrorCode.ResourceNeverPresent)); + protected new ObjectResult NotFound() => NotFound(new ErrorMessage(ErrorCode.ResourceNeverPresent)); /// /// Generic 501 response. @@ -190,14 +189,9 @@ namespace Tgstation.Server.Host.Controllers { if (ApiHeaders != null) Logger.LogDebug( - "Starting API Request: Version: {1}. User-Agent: {2}", - AuthenticationContext?.User.Id.Value.ToString(CultureInfo.InvariantCulture), + "Starting API Request: Version: {0}. User-Agent: {1}", ApiHeaders.ApiVersion.Semver(), - ApiHeaders.RawUserAgent, - Request.Method, - Request.Path, - Request.QueryString, - ApiHeaders.InstanceId); + ApiHeaders.RawUserAgent); await base.OnActionExecutionAsync(context, next).ConfigureAwait(false); } } diff --git a/src/Tgstation.Server.Host/Controllers/ChatController.cs b/src/Tgstation.Server.Host/Controllers/ChatController.cs index 236b4de0a0..772083a05c 100644 --- a/src/Tgstation.Server.Host/Controllers/ChatController.cs +++ b/src/Tgstation.Server.Host/Controllers/ChatController.cs @@ -188,9 +188,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the for the operation. /// Retrieved successfully. + /// The with the given ID does not exist in this instance. [HttpGet("{id}")] [TgsAuthorize(ChatBotRights.Read)] [ProducesResponseType(typeof(Api.Models.ChatBot), 200)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task GetId(long id, CancellationToken cancellationToken) { var query = DatabaseContext.ChatBots @@ -216,11 +218,14 @@ namespace Tgstation.Server.Host.Controllers /// The update to apply. /// The for the operation. /// A resulting in the for the operation. - /// Update applied successfully. may or may not be returned based on user permissions. + /// Update applied successfully. + /// Update applied successfully. not returned based on user permissions. + /// The with the given ID does not exist in this instance. [HttpPost] [TgsAuthorize(ChatBotRights.WriteChannels | ChatBotRights.WriteConnectionString | ChatBotRights.WriteEnabled | ChatBotRights.WriteName | ChatBotRights.WriteProvider)] - [ProducesResponseType(200)] [ProducesResponseType(typeof(Api.Models.ChatBot), 200)] + [ProducesResponseType(204)] + [ProducesResponseType(typeof(ErrorMessage), 410)] #pragma warning disable CA1502, CA1506 // TODO: Decomplexify public async Task Update([FromBody] Api.Models.ChatBot model, CancellationToken cancellationToken) #pragma warning restore CA1502, CA1506 @@ -314,7 +319,7 @@ namespace Tgstation.Server.Host.Controllers return Json(current.ToApi()); } - return Ok(); + return NoContent(); } /// diff --git a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs index e012365a9d..4cebfdbc8a 100644 --- a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs +++ b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs @@ -116,10 +116,13 @@ namespace Tgstation.Server.Host.Controllers /// /// The path of the file to get /// The for the operation - /// A resulting in the for the operation + /// A resulting in the for the operation> + /// File read successfully.> + /// File does not currently exist. [HttpGet(Routes.File + "/{*filePath}")] [TgsAuthorize(ConfigurationRights.Read)] [ProducesResponseType(typeof(ConfigurationFile), 200)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task File(string filePath, CancellationToken cancellationToken) { if (ForbidDueToModeConflicts(filePath, out var systemIdentity)) @@ -153,9 +156,12 @@ namespace Tgstation.Server.Host.Controllers /// The path of the directory to get /// The for the operation /// A resulting in the for the operation + /// Directory listed successfully.> + /// Directory does not currently exist. [HttpGet(Routes.List + "/{*directoryPath}")] [TgsAuthorize(ConfigurationRights.List)] [ProducesResponseType(typeof(IReadOnlyList), 200)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task Directory(string directoryPath, CancellationToken cancellationToken) { if (ForbidDueToModeConflicts(directoryPath, out var systemIdentity)) diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 748067ad4c..707f1d9309 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -84,9 +84,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the operation. /// Read information successfully. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpGet] [TgsAuthorize(DreamDaemonRights.ReadMetadata | DreamDaemonRights.ReadRevision)] [ProducesResponseType(typeof(DreamDaemon), 200)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public Task Read(CancellationToken cancellationToken) => ReadImpl(null, cancellationToken); /// @@ -171,9 +173,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the operation. /// Settings applied successfully. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpPost] [TgsAuthorize(DreamDaemonRights.SetAutoStart | DreamDaemonRights.SetPorts | DreamDaemonRights.SetSecurity | DreamDaemonRights.SetWebClient | DreamDaemonRights.SoftRestart | DreamDaemonRights.SoftShutdown | DreamDaemonRights.Start | DreamDaemonRights.SetStartupTimeout | DreamDaemonRights.SetHeartbeatInterval)] [ProducesResponseType(typeof(DreamDaemon), 200)] + [ProducesResponseType(typeof(ErrorMessage), 410)] #pragma warning disable CA1502 // TODO: Decomplexify #pragma warning disable CA1506 public async Task Update([FromBody] DreamDaemon model, CancellationToken cancellationToken) diff --git a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs index d3812e3d1d..b40053100b 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs @@ -76,9 +76,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the request. /// retrieved successfully. + /// Specified ID does not exist in this instance. [HttpGet("{id}")] [TgsAuthorize(DreamMakerRights.CompileJobs)] [ProducesResponseType(typeof(Api.Models.CompileJob), 200)] + [ProducesResponseType(typeof(ErrorMessage), 404)] public async Task GetId(long id, CancellationToken cancellationToken) { var compileJob = await DatabaseContext @@ -156,10 +158,12 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the request. /// Changes applied successfully. The updated settings will be returned. /// Changes applied successfully. The updated settings will be not be returned due to permissions. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpPost] [TgsAuthorize(DreamMakerRights.SetDme | DreamMakerRights.SetApiValidationPort | DreamMakerRights.SetApiValidationPort)] [ProducesResponseType(typeof(DreamMaker), 200)] [ProducesResponseType(204)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task Update([FromBody] DreamMaker model, CancellationToken cancellationToken) { if (model == null) diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index c55405bc2e..95207a7f78 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -312,9 +312,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the request. /// Instance detatched successfully. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpDelete("{id}")] [TgsAuthorize(InstanceManagerRights.Delete)] [ProducesResponseType(204)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task Delete(long id, CancellationToken cancellationToken) { var originalModel = await DatabaseContext @@ -355,10 +357,12 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the request. /// Instance updated successfully. /// Instance updated successfully and relocation job created. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpPost] [TgsAuthorize(InstanceManagerRights.Relocate | InstanceManagerRights.Rename | InstanceManagerRights.SetAutoUpdate | InstanceManagerRights.SetConfiguration | InstanceManagerRights.SetOnline | InstanceManagerRights.SetChatBotLimit)] [ProducesResponseType(typeof(Api.Models.Instance), 200)] [ProducesResponseType(typeof(Api.Models.Instance), 202)] + [ProducesResponseType(typeof(ErrorMessage), 410)] #pragma warning disable CA1502 // TODO: Decomplexify public async Task Update([FromBody] Api.Models.Instance model, CancellationToken cancellationToken) { @@ -583,9 +587,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the request. /// Retrieved successfully. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpGet("{id}")] [TgsAuthorize(InstanceManagerRights.List | InstanceManagerRights.Read)] [ProducesResponseType(typeof(Api.Models.Instance), 200)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task GetId(long id, CancellationToken cancellationToken) { var cantList = !AuthenticationContext.User.InstanceManagerRights.Value.HasFlag(InstanceManagerRights.List); diff --git a/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs b/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs index 4fbd2460d4..a6c4bef4f5 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceUserController.cs @@ -89,9 +89,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the request. /// updated successfully. + /// The requested does not currently exist. [HttpPost] [TgsAuthorize(InstanceUserRights.WriteUsers)] [ProducesResponseType(typeof(Api.Models.InstanceUser), 200)] + [ProducesResponseType(typeof(ErrorMessage), 410)] #pragma warning disable CA1506 // TODO: Decomplexify public async Task Update([FromBody] Api.Models.InstanceUser model, CancellationToken cancellationToken) { @@ -163,9 +165,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the request. /// Retrieve successfully. + /// The requested does not currently exist. [HttpGet("{id}")] [TgsAuthorize(InstanceUserRights.ReadUsers)] [ProducesResponseType(typeof(Api.Models.InstanceUser), 200)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task GetId(long id, CancellationToken cancellationToken) { // this functions as userId diff --git a/src/Tgstation.Server.Host/Controllers/JobController.cs b/src/Tgstation.Server.Host/Controllers/JobController.cs index 080b8e5ca4..0bcf5248f2 100644 --- a/src/Tgstation.Server.Host/Controllers/JobController.cs +++ b/src/Tgstation.Server.Host/Controllers/JobController.cs @@ -93,9 +93,11 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the request. /// cancellation requested successfully. /// does not exist in this instance. + /// could not be found in the job manager. Has it already completed? [HttpDelete("{id}")] [TgsAuthorize] [ProducesResponseType(typeof(Api.Models.Job), 202)] + [ProducesResponseType(typeof(ErrorMessage), 404)] public async Task Delete(long id, CancellationToken cancellationToken) { // don't care if an instance post or not at this point @@ -129,6 +131,7 @@ namespace Tgstation.Server.Host.Controllers [HttpGet("{id}")] [TgsAuthorize] [ProducesResponseType(typeof(Api.Models.Job), 200)] + [ProducesResponseType(typeof(ErrorMessage), 404)] public async Task GetId(long id, CancellationToken cancellationToken) { var job = await DatabaseContext diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index d4d46befe2..d6536518e3 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -140,9 +140,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the request. /// The was created successfully and the to clone it has begun. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpPut] [TgsAuthorize(RepositoryRights.SetOrigin)] [ProducesResponseType(typeof(Repository), 201)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task Create([FromBody] Repository model, CancellationToken cancellationToken) { if (model == null) @@ -232,9 +234,11 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation /// A resulting in the of the operation /// Job to delete the repository created successfully. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpDelete] [TgsAuthorize(RepositoryRights.Delete)] [ProducesResponseType(typeof(Repository), 202)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task Delete(CancellationToken cancellationToken) { var currentModel = await DatabaseContext @@ -273,10 +277,12 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the operation. /// Retrieved the settings successfully. /// Retrieved the settings successfully, though they did not previously exist. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpGet] [TgsAuthorize(RepositoryRights.Read)] [ProducesResponseType(typeof(Repository), 200)] [ProducesResponseType(typeof(Repository), 201)] + [ProducesResponseType(typeof(ErrorMessage), 410)] public async Task Read(CancellationToken cancellationToken) { var currentModel = await DatabaseContext @@ -317,10 +323,12 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the operation. /// Updated the settings successfully. /// Updated the settings successfully and a was created to make the requested git changes. + /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpPost] [TgsAuthorize(RepositoryRights.ChangeAutoUpdateSettings | RepositoryRights.ChangeCommitter | RepositoryRights.ChangeCredentials | RepositoryRights.ChangeTestMergeCommits | RepositoryRights.MergePullRequest | RepositoryRights.SetReference | RepositoryRights.SetSha | RepositoryRights.UpdateBranch)] [ProducesResponseType(typeof(Repository), 200)] [ProducesResponseType(typeof(Repository), 202)] + [ProducesResponseType(typeof(ErrorMessage), 410)] #pragma warning disable CA1502, CA1505 // TODO: Decomplexify public async Task Update([FromBody]Repository model, CancellationToken cancellationToken) { diff --git a/src/Tgstation.Server.Host/Controllers/UserController.cs b/src/Tgstation.Server.Host/Controllers/UserController.cs index f0ac5a30ec..7bac3e59e8 100644 --- a/src/Tgstation.Server.Host/Controllers/UserController.cs +++ b/src/Tgstation.Server.Host/Controllers/UserController.cs @@ -99,6 +99,7 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the operation. /// created successfully. + /// The requested system identifier could not be found. [HttpPut] [TgsAuthorize(AdministrationRights.WriteUsers)] [ProducesResponseType(typeof(Api.Models.User), 201)] @@ -173,6 +174,7 @@ namespace Tgstation.Server.Host.Controllers [HttpPost] [TgsAuthorize(AdministrationRights.WriteUsers | AdministrationRights.EditOwnPassword)] [ProducesResponseType(typeof(Api.Models.User), 200)] + [ProducesResponseType(typeof(ErrorMessage), 404)] #pragma warning disable CA1502 // TODO: Decomplexify #pragma warning disable CA1506 public async Task Update([FromBody] UserUpdate model, CancellationToken cancellationToken) @@ -290,6 +292,7 @@ namespace Tgstation.Server.Host.Controllers [HttpGet("{id}")] [TgsAuthorize] [ProducesResponseType(typeof(Api.Models.User), 200)] + [ProducesResponseType(typeof(ErrorMessage), 404)] public async Task GetId(long id, CancellationToken cancellationToken) { if (id == AuthenticationContext.User.Id) diff --git a/src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs b/src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs index 09dae53718..218740c51b 100644 --- a/src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs +++ b/src/Tgstation.Server.Host/Core/SwaggerConfiguration.cs @@ -84,24 +84,12 @@ namespace Tgstation.Server.Host.Core Description = "User lacks sufficient permissions for the operation." }); - AddDefaultResponse(HttpStatusCode.NotFound, new OpenApiResponse - { - Description = ErrorCode.ResourceNeverPresent.Describe(), - Content = errorMessageContent - }); - AddDefaultResponse(HttpStatusCode.Conflict, new OpenApiResponse { Description = "A data integrity check failed while performing the operation. See error message for details.", Content = errorMessageContent }); - AddDefaultResponse(HttpStatusCode.Gone, new OpenApiResponse - { - Description = ErrorCode.ResourceNotPresent.Describe(), - Content = errorMessageContent - }); - AddDefaultResponse(HttpStatusCode.InternalServerError, new OpenApiResponse { Description = ErrorCode.InternalServerError.Describe(),