6using System.Threading.Tasks;
9using Microsoft.AspNetCore.Mvc;
10using Microsoft.Extensions.Logging;
11using Microsoft.Extensions.Options;
110 ILogger<AdministrationController> logger,
111 IOptions<FileLoggingConfiguration> fileLoggingConfigurationOptions,
115 authenticationContext,
127 fileLoggingConfiguration = fileLoggingConfigurationOptions?.Value ??
throw new ArgumentNullException(nameof(fileLoggingConfigurationOptions));
143 public async ValueTask<IActionResult>
Read(CancellationToken cancellationToken)
147 Version? greatestVersion =
null;
153 var releases = await gitHubService.GetTgsReleases(cancellationToken);
155 foreach (var kvp
in releases)
157 var version = kvp.Key;
158 var release = kvp.Value;
159 if (version.Major > 3
160 && (greatestVersion ==
null || version > greatestVersion))
161 greatestVersion = version;
164 repoUrl = await repositoryUrlTask;
166 catch (NotFoundException e)
168 Logger.LogWarning(e,
"Not found exception while retrieving upstream repository info!");
173 LatestVersion = greatestVersion,
174 TrackedRepositoryUrl = repoUrl,
177 catch (RateLimitExceededException e)
181 catch (ApiException e)
186 AdditionalData = e.Message,
211 ArgumentNullException.ThrowIfNull(model);
213 var attemptingUpload = model.UploadZip ==
true;
214 if (attemptingUpload)
222 if (model.NewVersion ==
null)
225 AdditionalData =
"newVersion is required!",
228 if (model.NewVersion.Major < 3)
245 [ProducesResponseType(204)]
247 public async ValueTask<IActionResult>
Delete()
253 Logger.LogDebug(
"Restart request failed due to lack of host watchdog!");
260 catch (InvalidOperationException)
262 return StatusCode(HttpStatusCode.ServiceUnavailable);
279 public ValueTask<IActionResult>
ListLogs([FromQuery]
int? page, [FromQuery]
int? pageSize, CancellationToken cancellationToken)
287 var tasks = files.Select(
298 await Task.WhenAll(tasks);
303 .Select(x => x.Result)
304 .OrderByDescending(x => x.Name));
306 catch (IOException ex)
311 AdditionalData = ex.ToString(),
332 public async ValueTask<IActionResult>
GetLog(
string path, CancellationToken cancellationToken)
334 ArgumentNullException.ThrowIfNull(path);
336 path = HttpUtility.UrlDecode(path);
340 if (path != sanitizedPath)
359 FileTicket = fileTransferTicket.FileTicket,
362 catch (IOException ex)
366 AdditionalData = ex.ToString(),
378 async ValueTask<IActionResult>
AttemptInitiateUpdate(Version newVersion,
bool attemptingUpload, CancellationToken cancellationToken)
393 if (attemptingUpload)
394 await uploadTicket!.DisposeAsync();
399 catch (RateLimitExceededException e)
403 catch (ApiException e)
408 AdditionalData = e.Message,
412 return updateResult
switch
414 ServerUpdateResult.Started => Accepted(
new ServerUpdateResponse(newVersion, uploadTicket?.Ticket.FileTicket)),
415 ServerUpdateResult.ReleaseMissing => this.Gone(),
418 _ =>
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.
ValueTask< IActionResult > ListLogs([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken)
List LogFileResponses present.
readonly FileLoggingConfiguration fileLoggingConfiguration
The FileLoggingConfiguration for the AdministrationController.
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the AdministrationController.
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 > Read(CancellationToken cancellationToken)
Get AdministrationResponse server information.
async ValueTask< IActionResult > GetLog(string path, CancellationToken cancellationToken)
Download a LogFileResponse.
readonly IPlatformIdentifier platformIdentifier
The IPlatformIdentifier for the AdministrationController.
const string OctokitException
Default Exception.Message for ApiExceptions.
readonly IGitHubServiceFactory gitHubServiceFactory
The IGitHubServiceFactory for the AdministrationController.
readonly IIOManager ioManager
The IIOManager for the AdministrationController.
async ValueTask< IActionResult > AttemptInitiateUpdate(Version newVersion, bool attemptingUpload, CancellationToken cancellationToken)
Attempt to initiate an update.
async ValueTask< IActionResult > Delete()
Attempts to restart the server.
readonly IServerUpdateInitiator serverUpdateInitiator
The IServerUpdateInitiator for the AdministrationController.
AdministrationController(IDatabaseContext databaseContext, IAuthenticationContext authenticationContext, IGitHubServiceFactory gitHubServiceFactory, IServerControl serverControl, IServerUpdateInitiator serverUpdateInitiator, IAssemblyInformationProvider assemblyInformationProvider, IIOManager ioManager, IPlatformIdentifier platformIdentifier, IFileTransferTicketProvider fileTransferService, ILogger< AdministrationController > logger, IOptions< FileLoggingConfiguration > fileLoggingConfigurationOptions, IApiHeadersProvider apiHeadersProvider)
Initializes a new instance of the AdministrationController class.
readonly IServerControl serverControl
The IServerControl for the AdministrationController.
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...
bool WatchdogPresent
true if live updates are supported, false. TryStartUpdate(IServerUpdateExecutor, Version) and Restart...
ValueTask Restart()
Restarts the Host.
Initiates server self updates.
ValueTask< 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 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.
Represents the currently authenticated Models.User.
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.
Factory for IGitHubServices.
IGitHubService CreateService()
Create a IGitHubService.
ValueTask< 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...