tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AdministrationController.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3using System.Linq;
6using System.Web;
7
11
26
28{
34 {
39
44
49
54
59
64
103
113 [HttpGet]
120 this,
121 authority => authority.GetUpdateInformation(fresh ?? false, cancellationToken));
122
134 [HttpPost]
142 {
143 ArgumentNullException.ThrowIfNull(model);
144
145 if (model.NewVersion == null)
146 return BadRequest(new ErrorMessageResponse(ErrorCode.ModelValidationFailure)
147 {
148 AdditionalData = "newVersion is required!",
149 });
150
152 this,
153 authority => authority.TriggerServerVersionChange(model.NewVersion, model.UploadZip ?? false, cancellationToken));
154 }
155
162 [HttpDelete]
167#pragma warning disable API1001 // Action returns undeclared success result
169 this,
170 authority => authority.TriggerServerRestart());
171#pragma warning restore API1001 // Action returns undeclared success result
172
183 [TgsAuthorize(AdministrationRights.DownloadLogs)]
187 => Paginated(
188 async () =>
189 {
191 try
192 {
194 var tasks = files.Select(
196 {
197 Name = ioManager.GetFileName(file),
198 LastModified = await ioManager
199 .GetLastModified(
202 })
203 .ToList();
204
205 await Task.WhenAll(tasks);
206
208 tasks
209 .AsQueryable()
210 .Select(x => x.Result)
211 .OrderByDescending(x => x.Name));
212 }
213 catch (IOException ex)
214 {
216 Conflict(new ErrorMessageResponse(ErrorCode.IOError)
217 {
218 AdditionalData = ex.ToString(),
219 }));
220 }
221 },
222 null,
223 page,
224 pageSize,
226
235 [HttpGet(Routes.Logs + "/{*path}")]
236 [TgsAuthorize(AdministrationRights.DownloadLogs)]
240 {
241 ArgumentNullException.ThrowIfNull(path);
242
243 path = HttpUtility.UrlDecode(path);
244
245 // guard against directory navigation
247 if (path != sanitizedPath)
248 return Forbid();
249
252 path);
253 try
254 {
257 () => null,
258 null,
259 fullPath,
260 true));
261
262 return Ok(new LogFileResponse
263 {
264 Name = path,
266 FileTicket = fileTransferTicket.FileTicket,
267 });
268 }
269 catch (IOException ex)
270 {
271 return Conflict(new ErrorMessageResponse(ErrorCode.IOError)
272 {
273 AdditionalData = ex.ToString(),
274 });
275 }
276 }
277 }
278}
Represents an error message returned by the server.
Routes to a server actions.
Definition Routes.cs:9
const string Administration
The server administration controller.
Definition Routes.cs:28
const string Logs
The endpoint to download server logs.
Definition Routes.cs:33
string GetFullLogDirectory(IIOManager ioManager, IAssemblyInformationProvider assemblyInformationProvider, IPlatformIdentifier platformIdentifier)
Gets the evaluated log Directory.
readonly IRestAuthorityInvoker< IAdministrationAuthority > administrationAuthority
The IRestAuthorityInvoker<TAuthority> for the IAdministrationAuthority.
ValueTask< IActionResult > Read([FromQuery] bool? fresh, CancellationToken cancellationToken)
Get AdministrationResponse server information.
AdministrationController(IDatabaseContext databaseContext, IAuthenticationContext authenticationContext, IApiHeadersProvider apiHeadersProvider, ILogger< AdministrationController > logger, IRestAuthorityInvoker< IAdministrationAuthority > administrationAuthority, IAssemblyInformationProvider assemblyInformationProvider, IIOManager ioManager, IPlatformIdentifier platformIdentifier, IFileTransferTicketProvider fileTransferService, IOptions< FileLoggingConfiguration > fileLoggingConfigurationOptions)
Initializes a new instance of the AdministrationController class.
ValueTask< IActionResult > ListLogs([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken)
List LogFileResponses present.
readonly FileLoggingConfiguration fileLoggingConfiguration
The FileLoggingConfiguration for the AdministrationController.
ValueTask< IActionResult > AdministrationResponse(this, authority=> authority.GetUpdateInformation(fresh ?? false, cancellationToken))
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the AdministrationController.
ValueTask< IActionResult > Delete()
Attempts to restart the server.
readonly IFileTransferTicketProvider fileTransferService
The IFileTransferTicketProvider for the AdministrationController.
async ValueTask< IActionResult > Update([FromBody] ServerUpdateRequest model, CancellationToken cancellationToken)
Attempt to perform a server upgrade.
async ValueTask< IActionResult > GetLog(string path, CancellationToken cancellationToken)
Download a LogFileResponse.
readonly IPlatformIdentifier platformIdentifier
The IPlatformIdentifier for the AdministrationController.
readonly IIOManager ioManager
The IIOManager for the AdministrationController.
Base Controller for API functions.
Represents a file on disk to be downloaded.
IAuthority for administrative server operations.
ValueTask< AuthorityResponse > TriggerServerRestart()
Triggers a restart of tgstation-server without terminating running game instances.
ValueTask< AuthorityResponse< ServerUpdateResponse > > TriggerServerVersionChange(Version targetVersion, bool uploadZip, CancellationToken cancellationToken)
Triggers a restart of tgstation-server without terminating running game instances,...
ValueTask< AuthorityResponse< AdministrationResponse > > GetUpdateInformation(bool forceFresh, CancellationToken cancellationToken)
Gets the AdministrationResponse containing server update information.
Invokes TAuthority methods and generates IActionResult responses.
ValueTask< IActionResult > Invoke(ApiController controller, Func< TAuthority, ValueTask< AuthorityResponse > > authorityInvoker)
Invoke a TAuthority method with no success result.
Interface for using filesystems.
Definition IIOManager.cs:13
Task< IReadOnlyList< string > > GetFiles(string path, CancellationToken cancellationToken)
Returns full file names in a given path .
string GetFileName(string path)
Gets the file name portion of a path .
string ConcatPath(params string[] paths)
Combines an array of strings into a path.
Task< DateTimeOffset > GetLastModified(string path, CancellationToken cancellationToken)
Get the DateTimeOffset of when a given path was last modified.
For creating and accessing authentication contexts.
For identifying the current platform.
Service for temporarily storing files to be downloaded or uploaded.
FileTicketResponse CreateDownload(FileDownloadProvider fileDownloadProvider)
Create a FileTicketResponse for a download.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12
@ List
User may list files if the Models.Instance allows it.
AdministrationRights
Administration rights for the server.