Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelvds committed Jan 29, 2024
1 parent e5d0842 commit 55afd78
Showing 1 changed file with 51 additions and 12 deletions.
63 changes: 51 additions & 12 deletions src/fiskaltrust.Launcher/Commands/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,8 @@ public static async Task<int> HandleAsync<O, S>(
var cashboxConfiguration = new ftCashBoxConfiguration();
try
{
cashboxConfiguration =
CashBoxConfigurationExt.Deserialize(
await File.ReadAllTextAsync(launcherConfiguration.CashboxConfigurationFile!));
if (clientEcdh is not null)
{
cashboxConfiguration.Decrypt(launcherConfiguration, clientEcdh);
}
cashboxConfiguration = CashBoxConfigurationExt.Deserialize(await File.ReadAllTextAsync(launcherConfiguration.CashboxConfigurationFile!));
if (clientEcdh is not null) { cashboxConfiguration.Decrypt(launcherConfiguration, clientEcdh); }
}
catch (Exception e)
{
Expand Down Expand Up @@ -257,8 +252,7 @@ public static async Task<int> HandleAsync<O, S>(
launcherConfiguration.CashboxConfigurationFile);
Log.Debug("Launcher Configuration: {@LauncherConfiguration}", launcherConfiguration.Redacted());

Log.Debug("Launcher running as {ServiceType}",
Enum.GetName(typeof(ServiceTypes), host.Services.GetRequiredService<ServiceType>().Type));
Log.Debug("Launcher running as {ServiceType}", Enum.GetName(typeof(ServiceTypes), host.Services.GetRequiredService<ServiceType>().Type));

var dataProtectionProvider = DataProtectionExtensions.Create(launcherConfiguration.AccessToken,
useFallback: launcherConfiguration.UseLegacyDataProtection!.Value);
Expand All @@ -273,9 +267,54 @@ public static async Task<int> HandleAsync<O, S>(
Log.Warning(e, "Error decrypring launcher configuration file.");
}

return await handler(options,
new CommonProperties(launcherConfiguration, cashboxConfiguration, clientEcdh!, dataProtectionProvider),
specificOptions, host.Services.GetRequiredService<S>());
return await handler(options, new CommonProperties(launcherConfiguration, cashboxConfiguration, clientEcdh!, dataProtectionProvider), specificOptions, host.Services.GetRequiredService<S>());
}

private static async Task EnsureServiceDirectoryExists(LauncherConfiguration config)
{
var serviceDirectory = config.ServiceFolder!;
try
{
if (!Directory.Exists(serviceDirectory))
{
Directory.CreateDirectory(serviceDirectory);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var user = Environment.GetEnvironmentVariable("USER");
if (!string.IsNullOrEmpty(user))
{
var chownResult = await ProcessHelper.RunProcess("chown", new[] { user, serviceDirectory }, LogEventLevel.Debug);
if (chownResult.exitCode != 0)
{
Log.Warning("Failed to change owner of the service directory.");
}

var chmodResult = await ProcessHelper.RunProcess("chmod", new[] { "774", serviceDirectory }, LogEventLevel.Debug);
if (chmodResult.exitCode != 0)
{
Log.Warning("Failed to change permissions of the service directory.");
}
}
else
{
Log.Warning(
"Service user name is not set. Owner of the service directory will not be changed.");
}
}
else
{
Log.Debug("Changing owner and permissions is skipped on non-Unix operating systems.");
}
}
}
catch (UnauthorizedAccessException e)
{
// will exit with non-zero exit code later.
Log.Fatal(e,
"Access to the path '{ServiceDirectory}' is denied. Please run the application with sufficient permissions.", serviceDirectory);
}
}

private static async Task EnsureServiceDirectoryExists(LauncherConfiguration config)
Expand Down

0 comments on commit 55afd78

Please sign in to comment.