From 5d20fa76c0cbd5c066e3e84a3e104a67f9253683 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 11:35:34 -0500 Subject: [PATCH 01/12] Fix hosting API documentation in production - Actually inject the swagger service if the config is set. - This setting is no longer overridden by launching in development mode. --- src/Tgstation.Server.Host/Core/Application.cs | 5 ++--- tests/Tgstation.Server.Tests/TestingServer.cs | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index b1dc85fcee..dc235d3140 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -195,7 +195,7 @@ namespace Tgstation.Server.Host.Core options.SerializerSettings.Converters = new[] { new VersionConverter() }; }); - if (hostingEnvironment.IsDevelopment()) + if (postSetupServices.GeneralConfiguration.HostApiDocumemtation) { static string GetDocumentationFilePath(string assemblyLocation) => IOManager.ConcatPath(IOManager.GetDirectoryName(assemblyLocation), String.Concat(IOManager.GetFileNameWithoutExtension(assemblyLocation), ".xml")); var assemblyDocumentationPath = GetDocumentationFilePath(typeof(Application).Assembly.Location); @@ -396,8 +396,7 @@ namespace Tgstation.Server.Host.Core // suppress OperationCancelledExceptions, they are just aborted HTTP requests applicationBuilder.UseCancelledRequestSuppression(); - if (hostingEnvironment.IsDevelopment() - || generalConfiguration.HostApiDocumemtation) + if (generalConfiguration.HostApiDocumemtation) { applicationBuilder.UseSwagger(); applicationBuilder.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TGS API V4")); diff --git a/tests/Tgstation.Server.Tests/TestingServer.cs b/tests/Tgstation.Server.Tests/TestingServer.cs index c061a0f9f3..a3181cf3cc 100644 --- a/tests/Tgstation.Server.Tests/TestingServer.cs +++ b/tests/Tgstation.Server.Tests/TestingServer.cs @@ -78,6 +78,7 @@ namespace Tgstation.Server.Tests String.Format(CultureInfo.InvariantCulture, "General:MinimumPasswordLength={0}", 10), String.Format(CultureInfo.InvariantCulture, "General:InstanceLimit={0}", 11), String.Format(CultureInfo.InvariantCulture, "General:UserLimit={0}", 150), + String.Format(CultureInfo.InvariantCulture, "General:HostApiDocumentation={0}", DumpOpenApiSpecpath), String.Format(CultureInfo.InvariantCulture, "FileLogging:Directory={0}", Path.Combine(Directory, "Logs")), String.Format(CultureInfo.InvariantCulture, "FileLogging:LogLevel={0}", "Trace"), String.Format(CultureInfo.InvariantCulture, "General:ValidInstancePaths:0={0}", Directory), From 7b98acdf96eda620aeca0c89b7ea8823831b8296 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 11:36:32 -0500 Subject: [PATCH 02/12] Fixed typo in HostApiDocumentation setting - Config version patch bump (Yes, it is technically a breaking change but I think it's forgivable as this is how it was spelt in the changelog). --- build/Version.props | 2 +- .../Configuration/GeneralConfiguration.cs | 2 +- src/Tgstation.Server.Host/Core/Application.cs | 4 ++-- src/Tgstation.Server.Host/Setup/SetupWizard.cs | 2 +- src/Tgstation.Server.Host/appsettings.json | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/Version.props b/build/Version.props index 79bcb4fb8f..e6845264db 100644 --- a/build/Version.props +++ b/build/Version.props @@ -3,7 +3,7 @@ 4.5.4 - 2.1.0 + 2.1.1 7.4.0 8.4.0 5.2.7 diff --git a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs index 4b925e9342..ad0e098be3 100644 --- a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs +++ b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs @@ -90,7 +90,7 @@ namespace Tgstation.Server.Host.Configuration /// /// If the swagger UI should be made avaiable. /// - public bool HostApiDocumemtation { get; set; } + public bool HostApiDocumentation { get; set; } /// /// Initializes a new instance of the . diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index dc235d3140..e8c6f11a48 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -195,7 +195,7 @@ namespace Tgstation.Server.Host.Core options.SerializerSettings.Converters = new[] { new VersionConverter() }; }); - if (postSetupServices.GeneralConfiguration.HostApiDocumemtation) + if (postSetupServices.GeneralConfiguration.HostApiDocumentation) { static string GetDocumentationFilePath(string assemblyLocation) => IOManager.ConcatPath(IOManager.GetDirectoryName(assemblyLocation), String.Concat(IOManager.GetFileNameWithoutExtension(assemblyLocation), ".xml")); var assemblyDocumentationPath = GetDocumentationFilePath(typeof(Application).Assembly.Location); @@ -396,7 +396,7 @@ namespace Tgstation.Server.Host.Core // suppress OperationCancelledExceptions, they are just aborted HTTP requests applicationBuilder.UseCancelledRequestSuppression(); - if (generalConfiguration.HostApiDocumemtation) + if (generalConfiguration.HostApiDocumentation) { applicationBuilder.UseSwagger(); applicationBuilder.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TGS API V4")); diff --git a/src/Tgstation.Server.Host/Setup/SetupWizard.cs b/src/Tgstation.Server.Host/Setup/SetupWizard.cs index b32bd9206d..31b934258e 100644 --- a/src/Tgstation.Server.Host/Setup/SetupWizard.cs +++ b/src/Tgstation.Server.Host/Setup/SetupWizard.cs @@ -613,7 +613,7 @@ namespace Tgstation.Server.Host.Setup if (String.IsNullOrWhiteSpace(newGeneralConfiguration.GitHubAccessToken)) newGeneralConfiguration.GitHubAccessToken = null; - newGeneralConfiguration.HostApiDocumemtation = await PromptYesNo("Host API Documentation? (y/n): ", cancellationToken).ConfigureAwait(false); + newGeneralConfiguration.HostApiDocumentation = await PromptYesNo("Host API Documentation? (y/n): ", cancellationToken).ConfigureAwait(false); return newGeneralConfiguration; } diff --git a/src/Tgstation.Server.Host/appsettings.json b/src/Tgstation.Server.Host/appsettings.json index bdc52afffc..63f9edf1ff 100644 --- a/src/Tgstation.Server.Host/appsettings.json +++ b/src/Tgstation.Server.Host/appsettings.json @@ -10,7 +10,7 @@ "UserLimit": 100, "InstanceLimit": 10, "ValidInstancePaths": null, - "HostApiDocumemtation": false + "HostApiDocumentation": false }, "FileLogging": { "Directory": null, From bb1c5c4d9867e17385e8032718da004d31fda0cc Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 11:42:26 -0500 Subject: [PATCH 03/12] Cleanup unecessary double call --- src/Tgstation.Server.Host/ServerFactory.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Tgstation.Server.Host/ServerFactory.cs b/src/Tgstation.Server.Host/ServerFactory.cs index 9be5679521..701dea559c 100644 --- a/src/Tgstation.Server.Host/ServerFactory.cs +++ b/src/Tgstation.Server.Host/ServerFactory.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -44,10 +44,9 @@ namespace Tgstation.Server.Host if (args == null) throw new ArgumentNullException(nameof(args)); + var basePath = IOManager.ResolvePath(); IHostBuilder CreateDefaultBuilder() => Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) - .ConfigureAppConfiguration((context, configuration) => configuration - .SetBasePath( - IOManager.ResolvePath())); + .ConfigureAppConfiguration((context, configuration) => configuration.SetBasePath(basePath)); var setupWizardHostBuilder = CreateDefaultBuilder() .UseSetupApplication(); From 11538986aa04c0ee584a1efa6b8c9fce81d28303 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 11:44:23 -0500 Subject: [PATCH 04/12] Move SetupWizardMode to Setup namespace --- .../Configuration/GeneralConfiguration.cs | 1 + .../{Configuration => Setup}/SetupWizardMode.cs | 12 ++++++------ tests/Tgstation.Server.Tests/TestingServer.cs | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) rename src/Tgstation.Server.Host/{Configuration => Setup}/SetupWizardMode.cs (58%) diff --git a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs index ad0e098be3..a806ea56f7 100644 --- a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs +++ b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; using Tgstation.Server.Api.Models.Internal; +using Tgstation.Server.Host.Setup; namespace Tgstation.Server.Host.Configuration { diff --git a/src/Tgstation.Server.Host/Configuration/SetupWizardMode.cs b/src/Tgstation.Server.Host/Setup/SetupWizardMode.cs similarity index 58% rename from src/Tgstation.Server.Host/Configuration/SetupWizardMode.cs rename to src/Tgstation.Server.Host/Setup/SetupWizardMode.cs index a61515d731..8d0798b88f 100644 --- a/src/Tgstation.Server.Host/Configuration/SetupWizardMode.cs +++ b/src/Tgstation.Server.Host/Setup/SetupWizardMode.cs @@ -1,27 +1,27 @@ -namespace Tgstation.Server.Host.Configuration +namespace Tgstation.Server.Host.Setup { /// - /// Determines if the will run + /// Determines if the will run. /// public enum SetupWizardMode { /// - /// Run the wizard if the appsettings.{Environment}.json is not present or empty + /// Run the wizard if the appsettings.{Environment}.json is not present or empty. /// Autodetect, /// - /// Force run the wizard + /// Force run the wizard. /// Force, /// - /// Only run the wizard and exit + /// Only run the wizard and exit. /// Only, /// - /// Never run the wizard + /// Never run the wizard. /// Never } diff --git a/tests/Tgstation.Server.Tests/TestingServer.cs b/tests/Tgstation.Server.Tests/TestingServer.cs index a3181cf3cc..8962ce2d58 100644 --- a/tests/Tgstation.Server.Tests/TestingServer.cs +++ b/tests/Tgstation.Server.Tests/TestingServer.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Tgstation.Server.Host; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.Setup; namespace Tgstation.Server.Tests { From b0f9e2f3484dd2c58b7df277b31837aa5c9c09d5 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 11:57:24 -0500 Subject: [PATCH 05/12] Fix ServerFactory ignoring SetupWizardMode.Only --- src/Tgstation.Server.Host/IServerFactory.cs | 4 ++-- src/Tgstation.Server.Host/ServerFactory.cs | 5 +++++ tests/Tgstation.Server.Host.Tests/TestServerFactory.cs | 8 +++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Tgstation.Server.Host/IServerFactory.cs b/src/Tgstation.Server.Host/IServerFactory.cs index 2502a65906..1fd1eddee5 100644 --- a/src/Tgstation.Server.Host/IServerFactory.cs +++ b/src/Tgstation.Server.Host/IServerFactory.cs @@ -1,4 +1,4 @@ -using System.Threading; +using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.IO; @@ -20,7 +20,7 @@ namespace Tgstation.Server.Host /// The arguments for the /// The directory in which to install server updates /// The for the operation. - /// A resulting in a new + /// A resulting in a new if it should be run, otherwise. Task CreateServer(string[] args, string updatePath, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/ServerFactory.cs b/src/Tgstation.Server.Host/ServerFactory.cs index 701dea559c..2008459b9a 100644 --- a/src/Tgstation.Server.Host/ServerFactory.cs +++ b/src/Tgstation.Server.Host/ServerFactory.cs @@ -58,6 +58,11 @@ namespace Tgstation.Server.Host await setupHost.RunAsync(cancellationToken).ConfigureAwait(false); } + if (postSetupServices.GeneralConfiguration.SetupWizardMode == SetupWizardMode.Only) + { + return null; + } + var hostBuilder = CreateDefaultBuilder() .ConfigureWebHost(webHostBuilder => webHostBuilder diff --git a/tests/Tgstation.Server.Host.Tests/TestServerFactory.cs b/tests/Tgstation.Server.Host.Tests/TestServerFactory.cs index 07b454cb5f..6039e4e8f7 100644 --- a/tests/Tgstation.Server.Host.Tests/TestServerFactory.cs +++ b/tests/Tgstation.Server.Host.Tests/TestServerFactory.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; using System.Threading.Tasks; @@ -30,7 +30,8 @@ namespace Tgstation.Server.Host.Tests var factory = Application.CreateDefaultServerFactory(); await Assert.ThrowsExceptionAsync(() => factory.CreateServer(null, null, default)); - await factory.CreateServer(new[] { "General:SetupWizardMode=Never" }, null, default); + var result = await factory.CreateServer(new[] { "General:SetupWizardMode=Never" }, null, default); + Assert.IsNotNull(result); } [TestMethod] @@ -41,7 +42,8 @@ namespace Tgstation.Server.Host.Tests await Assert.ThrowsExceptionAsync(() => factory.CreateServer(null, null, default)); await Assert.ThrowsExceptionAsync(() => factory.CreateServer(null, Path, default)); - await factory.CreateServer(new[] { "General:SetupWizardMode=Never" }, Path, default); + var result = await factory.CreateServer(new[] { "General:SetupWizardMode=Never" }, Path, default); + Assert.IsNotNull(result); } } } From 49bfa5e6651bcc68b7282ff7af41be3456cf98aa Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 12:33:54 -0500 Subject: [PATCH 06/12] Add a small amount of logging to ServerFactory --- src/Tgstation.Server.Host/ServerFactory.cs | 14 ++++++++------ .../Setup/IPostSetupServices{TLoggerType}.cs | 16 ++++++++++++++++ .../Setup/PostSetupServices.cs | 16 +++++++++++++--- .../Setup/SetupApplication.cs | 4 ++-- 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 src/Tgstation.Server.Host/Setup/IPostSetupServices{TLoggerType}.cs diff --git a/src/Tgstation.Server.Host/ServerFactory.cs b/src/Tgstation.Server.Host/ServerFactory.cs index 2008459b9a..3a27b0eecc 100644 --- a/src/Tgstation.Server.Host/ServerFactory.cs +++ b/src/Tgstation.Server.Host/ServerFactory.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using System; using System.Threading; using System.Threading.Tasks; @@ -51,16 +52,17 @@ namespace Tgstation.Server.Host var setupWizardHostBuilder = CreateDefaultBuilder() .UseSetupApplication(); - IPostSetupServices postSetupServices; + IPostSetupServices postSetupServices; using (var setupHost = setupWizardHostBuilder.Build()) { - postSetupServices = setupHost.Services.GetRequiredService(); + postSetupServices = setupHost.Services.GetRequiredService>(); await setupHost.RunAsync(cancellationToken).ConfigureAwait(false); - } - if (postSetupServices.GeneralConfiguration.SetupWizardMode == SetupWizardMode.Only) - { - return null; + if (postSetupServices.GeneralConfiguration.SetupWizardMode == SetupWizardMode.Only) + { + postSetupServices.Logger.LogInformation("Shutting down due to only running setup wizard."); + return null; + } } var hostBuilder = CreateDefaultBuilder() diff --git a/src/Tgstation.Server.Host/Setup/IPostSetupServices{TLoggerType}.cs b/src/Tgstation.Server.Host/Setup/IPostSetupServices{TLoggerType}.cs new file mode 100644 index 0000000000..029ec74c55 --- /dev/null +++ b/src/Tgstation.Server.Host/Setup/IPostSetupServices{TLoggerType}.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.Logging; + +namespace Tgstation.Server.Host.Setup +{ + /// + /// with a . + /// + /// The category for . + interface IPostSetupServices : IPostSetupServices + { + /// + /// The . + /// + ILogger Logger { get; } + } +} diff --git a/src/Tgstation.Server.Host/Setup/PostSetupServices.cs b/src/Tgstation.Server.Host/Setup/PostSetupServices.cs index 48353fbb5b..f595e3ba65 100644 --- a/src/Tgstation.Server.Host/Setup/PostSetupServices.cs +++ b/src/Tgstation.Server.Host/Setup/PostSetupServices.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Options; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using System; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.System; @@ -6,7 +7,7 @@ using Tgstation.Server.Host.System; namespace Tgstation.Server.Host.Setup { /// - sealed class PostSetupServices : IPostSetupServices + sealed class PostSetupServices : IPostSetupServices { /// public IPlatformIdentifier PlatformIdentifier { get; } @@ -20,6 +21,9 @@ namespace Tgstation.Server.Host.Setup /// public FileLoggingConfiguration FileLoggingConfiguration => fileLoggingConfigurationOptions.Value; + /// + public ILogger Logger { get; } + /// /// Backing for . /// @@ -36,19 +40,25 @@ namespace Tgstation.Server.Host.Setup readonly IOptions fileLoggingConfigurationOptions; /// - /// Initializes a new instance of the . + /// Initializes a new instance of the . /// /// The value of . + /// The used to create . /// The containing the value of . /// The containing the value of . /// The containing the value of . public PostSetupServices( IPlatformIdentifier platformIdentifier, + ILoggerFactory loggerFactory, IOptions generalConfigurationOptions, IOptions databaseConfigurationOptions, IOptions fileLoggingConfigurationOptions) { PlatformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier)); + if (loggerFactory == null) + throw new ArgumentNullException(nameof(loggerFactory)); + + Logger = loggerFactory.CreateLogger(); this.generalConfigurationOptions = generalConfigurationOptions ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); this.databaseConfigurationOptions = databaseConfigurationOptions ?? throw new ArgumentNullException(nameof(databaseConfigurationOptions)); this.fileLoggingConfigurationOptions = fileLoggingConfigurationOptions ?? throw new ArgumentNullException(nameof(fileLoggingConfigurationOptions)); diff --git a/src/Tgstation.Server.Host/Setup/SetupApplication.cs b/src/Tgstation.Server.Host/Setup/SetupApplication.cs index 87548b1145..9f848efa8f 100644 --- a/src/Tgstation.Server.Host/Setup/SetupApplication.cs +++ b/src/Tgstation.Server.Host/Setup/SetupApplication.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Serilog.Events; @@ -73,7 +73,7 @@ namespace Tgstation.Server.Host.Setup /// The to configure. protected virtual void ConfigureHostedService(IServiceCollection services) { - services.AddSingleton(); + services.AddSingleton(typeof(IPostSetupServices<>), typeof(PostSetupServices<>)); services.AddSingleton(); } } From ad36b98d40062c85be9a73008f43146c72ff9d62 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 12:45:35 -0500 Subject: [PATCH 07/12] Fix potential deadlock in job startup --- src/Tgstation.Server.Host/Jobs/JobManager.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Tgstation.Server.Host/Jobs/JobManager.cs b/src/Tgstation.Server.Host/Jobs/JobManager.cs index 5066f0cdfb..891d4bc409 100644 --- a/src/Tgstation.Server.Host/Jobs/JobManager.cs +++ b/src/Tgstation.Server.Host/Jobs/JobManager.cs @@ -207,10 +207,9 @@ namespace Tgstation.Server.Host.Jobs try { lock (synchronizationLock) - { jobs.Add(job.Id, jobHandler); - jobHandler.Start(); - } + + jobHandler.Start(); } catch { From 526107a785ec8db8e8eb9a5d67a2607f12a8072f Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 13:12:39 -0500 Subject: [PATCH 08/12] Suppress yet another CA1506 --- src/Tgstation.Server.Host/ServerFactory.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Tgstation.Server.Host/ServerFactory.cs b/src/Tgstation.Server.Host/ServerFactory.cs index 3a27b0eecc..55bbd24e3a 100644 --- a/src/Tgstation.Server.Host/ServerFactory.cs +++ b/src/Tgstation.Server.Host/ServerFactory.cs @@ -40,6 +40,8 @@ namespace Tgstation.Server.Host } /// + // TODO: Decomplexify +#pragma warning disable CA1506 public async Task CreateServer(string[] args, string updatePath, CancellationToken cancellationToken) { if (args == null) @@ -88,5 +90,6 @@ namespace Tgstation.Server.Host return new Server(hostBuilder, updatePath); } +#pragma warning restore CA1506 } } From 2360bcbe0f1f188d6ec6933de44e7d618ed00350 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 14:25:02 -0500 Subject: [PATCH 09/12] Adding a safety CancellationToken check --- .../Components/Chat/Providers/IrcProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs index 02e413701a..911f95dc23 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs @@ -239,6 +239,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers protected override async Task Connect(CancellationToken cancellationToken) { disconnecting = false; + cancellationToken.ThrowIfCancellationRequested(); try { client.Connect(address, port); From 5284615c69a8862385df9a8501ce9c04a9baea60 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 14:30:22 -0500 Subject: [PATCH 10/12] Improve master version handling --- .../Components/Interop/DMApiConstants.cs | 8 +-- .../Interop/DMApiVersionAtrribute.cs | 25 ---------- .../Configuration/GeneralConfiguration.cs | 3 +- src/Tgstation.Server.Host/Core/Application.cs | 6 +++ .../Properties/MasterVersionsAttribute.cs | 50 +++++++++++++++++++ .../Tgstation.Server.Host.csproj | 10 ++-- 6 files changed, 66 insertions(+), 36 deletions(-) delete mode 100644 src/Tgstation.Server.Host/Components/Interop/DMApiVersionAtrribute.cs create mode 100644 src/Tgstation.Server.Host/Properties/MasterVersionsAttribute.cs diff --git a/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs b/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs index 4ece931574..9f3100ffa3 100644 --- a/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs +++ b/src/Tgstation.Server.Host/Components/Interop/DMApiConstants.cs @@ -1,8 +1,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using System; -using System.Reflection; using Tgstation.Server.Host.Components.Interop.Converters; +using Tgstation.Server.Host.Properties; namespace Tgstation.Server.Host.Components.Interop { @@ -34,11 +34,7 @@ namespace Tgstation.Server.Host.Components.Interop /// /// The DMAPI being used. /// - public static readonly Version Version = Version.Parse( - Assembly - .GetExecutingAssembly() - .GetCustomAttribute() - .RawDMApiVersion); + public static readonly Version Version = Version.Parse(MasterVersionsAttribute.Instance.RawDMApiVersion); /// /// for use when communicating with the DMAPI. diff --git a/src/Tgstation.Server.Host/Components/Interop/DMApiVersionAtrribute.cs b/src/Tgstation.Server.Host/Components/Interop/DMApiVersionAtrribute.cs deleted file mode 100644 index be4a05a0c3..0000000000 --- a/src/Tgstation.Server.Host/Components/Interop/DMApiVersionAtrribute.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Tgstation.Server.Host.Components.Interop -{ - /// - /// Attribute for bringing in the from MSBuild. - /// - [AttributeUsage(AttributeTargets.Assembly)] - sealed class DMApiVersionAtrribute : Attribute - { - /// - /// The string of the DMAPI version built. - /// - public string RawDMApiVersion { get; } - - /// - /// Initializes a new instance of the . - /// - /// The value of . - public DMApiVersionAtrribute(string rawDMApiVersion) - { - RawDMApiVersion = rawDMApiVersion ?? throw new ArgumentNullException(nameof(rawDMApiVersion)); - } - } -} diff --git a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs index a806ea56f7..e58c8d036e 100644 --- a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs +++ b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; using Tgstation.Server.Api.Models.Internal; +using Tgstation.Server.Host.Properties; using Tgstation.Server.Host.Setup; namespace Tgstation.Server.Host.Configuration @@ -25,7 +26,7 @@ namespace Tgstation.Server.Host.Configuration /// /// The current . /// - public static readonly Version CurrentConfigVersion = new Version(2, 1, 0); + public static readonly Version CurrentConfigVersion = Version.Parse(MasterVersionsAttribute.Instance.RawConfigurationVersion); /// /// The default value for . diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index e8c6f11a48..b344c2a85d 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -35,6 +35,7 @@ using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Extensions; using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; +using Tgstation.Server.Host.Properties; using Tgstation.Server.Host.Security; using Tgstation.Server.Host.Setup; using Tgstation.Server.Host.System; @@ -433,6 +434,11 @@ namespace Tgstation.Server.Host.Core else logger.LogDebug("Web control panel disabled!"); + var masterVersionsAttribute = MasterVersionsAttribute.Instance; + logger.LogTrace("Configuration version: {0}", masterVersionsAttribute.RawConfigurationVersion); + logger.LogTrace("DMAPI version: {0}", masterVersionsAttribute.RawDMApiVersion); + logger.LogTrace("Web control panel version: {0}", masterVersionsAttribute.RawControlPanelVersion); + logger.LogDebug("Starting hosting..."); // authenticate JWT tokens using our security pipeline if present, returns 401 if bad diff --git a/src/Tgstation.Server.Host/Properties/MasterVersionsAttribute.cs b/src/Tgstation.Server.Host/Properties/MasterVersionsAttribute.cs new file mode 100644 index 0000000000..20cc04786c --- /dev/null +++ b/src/Tgstation.Server.Host/Properties/MasterVersionsAttribute.cs @@ -0,0 +1,50 @@ +using System; +using System.Reflection; + +namespace Tgstation.Server.Host.Properties +{ + /// + /// Attribute for bringing in the master versions list from MSBuild that aren't embedded into assemblies by default. + /// + [AttributeUsage(AttributeTargets.Assembly)] + sealed class MasterVersionsAttribute : Attribute + { + /// + /// Return the 's instance of the . + /// + public static MasterVersionsAttribute Instance => Assembly + .GetExecutingAssembly() + .GetCustomAttribute(); + + /// + /// The of the version built. + /// + public string RawConfigurationVersion { get; } + + /// + /// The of the DMAPI version built. + /// + public string RawDMApiVersion { get; } + + /// + /// The of the control panel version built. + /// + public string RawControlPanelVersion { get; } + + /// + /// Initializes a new instance of the . + /// + /// The value of . + /// The value of . + /// The value of . + public MasterVersionsAttribute( + string rawConfigurationVersion, + string rawDMApiVersion, + string rawControlPanelVersion) + { + RawConfigurationVersion = rawConfigurationVersion ?? throw new ArgumentNullException(nameof(rawConfigurationVersion)); + RawDMApiVersion = rawDMApiVersion ?? throw new ArgumentNullException(nameof(rawDMApiVersion)); + RawControlPanelVersion = rawControlPanelVersion ?? throw new ArgumentNullException(nameof(rawControlPanelVersion)); + } + } +} diff --git a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj index bee26f447e..351989b019 100644 --- a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj +++ b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj @@ -41,14 +41,16 @@ - + - - <_Parameter1>$(TgsDmapiVersion) + + <_Parameter1>$(TgsConfigVersion) + <_Parameter2>$(TgsDmapiVersion) + <_Parameter3>$(TgsControlPanelVersion) - + From 207f749c078cb5603ba56df78d250fcc82bd2f4b Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 3 Nov 2020 16:42:06 -0500 Subject: [PATCH 11/12] Reposition some code --- src/Tgstation.Server.Host/Core/Application.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index b344c2a85d..0b78c9c1bd 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -434,13 +434,6 @@ namespace Tgstation.Server.Host.Core else logger.LogDebug("Web control panel disabled!"); - var masterVersionsAttribute = MasterVersionsAttribute.Instance; - logger.LogTrace("Configuration version: {0}", masterVersionsAttribute.RawConfigurationVersion); - logger.LogTrace("DMAPI version: {0}", masterVersionsAttribute.RawDMApiVersion); - logger.LogTrace("Web control panel version: {0}", masterVersionsAttribute.RawControlPanelVersion); - - logger.LogDebug("Starting hosting..."); - // authenticate JWT tokens using our security pipeline if present, returns 401 if bad applicationBuilder.UseAuthentication(); @@ -451,6 +444,14 @@ namespace Tgstation.Server.Host.Core applicationBuilder.UseMvc(); // 404 anything that gets this far + // End of request pipeline setup + + var masterVersionsAttribute = MasterVersionsAttribute.Instance; + logger.LogTrace("Configuration version: {0}", masterVersionsAttribute.RawConfigurationVersion); + logger.LogTrace("DMAPI version: {0}", masterVersionsAttribute.RawDMApiVersion); + logger.LogTrace("Web control panel version: {0}", masterVersionsAttribute.RawControlPanelVersion); + + logger.LogDebug("Starting hosting..."); } } } From 1309e8aa4387b506db0e33a92cfa32e65e0eb589 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Wed, 4 Nov 2020 09:56:23 -0500 Subject: [PATCH 12/12] Fix StyleCop warning --- src/Tgstation.Server.Host/Core/Application.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 0b78c9c1bd..8656493f63 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -445,7 +445,6 @@ namespace Tgstation.Server.Host.Core // 404 anything that gets this far // End of request pipeline setup - var masterVersionsAttribute = MasterVersionsAttribute.Instance; logger.LogTrace("Configuration version: {0}", masterVersionsAttribute.RawConfigurationVersion); logger.LogTrace("DMAPI version: {0}", masterVersionsAttribute.RawDMApiVersion);