Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEST-326: Fix: Maintenance to update staging tenant bindings after DB replace #59

Merged
merged 3 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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