Skip to content

Commit 64ccaa4

Browse files
Adds debug logging to config manager
Adds debug logging to the service config manager to assist with troubleshooting configuration loading issues. This change adds logging for scenarios where the config file is empty, not found, or fails to load. Improves diagnostic logging and fixes typo Updates logging to use Console.WriteLine instead of Debug.WriteLine for better visibility. Includes server config status in HTTP challenge server logs. Corrects a typo in the CLI help text for backup import. Handles exceptions when loading service config Improves the robustness of the service configuration loading process by catching potential exceptions. Specifically, it catches exceptions when attempting to access the AppData path and unauthorized access exceptions when reading the service configuration file. This prevents the service from crashing and provides more informative error messages to the user. Fixes server connection configuration. Ensures the client uses the provided connection configuration or defaults to the service configuration. Adds logging to display the service configuration for debugging. Adds debug logging for config loading Adds logging statements to the API client and service config manager to aid in debugging configuration loading issues. This helps track the base URI and service config file paths used by the application.
1 parent 592e7ae commit 64ccaa4

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

src/Certify.CLI/Certify.CLI.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<ProjectReference Include="..\Certify.Client\Certify.Client.csproj" />
5353
<ProjectReference Include="..\Certify.Locales\Certify.Locales.csproj" />
5454
<ProjectReference Include="..\Certify.Models\Certify.Models.csproj" />
55+
56+
<TrimmerRootAssembly Include="Certify.Models" />
57+
<TrimmerRootAssembly Include="Certify.Client" />
5558
</ItemGroup>
5659

5760
<ItemGroup>

src/Certify.CLI/CertifyCLI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ internal void ShowHelp()
108108
System.Console.WriteLine("certify credential list : list current stored credential summary information");
109109
System.Console.WriteLine("certify activate <email address> <key> : activate your Certify The Web install using your license key");
110110
System.Console.WriteLine("certify backup export <directory or full filename> <encryption secret> : export a backup file (autonamed if a directory) using the given secret password for encryption.");
111-
System.Console.WriteLine("certify backup import preview <full filename> <encryption secret> : import a backup file using the given secret password for encryption. 'preview' is optional and us used to test a backup without importing anything.");
111+
System.Console.WriteLine("certify backup import preview <full filename> <encryption secret> : import a backup file using the given secret password for encryption. 'preview' is optional and is used to test a backup without importing anything.");
112112
System.Console.WriteLine("\n\n");
113113
System.Console.WriteLine("For help, see the docs at https://docs.certifytheweb.com");
114114

src/Certify.Client/CertifyApiClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ public partial class CertifyApiClient : ICertifyInternalApiClient
7171
internal string _accessToken { get; set; } = "";
7272
internal string _refreshToken { get; set; } = "";
7373

74-
public CertifyApiClient(Providers.IServiceConfigProvider configProvider, Shared.ServerConnection config = null)
74+
public CertifyApiClient(Providers.IServiceConfigProvider configProvider, Shared.ServerConnection connectionConfig = null)
7575
{
7676
_configProvider = configProvider;
77-
_connectionConfig = config ?? GetDefaultServerConnection();
77+
78+
_connectionConfig = connectionConfig ?? new ServerConnection(configProvider.GetServiceConfig());
7879

7980
_baseUri = $"{(_connectionConfig.UseHTTPS ? "https" : "http")}://{_connectionConfig.Host}:{_connectionConfig.Port}" + _baseUri;
8081

@@ -129,6 +130,7 @@ private void SetClientAuthorizationBearerToken()
129130
public ServerConnection GetDefaultServerConnection()
130131
{
131132
var serviceCfg = _configProvider.GetServiceConfig();
133+
132134
return new ServerConnection(serviceCfg);
133135
}
134136

src/Certify.Shared/Utils/HttpChallengeServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public bool Start(ServiceConfig serverConfig, string controlKey = null, string c
146146

147147
Log($"Http Challenge Server Started: {uriPrefix}", true);
148148
Log($"Control Key: {_controlKey}: Check Key: {_checkKey}");
149-
Log($"Using Internal API: {_baseUri}");
149+
Log($"Using Internal API: {_baseUri} {serverConfig.ConfigStatus}");
150150

151151
_ = Task.Run(ServerTask);
152152

src/Certify.Shared/Utils/ServiceConfigManager.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ public static ServiceConfig GetAppServiceConfig()
2020
ConfigStatus = ConfigStatus.DefaultFailed
2121
};
2222

23-
var appDataPath = EnvironmentUtil.EnsuredAppDataPath();
23+
var appDataPath = string.Empty;
24+
try
25+
{
26+
appDataPath = EnvironmentUtil.EnsuredAppDataPath();
27+
}
28+
catch (Exception exp)
29+
{
30+
System.Console.WriteLine($"ServiceConfigManager: Failed to get AppData path. {exp.Message}");
31+
serviceConfig.ServiceFaultMsg = $"Failed to get AppData path. {exp.Message}";
32+
return serviceConfig;
33+
}
34+
2435
var serviceConfigFile = Path.Combine(appDataPath, "serviceconfig.json");
2536
#if DEBUG
2637
serviceConfigFile = Path.Combine(appDataPath, "serviceconfig.debug.json");
@@ -34,26 +45,42 @@ public static ServiceConfig GetAppServiceConfig()
3445
{
3546
serviceConfig = JsonConvert.DeserializeObject<ServiceConfig>(config);
3647
}
48+
else
49+
{
50+
System.Console.WriteLine($"ServiceConfigManager: Empty service config found at {serviceConfigFile}");
51+
}
3752

3853
serviceConfig.ConfigStatus = ConfigStatus.NotModified;
3954
}
4055
else
4156
{
4257
serviceConfig.ConfigStatus = ConfigStatus.New;
58+
System.Console.WriteLine($"ServiceConfigManager: No service config found at {serviceConfigFile}");
4359
}
4460
}
61+
catch (UnauthorizedAccessException uaExp)
62+
{
63+
serviceConfig.ConfigStatus = ConfigStatus.DefaultFailed;
64+
serviceConfig.ServiceFaultMsg = $"Access denied to service configuration file at {serviceConfigFile}. {uaExp.Message}";
65+
System.Console.WriteLine($"ServiceConfigManager: {serviceConfig.ServiceFaultMsg}");
66+
}
4567
catch (Exception exp)
4668
{
4769
if (serviceConfig != null)
4870
{
4971
serviceConfig.ConfigStatus = ConfigStatus.DefaultFailed;
5072
serviceConfig.ServiceFaultMsg = $"There was a problem loading the service configuration from {serviceConfigFile} {exp.Message}";
5173
}
74+
else
75+
{
76+
System.Diagnostics.Debug.WriteLine($"ServiceConfigManager: Fault loading service config found at {exp}");
77+
}
5278
}
5379

5480
// if something went wrong, default to standard config
5581
if (serviceConfig == null)
5682
{
83+
System.Console.WriteLine($"ServiceConfigManager: Falling back to default service config.");
5784
serviceConfig = new ServiceConfig()
5885
{
5986
ConfigStatus = ConfigStatus.DefaultFailed

0 commit comments

Comments
 (0)