From 49d9e1f0f9915593f53103c44d8dcec5276e9c72 Mon Sep 17 00:00:00 2001 From: qJake Date: Mon, 10 Aug 2020 22:01:17 -0500 Subject: [PATCH 1/2] Additional Launch Prep --- Docker/BuildHaccContainers.ps1 | 2 +- .../Services/JsonConfigStore.cs | 36 +++++++++++++++++-- HADotNet.CommandCenter/Startup.cs | 2 ++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Docker/BuildHaccContainers.ps1 b/Docker/BuildHaccContainers.ps1 index 2f26dc7..e33b23c 100644 --- a/Docker/BuildHaccContainers.ps1 +++ b/Docker/BuildHaccContainers.ps1 @@ -1,4 +1,4 @@ -$version = '1.0.18' +$version = '1.0.21' function Test-ExitCode ([int] $Expected = 0) { diff --git a/HADotNet.CommandCenter/Services/JsonConfigStore.cs b/HADotNet.CommandCenter/Services/JsonConfigStore.cs index 0884b8e..4935c43 100644 --- a/HADotNet.CommandCenter/Services/JsonConfigStore.cs +++ b/HADotNet.CommandCenter/Services/JsonConfigStore.cs @@ -4,6 +4,7 @@ using HADotNet.CommandCenter.Models.Config.Themes; using HADotNet.CommandCenter.Services.Interfaces; using HADotNet.CommandCenter.Utils; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -34,13 +35,18 @@ public class JsonConfigStore : IConfigStore private bool IsValid { get; set; } private string ConfigDirectory { get; set; } + private string OldLinuxConfigPath => Path.Combine(".", CONFIG_FILE); private string ConfigPath => Path.Combine(ConfigDirectory, CONFIG_FILE); - public HaccOptions Options { get; } + private HaccOptions Options { get; } + private ILogger Log { get; } - public JsonConfigStore(IOptions haccOptions) + public JsonConfigStore(IOptions haccOptions, ILogger log) { Options = haccOptions.Value; - ConfigDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Options.ConfigLocation == "." ? LINUX_DATA_LOCATION : Environment.ExpandEnvironmentVariables(Options.ConfigLocation); + ConfigDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && Options.ConfigLocation == "." + ? LINUX_DATA_LOCATION + : Environment.ExpandEnvironmentVariables(Options.ConfigLocation); + Log = log; } public async Task ManipulateConfig(params Action[] changes) @@ -63,6 +69,30 @@ public async Task GetConfigAsync() { if (CheckPermissions()) { + // One-time config Linux platform migration + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && File.Exists(OldLinuxConfigPath) && !File.Exists(ConfigPath)) + { + try + { + var oldContents = await File.ReadAllTextAsync(ConfigPath); + var oldCfg = JsonConvert.DeserializeObject(oldContents, SerializerSettings); + try + { + File.Delete(OldLinuxConfigPath); + } + catch (Exception ex) + { + Log.LogWarning(ex, "Unable to delete old configuration store location. Subsequent app runs may cause issues."); + } + Log.LogInformation("Successfully loaded legacy configuration path for migration."); + return oldCfg; + } + catch (Exception ex) + { + Log.LogWarning(ex, "Unable to read old configuration store for migration. Configuration will be blank."); + } + } + if (!File.Exists(ConfigPath)) { return new ConfigRoot(); diff --git a/HADotNet.CommandCenter/Startup.cs b/HADotNet.CommandCenter/Startup.cs index 9d4d2cf..d173128 100644 --- a/HADotNet.CommandCenter/Startup.cs +++ b/HADotNet.CommandCenter/Startup.cs @@ -49,6 +49,8 @@ public void ConfigureServices(IServiceCollection services) l.SetMinimumLevel(LogLevel.Information); l.AddFilter("Microsoft", LogLevel.Error); l.AddFilter("System", LogLevel.Warning); + // This complains about the antiforgery token once on EVERY app startup, not sure why + l.AddFilter("Microsoft.AspNetCore.Antiforgery", LogLevel.None); } }); services.AddOptions(); From 49d327663d5982048eaf75b2acba5a0ad78548eb Mon Sep 17 00:00:00 2001 From: qJake Date: Mon, 10 Aug 2020 22:03:21 -0500 Subject: [PATCH 2/2] v1.0.21 --- HADotNet.CommandCenter/HADotNet.CommandCenter.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HADotNet.CommandCenter/HADotNet.CommandCenter.csproj b/HADotNet.CommandCenter/HADotNet.CommandCenter.csproj index c238d24..fec75f2 100644 --- a/HADotNet.CommandCenter/HADotNet.CommandCenter.csproj +++ b/HADotNet.CommandCenter/HADotNet.CommandCenter.csproj @@ -5,8 +5,8 @@ win10;alpine.3.10-x64;debian.10-arm Latest Linux - 1.0.20.0 - 1.0.20.0 + 1.0.21.0 + 1.0.21.0 false false false