tgstation-server 6.12.0
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 var scopeCancellationToken = CancellationToken.None; // DCT: None available
102 try
103 {
107
108 foreach (var kvp in releases)
109 {
110 var version = kvp.Key;
111 var release = kvp.Value;
112 if (version.Major > 3 // Forward/backward compatible but not before TGS4
113 && (greatestVersion == null || version > greatestVersion))
115 }
116
118 }
119 catch (NotFoundException e)
120 {
121 Logger.LogWarning(e, "Not found exception while retrieving upstream repository info!");
122 }
123
124 return new AdministrationResponse
125 {
126 LatestVersion = greatestVersion,
127 TrackedRepositoryUrl = repoUrl,
128 GeneratedAt = DateTimeOffset.UtcNow,
129 };
130 }
131
132 var ttl = TimeSpan.FromMinutes(30);
135 {
136 using var entry = cacheService.CreateEntry(ReadCacheKey);
138 entry.Value = task = CacheFactory();
139 }
140 else
142
143 var result = await task.WaitAsync(cancellationToken);
145 }
147 {
149 }
150 catch (ApiException e)
151 {
152 Logger.LogWarning(e, OctokitException);
154 new ErrorMessageResponse(ErrorCode.RemoteApiError)
155 {
156 AdditionalData = e.Message,
157 },
158 HttpFailureResponse.FailedDependency);
159 }
160 }
161
164 {
167 {
170 }
173
174 if (targetVersion.Major < 4)
175 return BadRequest<ServerUpdateResponse>(ErrorCode.CannotChangeServerSuite);
176
179 new ErrorMessageResponse(ErrorCode.MissingHostWatchdog),
180 HttpFailureResponse.UnprocessableEntity);
181
184 : null;
185
187 try
188 {
189 try
190 {
192 }
193 catch
194 {
196 await uploadTicket!.DisposeAsync();
197
198 throw;
199 }
200 }
202 {
204 }
205 catch (ApiException e)
206 {
207 Logger.LogWarning(e, OctokitException);
209 new ErrorMessageResponse(ErrorCode.RemoteApiError)
210 {
211 AdditionalData = e.Message,
212 },
213 HttpFailureResponse.FailedDependency);
214 }
215
216 return updateResult switch
217 {
222 new ErrorMessageResponse(ErrorCode.SwarmIntegrityCheckFailed),
223 HttpFailureResponse.FailedDependency),
224 _ => throw new InvalidOperationException($"Unexpected ServerUpdateResult: {updateResult}"),
225 };
226 }
227
230 {
232 {
233 Logger.LogDebug("Restart request failed due to lack of host watchdog!");
234 return new AuthorityResponse(
235 new ErrorMessageResponse(ErrorCode.MissingHostWatchdog),
236 HttpFailureResponse.UnprocessableEntity);
237 }
238
240 return new AuthorityResponse();
241 }
242 }
243}
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...