Skip to content

Commit

Permalink
Merge pull request #59 from Lombiq/issue/NEST-326
Browse files Browse the repository at this point in the history
NEST-326: Fix: Maintenance to update staging tenant bindings after DB replace
  • Loading branch information
wAsnk authored May 18, 2023
2 parents 1f12dd4 + 3ac6cc4 commit 333781e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
15 changes: 7 additions & 8 deletions Lombiq.Hosting.Tenants.Maintenance/Helpers/TenantUrlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ public static string ReplaceTenantName(string url, string tenantName) =>
url?.Replace("{TenantName}", tenantName.ToLowerInvariant());
#pragma warning restore CA1308 // Normalize strings to uppercase

public static string GetTenantUrl(string urlForDefaultTenant, string urlForAnyTenant, ShellSettings shellSettings)
public static string GetEvaluatedValueForTenant(
string valueForDefaultTenant,
string valueForAnyTenant,
ShellSettings shellSettings)
{
var evaluatedRequestUrl = !string.IsNullOrEmpty(urlForAnyTenant)
? ReplaceTenantName(urlForAnyTenant, shellSettings.Name)
var evaluatedValue = !string.IsNullOrEmpty(valueForAnyTenant)
? ReplaceTenantName(valueForAnyTenant, shellSettings.Name)
: string.Empty;
var defaultShellRequestUrl =
string.IsNullOrEmpty(urlForDefaultTenant)
? evaluatedRequestUrl
: urlForDefaultTenant;

return shellSettings.IsDefaultShell() ? defaultShellRequestUrl : evaluatedRequestUrl;
return shellSettings.IsDefaultShell() ? valueForDefaultTenant : evaluatedValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public class UpdateShellRequestUrlMaintenanceOptions
public string DefaultShellRequestUrl { get; set; }
public string RequestUrl { get; set; }
public string RequestUrlPrefix { get; set; }
public string DefaultShellRequestUrlPrefix { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context)
var allShellSettings = await _shellSettingsManager.LoadSettingsAsync();
foreach (var shellSettings in allShellSettings)
{
shellSettings.RequestUrlHost = TenantUrlHelpers.GetTenantUrl(
shellSettings.RequestUrlHost = TenantUrlHelpers.GetEvaluatedValueForTenant(
_options.Value.DefaultShellRequestUrl,
_options.Value.RequestUrl,
shellSettings);
shellSettings.RequestUrlPrefix = TenantUrlHelpers.ReplaceTenantName(
shellSettings.RequestUrlPrefix = TenantUrlHelpers.GetEvaluatedValueForTenant(
_options.Value.DefaultShellRequestUrlPrefix,
_options.Value.RequestUrlPrefix,
shellSettings.Name);
shellSettings);

await _shellSettingsManager.SaveSettingsAsync(shellSettings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override Task<bool> ShouldExecuteAsync(MaintenanceTaskExecutionContext co
public override async Task ExecuteAsync(MaintenanceTaskExecutionContext context)
{
var siteSettings = await _siteService.LoadSiteSettingsAsync();
siteSettings.BaseUrl = TenantUrlHelpers.GetTenantUrl(
siteSettings.BaseUrl = TenantUrlHelpers.GetEvaluatedValueForTenant(
_options.Value.DefaultTenantSiteUrl,
_options.Value.SiteUrl,
_shellSettings);
Expand Down
1 change: 1 addition & 0 deletions Lombiq.Hosting.Tenants.Maintenance/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ The following configuration options are available to set the shell request URLs:
"IsEnabled": true,
"DefaultShellRequestUrl": "domain.com",
"RequestUrl": "{TenantName}.domain.com",
"DefaultShellRequestUrlPrefix": "",
"RequestUrlPrefix": "{TenantName}"
}
}
Expand Down

0 comments on commit 333781e

Please sign in to comment.