diff --git a/package/WindowsManaged/Actions/CustomActions.cs b/package/WindowsManaged/Actions/CustomActions.cs index 58ba77fbb..c5517344b 100644 --- a/package/WindowsManaged/Actions/CustomActions.cs +++ b/package/WindowsManaged/Actions/CustomActions.cs @@ -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"); } @@ -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; } @@ -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(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); } } } diff --git a/package/WindowsManaged/Actions/FileAccess.cs b/package/WindowsManaged/Actions/FileAccess.cs index 8ccc0f421..bcabf90f5 100644 --- a/package/WindowsManaged/Actions/FileAccess.cs +++ b/package/WindowsManaged/Actions/FileAccess.cs @@ -9,6 +9,7 @@ namespace DevolutionsGateway.Actions { internal enum FileAccess { + None, Read, Write, Modify, diff --git a/package/WindowsManaged/Configuration/Ngrok.cs b/package/WindowsManaged/Configuration/Ngrok.cs index dbe17f0b4..2c333e023 100644 --- a/package/WindowsManaged/Configuration/Ngrok.cs +++ b/package/WindowsManaged/Configuration/Ngrok.cs @@ -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; } diff --git a/package/WindowsManaged/Configuration/WebApp.cs b/package/WindowsManaged/Configuration/WebApp.cs index 902895886..8813ac3f1 100644 --- a/package/WindowsManaged/Configuration/WebApp.cs +++ b/package/WindowsManaged/Configuration/WebApp.cs @@ -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)]