Skip to content

Commit

Permalink
fix(installer): fix parsing errors with configuration check (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
thenextman authored Jun 18, 2024
1 parent b0d81c6 commit 4f89688
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
23 changes: 15 additions & 8 deletions package/WindowsManaged/Actions/CustomActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,11 @@ bool CheckAccess(string path, FileAccess desiredAccess, bool isDirectory)

using (Impersonation _ = new Impersonation(userDomain[1], userDomain[0], string.Empty))
{
if (!TryReadGatewayConfig(session, out config))
string configPath = Path.Combine(ProgramDataDirectory, GatewayConfigFile);

if (!TryReadGatewayConfig(session, configPath, out config, out Exception e))
{
results[configPath] = (false, FileAccess.Read, e);
session.Log("failed to load or parse the configuration file");
}

Expand Down Expand Up @@ -700,6 +703,7 @@ bool CheckAccess(string path, FileAccess desiredAccess, bool isDirectory)
}
catch (Exception e)
{
results["Not applicable"] = (false, FileAccess.None, e);
session.Log($"unexpected error while checking configuration: {e}");
result = ActionResult.Failure;
}
Expand Down Expand Up @@ -1350,36 +1354,39 @@ private static bool TryGetPowerShellVersion(out Version powerShellVersion)
return Version.TryParse(version, out powerShellVersion);
}

internal static bool TryReadGatewayConfig(ILogger logger, out Gateway gatewayConfig)
internal static bool TryReadGatewayConfig(ILogger logger, string path, out Gateway gatewayConfig, out Exception error)
{
gatewayConfig = new Gateway();
string configPath = Path.Combine(ProgramDataDirectory, GatewayConfigFile);

if (!File.Exists(configPath))
if (!File.Exists(path))
{
error = new FileNotFoundException(path);
return false;
}

try
{
using StreamReader reader = new StreamReader(configPath);
using StreamReader reader = new StreamReader(path);
using JsonReader jsonReader = new JsonTextReader(reader);

JsonSerializer serializer = new JsonSerializer();
gatewayConfig = serializer.Deserialize<Gateway>(jsonReader);

error = null;

return true;
}
catch (Exception e)
{
logger.Log($"failed to load configuration file at {configPath}: {e}");
logger.Log($"failed to load configuration file at {path}: {e}");
error = e;
return false;
}
}

internal static bool TryReadGatewayConfig(Session session, out Gateway gatewayConfig)
internal static bool TryReadGatewayConfig(Session session, string path, out Gateway gatewayConfig, out Exception error)
{
return TryReadGatewayConfig(LogDelegate.WithSession(session), out gatewayConfig);
return TryReadGatewayConfig(LogDelegate.WithSession(session), path, out gatewayConfig, out error);
}
}
}
1 change: 1 addition & 0 deletions package/WindowsManaged/Actions/FileAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace DevolutionsGateway.Actions
{
internal enum FileAccess
{
None,
Read,
Write,
Modify,
Expand Down
4 changes: 2 additions & 2 deletions package/WindowsManaged/Configuration/Ngrok.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class Ngrok
{
public string AuthToken { get; set; }

public int HeartbeatInterval { get; set; }
public int? HeartbeatInterval { get; set; }

public int HeartbeatTolerance { get; set; }
public int? HeartbeatTolerance { get; set; }

public string Metadata { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions package/WindowsManaged/Configuration/WebApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public class WebApp

public string Authentication { get; set; }

public int AppTokenMaximumLifetime { get; set; }
public int? AppTokenMaximumLifetime { get; set; }

public int LoginLimitRate { get; set; }
public int? LoginLimitRate { get; set; }

[DefaultValue(Actions.CustomActions.DefaultUsersFile)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
Expand Down

0 comments on commit 4f89688

Please sign in to comment.