Skip to content

Commit 454e7d6

Browse files
Refactors Management Hub configuration
Consolidates Management Hub configuration settings into the ServiceConfig class for better organization and access. Removes the `IsManagementHubService` property from `CoreAppSettings` and replaces it with `IsManagementHub` in `ServiceConfig`. Ensures that the Management Hub functionality is consistently enabled based on the new configuration properties. Improves error messaging for Management Hub joining authentication failures, clarifying potential causes.
1 parent 6f87aa1 commit 454e7d6

File tree

4 files changed

+7
-16
lines changed

4 files changed

+7
-16
lines changed

src/Certify.Core/Management/CertifyManager/CertifyManager.Maintenance.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private async Task UpgradeSettings()
2626

2727
if (
2828
Environment.GetEnvironmentVariable("CERTIFY_ENABLE_MANAGEMENT_HUB")?.Equals("true", StringComparison.InvariantCultureIgnoreCase) == true
29-
|| CoreAppSettings.Current.IsManagementHubService
29+
|| _serverConfig.IsManagementHub
3030
|| _isDirectMgmtHubBackend
3131
)
3232
{
@@ -47,15 +47,10 @@ private async Task UpgradeSettings()
4747
// update the system version
4848
CoreAppSettings.Current.CurrentServiceVersion = systemVersion;
4949

50-
if (_isMgtmHubBackend)
51-
{
52-
CoreAppSettings.Current.IsManagementHubService = true;
53-
}
54-
5550
SettingsManager.SaveAppSettings();
5651

5752
// if we are a management hub backend, register with the hub if not already registered
58-
if (CoreAppSettings.Current.IsManagementHubService)
53+
if (_isMgtmHubBackend)
5954
{
6055
var accessControl = await GetCurrentAccessControl();
6156
await AccessControlConfig.ConfigureStandardUsersAndRoles(accessControl, _credentialsManager);

src/Certify.Core/Management/CertifyManager/CertifyManager.ManagementHub.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,16 @@ await _credentialsManager.Update(new StoredCredential
126126
/// <returns>Returns an action result indicating the success of the connection attempt and any relevant hub information.</returns>
127127
public async Task<ActionResult<HubJoiningInfo>> CheckManagementHubCredentials(string url, ClientSecret clientSecret, bool registerInstance = false)
128128
{
129-
var hubAssignedInstanceId = _serverConfig.HubAssignedInstanceId;
130129

131130
using (var httpClient = new System.Net.Http.HttpClient())
132131
{
133132
var request = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, $"{url.TrimEnd('/')}/api/v1/hub/{(registerInstance ? "register" : "joincheck")}");
134133
request.Headers.Add("X-Client-ID", clientSecret.ClientId);
135134
request.Headers.Add("X-Client-Secret", clientSecret.Secret);
136135

137-
if (!string.IsNullOrEmpty(hubAssignedInstanceId))
136+
if (!string.IsNullOrEmpty(_serverConfig.HubAssignedInstanceId))
138137
{
139-
request.Headers.Add("X-Certify-HubAssignedId", hubAssignedInstanceId);
138+
request.Headers.Add("X-Certify-HubAssignedId", _serverConfig.HubAssignedInstanceId);
140139
}
141140

142141
try
@@ -318,6 +317,7 @@ private async Task EnsureMgmtHubConnection()
318317

319318
// acquire new token
320319
var check = await CheckManagementHubCredentials(api, _mgmtHubJoiningSecret);
320+
321321
if (check.IsSuccess)
322322
{
323323
if (_serverConfig.HubAssignedInstanceId != check.Result.HubAssignedInstanceId)
@@ -351,7 +351,7 @@ private async Task EnsureMgmtHubConnection()
351351
SystemStatusCategories.SERVICE_CORE,
352352
SystemStatusKeys.SERVICE_CORE_HUB_JOINING_AUTH,
353353
"Management Hub Joining Auth",
354-
"Management hub joining auth failed, instance cannot join hub. Joining key may be invalid or for a different hub.",
354+
"Management hub joining auth failed, instance cannot join hub. Joining key (or current Hub Assigned ID) may be invalid or for a different hub.",
355355
hasError: true
356356
);
357357

src/Certify.Core/Management/SettingsManager.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ public static CoreAppSettings Current
185185
/// If true, ARI checks will not be performed during periodic maintenance
186186
/// </summary>
187187
public bool DisableARIChecks { get; set; }
188-
189-
/// <summary>
190-
/// if true, additional management hub features and data stores may be enabled
191-
/// </summary>
192-
public bool IsManagementHubService { get; set; }
193188
}
194189

195190
public class SettingsManager

src/Certify.Models/Shared/ServiceConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ServiceConfig
3737
public string ManagementServerHubAPI { get; set; } = string.Empty;
3838
public string ManagementServerHubEndpoint { get; set; } = string.Empty;
3939
public string HubAssignedInstanceId { get; set; } = string.Empty;
40+
public bool IsManagementHub { get; set; }
4041
}
4142

4243
public enum ConfigStatus

0 commit comments

Comments
 (0)