Skip to content

Commit

Permalink
Merge pull request #103 from qJake/v1.1-prep
Browse files Browse the repository at this point in the history
Additional v1.1 prep
  • Loading branch information
qJake authored Aug 11, 2020
2 parents 770d762 + b2d070a commit 45030f7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Docker/BuildHaccContainers.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$version = '1.0.19'
$version = '1.0.21'

function Test-ExitCode ([int] $Expected = 0)
{
Expand Down
4 changes: 2 additions & 2 deletions HADotNet.CommandCenter/HADotNet.CommandCenter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<RuntimeIdentifiers>win10;alpine.3.10-x64;debian.10-arm</RuntimeIdentifiers>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<AssemblyVersion>1.0.20.0</AssemblyVersion>
<FileVersion>1.0.20.0</FileVersion>
<AssemblyVersion>1.0.21.0</AssemblyVersion>
<FileVersion>1.0.21.0</FileVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Deterministic>false</Deterministic>
Expand Down
36 changes: 33 additions & 3 deletions HADotNet.CommandCenter/Services/JsonConfigStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> haccOptions)
public JsonConfigStore(IOptions<HaccOptions> 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<ConfigRoot>[] changes)
Expand All @@ -63,6 +69,30 @@ public async Task<ConfigRoot> 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<ConfigRoot>(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();
Expand Down
2 changes: 2 additions & 0 deletions HADotNet.CommandCenter/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 45030f7

Please sign in to comment.