tgstation-server 6.11.3
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AdministrationAuthority.cs
Go to the documentation of this file.
1using System;
4
7
8using Octokit;
9
19
21{
24 {
28 const string OctokitException = "Bad GitHub API response, check configuration!";
29
33 static readonly object ReadCacheKey = new();
34
39
44
49
54
59
91
94 {
95 try
96 {
98 {
99 Version? greatestVersion = null;
100 Uri? repoUrl = null;
101 try
102 {
104 var repositoryUrlTask = gitHubService.GetUpdatesRepositoryUrl(cancellationToken);
106
107 foreach (var kvp in releases)
108 {
109 var version = kvp.Key;
110 var release = kvp.Value;
111 if (version.Major > 3 // Forward/backward compatible but not before TGS4
112 && (greatestVersion == null || version > greatestVersion))
114 }
115
117 }
118 catch (NotFoundException e)
119 {
120 Logger.LogWarning(e, "Not found exception while retrieving upstream repository info!");
121 }
122
123 return new AdministrationResponse
124 {
125 LatestVersion = greatestVersion,
126 TrackedRepositoryUrl = repoUrl,
127 GeneratedAt = DateTimeOffset.UtcNow,
128 };
129 }
130
131 var ttl = TimeSpan.FromMinutes(30);
134 {
135 using var entry = cacheService.CreateEntry(ReadCacheKey);
137 entry.Value = task = CacheFactory();
138 }
139 else
141
143 }
145 {
147 }
148 catch (ApiException e)
149 {
150 Logger.LogWarning(e, OctokitException);
152 new ErrorMessageResponse(ErrorCode.RemoteApiError)
153 {
154 AdditionalData = e.Message,
155 },
156 HttpFailureResponse.FailedDependency);
157 }
158 }
159
162 {
165 {
168 }
171
172 if (targetVersion.Major < 4)
173 return BadRequest<ServerUpdateResponse>(ErrorCode.CannotChangeServerSuite);
174
177 new ErrorMessageResponse(ErrorCode.MissingHostWatchdog),
178 HttpFailureResponse.UnprocessableEntity);
179
182 : null;
183
185 try
186 {
187 try
188 {
190 }
191 catch
192 {
194 await uploadTicket!.DisposeAsync();
195
196 throw;
197 }
198 }
200 {
202 }
203 catch (ApiException e)
204 {
205 Logger.LogWarning(e, OctokitException);
207 new ErrorMessageResponse(ErrorCode.RemoteApiError)
208 {
209 AdditionalData = e.Message,
210 },
211 HttpFailureResponse.FailedDependency);
212 }
213
214 return updateResult switch
215 {
220 new ErrorMessageResponse(ErrorCode.SwarmIntegrityCheckFailed),
221 HttpFailureResponse.FailedDependency),
222 _ => throw new InvalidOperationException($"Unexpected ServerUpdateResult: {updateResult}"),
223 };
224 }
225
228 {
230 {
231 Logger.LogDebug("Restart request failed due to lack of host watchdog!");
232 return new AuthorityResponse(
233 new ErrorMessageResponse(ErrorCode.MissingHostWatchdog),
234 HttpFailureResponse.UnprocessableEntity);
235 }
236
238 return new AuthorityResponse();
239 }
240 }
241}
AdministrationRights? AdministrationRights
The Rights.AdministrationRights for the user.
Represents an error message returned by the server.
async ValueTask< AuthorityResponse< ServerUpdateResponse > > TriggerServerVersionChange(Version targetVersion, bool uploadZip, CancellationToken cancellationToken)
Triggers a restart of tgstation-server without terminating running game instances,...
AdministrationAuthority(IAuthenticationContext authenticationContext, IDatabaseContext databaseContext, ILogger< UserAuthority > logger, IGitHubServiceFactory gitHubServiceFactory, IServerControl serverControl, IServerUpdateInitiator serverUpdateInitiator, IFileTransferTicketProvider fileTransferService, IMemoryCache cacheService)
Initializes a new instance of the AdministrationAuthority class.
readonly IFileTransferTicketProvider fileTransferService
The IFileTransferTicketProvider for the AdministrationAuthority.
readonly IServerControl serverControl
The IServerControl for the AdministrationAuthority.
readonly IMemoryCache cacheService
The IMemoryCache for the AdministrationAuthority.
async ValueTask< AuthorityResponse > TriggerServerRestart()
Triggers a restart of tgstation-server without terminating running game instances....
const string OctokitException
Default Exception.Message for ApiExceptions.
async ValueTask< AuthorityResponse< AdministrationResponse > > GetUpdateInformation(bool forceFresh, CancellationToken cancellationToken)
Gets the AdministrationResponse containing server update information.A ValueTask<TResult> resulting i...
readonly IServerUpdateInitiator serverUpdateInitiator
The IServerUpdateInitiator for the AdministrationAuthority.
static readonly object ReadCacheKey
The IMemoryCache key for GetUpdateInformation(bool, CancellationToken).
readonly IGitHubServiceFactory gitHubServiceFactory
The IGitHubServiceFactory for the AdministrationAuthority.
ILogger< AuthorityBase > Logger
Gets the ILogger for the AuthorityBase.
PermissionSet PermissionSet
The User's effective PermissionSet.
IAuthority for administrative server operations.
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.
ValueTask< ServerUpdateResult > InitiateUpdate(IFileStreamProvider? fileStreamProvider, Version version, CancellationToken cancellationToken)
Start the process of downloading and applying an update to a new server version .
For creating and accessing authentication contexts.
Service for temporarily storing files to be downloaded or uploaded.
IFileUploadTicket CreateUpload(FileUploadStreamKind streamKind)
Create a IFileUploadTicket.
A FileTicketResponse that waits for a pending upload.
ValueTask< IGitHubService > CreateService(CancellationToken cancellationToken)
Create a IGitHubService.
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.
HttpFailureResponse
Indicates the type of HTTP status code an failing AuthorityResponse should generate.
HttpSuccessResponse
Indicates the type of HTTP status code a successful AuthorityResponse<TResult> should generate.
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...