6using System.Threading.Tasks;
9using Microsoft.AspNetCore.Mvc;
10using Microsoft.Extensions.Logging;
11using Microsoft.Extensions.Options;
107 ILogger<AdministrationController> logger,
108 IOptions<FileLoggingConfiguration> fileLoggingConfigurationOptions)
111 authenticationContextFactory,
122 fileLoggingConfiguration = fileLoggingConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(fileLoggingConfigurationOptions));
138 public async Task<IActionResult>
Read(CancellationToken cancellationToken)
142 Version greatestVersion =
null;
149 foreach (var kvp
in releases)
151 var version = kvp.Key;
152 var release = kvp.Value;
153 if (version.Major > 3
154 && (greatestVersion ==
null || version > greatestVersion))
155 greatestVersion = version;
158 repoUrl = await repositoryUrlTask;
160 catch (NotFoundException e)
162 Logger.LogWarning(e,
"Not found exception while retrieving upstream repository info!");
167 LatestVersion = greatestVersion,
168 TrackedRepositoryUrl = repoUrl,
171 catch (RateLimitExceededException e)
175 catch (ApiException e)
180 AdditionalData = e.Message,
205 ArgumentNullException.ThrowIfNull(model);
207 var attemptingUpload = model.UploadZip ==
true;
208 if (attemptingUpload)
216 if (model.NewVersion ==
null)
219 AdditionalData =
"newVersion is required!",
222 if (model.NewVersion.Major < 3)
239 [ProducesResponseType(204)]
241 public async Task<IActionResult>
Delete()
247 Logger.LogDebug(
"Restart request failed due to lack of host watchdog!");
254 catch (InvalidOperationException)
256 return StatusCode(HttpStatusCode.ServiceUnavailable);
273 public Task<IActionResult>
ListLogs([FromQuery]
int? page, [FromQuery]
int? pageSize, CancellationToken cancellationToken)
281 var tasks = files.Select(
292 await Task.WhenAll(tasks);
297 .Select(x => x.Result)
298 .OrderByDescending(x => x.Name));
300 catch (IOException ex)
305 AdditionalData = ex.ToString(),
326 public async Task<IActionResult>
GetLog(
string path, CancellationToken cancellationToken)
328 ArgumentNullException.ThrowIfNull(path);
330 path = HttpUtility.UrlDecode(path);
334 if (path != sanitizedPath)
353 FileTicket = fileTransferTicket.FileTicket,
356 catch (IOException ex)
360 AdditionalData = ex.ToString(),
372 async Task<IActionResult>
AttemptInitiateUpdate(Version newVersion,
bool attemptingUpload, CancellationToken cancellationToken)
387 if (attemptingUpload)
388 await uploadTicket.DisposeAsync();
393 catch (RateLimitExceededException e)
397 catch (ApiException e)
402 AdditionalData = e.Message,
406 return updateResult
switch
408 ServerUpdateResult.Started => Accepted(
new ServerUpdateResponse(newVersion, uploadTicket?.Ticket.FileTicket)),
409 ServerUpdateResult.ReleaseMissing => this.Gone(),
412 _ =>
throw new InvalidOperationException($
"Unexpected ServerUpdateResult: {updateResult}"),
AdministrationRights? AdministrationRights
The Rights.AdministrationRights for the user.
Represents a request to update TGS.
Represents administrative server information.
Represents an error message returned by the server.
Represents a server log file.
Represents a paginated set of models.
A response to a Request.ServerUpdateRequest.
Routes to a server actions.
const string Administration
The server administration controller.
const string Logs
The endpoint to download server logs.
File logging configuration options.
string GetFullLogDirectory(IIOManager ioManager, IAssemblyInformationProvider assemblyInformationProvider, IPlatformIdentifier platformIdentifier)
Gets the evaluated log Directory.
ApiController for TGS administration purposes.
async Task< IActionResult > AttemptInitiateUpdate(Version newVersion, bool attemptingUpload, CancellationToken cancellationToken)
Attempt to initiate an update.
AdministrationController(IDatabaseContext databaseContext, IAuthenticationContextFactory authenticationContextFactory, IGitHubService gitHubService, IServerControl serverControl, IServerUpdateInitiator serverUpdateInitiator, IAssemblyInformationProvider assemblyInformationProvider, IIOManager ioManager, IPlatformIdentifier platformIdentifier, IFileTransferTicketProvider fileTransferService, ILogger< AdministrationController > logger, IOptions< FileLoggingConfiguration > fileLoggingConfigurationOptions)
Initializes a new instance of the AdministrationController class.
readonly FileLoggingConfiguration fileLoggingConfiguration
The FileLoggingConfiguration for the AdministrationController.
async Task< IActionResult > GetLog(string path, CancellationToken cancellationToken)
Download a LogFileResponse.
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the AdministrationController.
Task< IActionResult > ListLogs([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken)
List LogFileResponses present.
async Task< IActionResult > Delete()
Attempts to restart the server.
readonly IFileTransferTicketProvider fileTransferService
The IFileTransferTicketProvider for the AdministrationController.
async Task< IActionResult > Read(CancellationToken cancellationToken)
Get AdministrationResponse server information.
readonly IPlatformIdentifier platformIdentifier
The IPlatformIdentifier for the AdministrationController.
const string OctokitException
Default Exception.Message for ApiExceptions.
readonly IIOManager ioManager
The IIOManager for the AdministrationController.
readonly IGitHubService gitHubService
The IGitHubService for the AdministrationController.
readonly IServerUpdateInitiator serverUpdateInitiator
The IServerUpdateInitiator for the AdministrationController.
readonly IServerControl serverControl
The IServerControl for the AdministrationController.
async Task< IActionResult > Update([FromBody] ServerUpdateRequest model, CancellationToken cancellationToken)
Attempt to perform a server upgrade.
Base Controller for API functions.
StatusCodeResult StatusCode(HttpStatusCode statusCode)
Strongly type calls to ControllerBase.StatusCode(int).
ObjectResult RateLimit(RateLimitExceededException rateLimitException)
429 response for a given rateLimitException .
ILogger< ApiController > Logger
The ILogger for the ApiController.
Helper for returning paginated models.
PermissionSet PermissionSet
The User's effective PermissionSet.
Represents a file on disk to be downloaded.
Represents a service that may take an updated Host assembly and run it, stopping the current assembly...
Task Restart()
Restarts the Host.
bool WatchdogPresent
true if live updates are supported, false. TryStartUpdate(IServerUpdateExecutor, Version) and Restart...
Initiates server self updates.
Task< ServerUpdateResult > InitiateUpdate(IFileStreamProvider fileStreamProvider, Version version, CancellationToken cancellationToken)
Start the process of downloading and applying an update to a new server version .
Interface for using filesystems.
Task< IReadOnlyList< string > > GetFiles(string path, CancellationToken cancellationToken)
Returns 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.
Service for temporarily storing files to be downloaded or uploaded.
FileTicketResponse CreateDownload(FileDownloadProvider fileDownloadProvider)
Create a FileTicketResponse for a download.
IFileUploadTicket CreateUpload(FileUploadStreamKind streamKind)
Create a IFileUploadTicket.
A FileTicketResponse that waits for a pending upload.
Service for interacting with the GitHub API.
Task< Dictionary< Version, Release > > GetTgsReleases(CancellationToken cancellationToken)
Get all valid TGS Releases from the configured update source.
Task< Uri > GetUpdatesRepositoryUrl(CancellationToken cancellationToken)
Gets the Uri of the repository designated as the updates repository.
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
AdministrationRights
Administration rights for the server.
ServerUpdateResult
The result of a call to start a server update.
FileUploadStreamKind
Determines the type of global::System.IO.Stream returned from IFileUploadTicket's created from IFileT...