@@ -2,8 +2,8 @@ using System.Net;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Tiku.Api.Background;
|
||||
using Tiku.Api.Options;
|
||||
using Tiku.Application.Tenancy;
|
||||
using Tiku.Application.PlatformAdmin;
|
||||
using Tiku.Application.Tenancy;
|
||||
|
||||
namespace Tiku.Api.Configuration;
|
||||
|
||||
@@ -17,7 +17,8 @@ internal static class NetworkConfigurationExtensions
|
||||
services.AddOptions<TenantResolutionOptions>()
|
||||
.Bind(configuration.GetSection(TenantResolutionOptions.SectionName))
|
||||
.Validate(
|
||||
options => OptionsValidation.BeValidTenantResolutionOptions(options, configuration, environment.IsProduction()),
|
||||
options => OptionsValidation.BeValidTenantResolutionOptions(options, configuration,
|
||||
environment.IsProduction()),
|
||||
"Production requires formal platform hosts, non-wildcard AllowedHosts, and trusted proxy addresses.")
|
||||
.ValidateOnStart();
|
||||
services.Configure<ForwardedHeadersOptions>(options =>
|
||||
@@ -34,22 +35,15 @@ internal static class NetworkConfigurationExtensions
|
||||
.GetSection(TenantResolutionOptions.SectionName)
|
||||
.Get<TenantResolutionOptions>() ?? new TenantResolutionOptions();
|
||||
foreach (var address in resolution.TrustedProxyAddresses)
|
||||
{
|
||||
if (IPAddress.TryParse(address, out var proxy))
|
||||
{
|
||||
options.KnownProxies.Add(proxy);
|
||||
}
|
||||
}
|
||||
});
|
||||
services.AddOptions<DomainLifecycleOptions>()
|
||||
.Bind(configuration.GetSection("TenantDomains"))
|
||||
.Validate(options => environment.IsDevelopment() || !options.EnableDevelopmentLocalhostBypass,
|
||||
"The .localhost domain lifecycle bypass can only be enabled in Development.")
|
||||
.ValidateOnStart();
|
||||
if (environment.IsDevelopment())
|
||||
{
|
||||
services.AddHostedService<DevelopmentTenantDomainLifecycleHostedService>();
|
||||
}
|
||||
if (environment.IsDevelopment()) services.AddHostedService<DevelopmentTenantDomainLifecycleHostedService>();
|
||||
services.AddOptions<TenantProvisioningOptions>()
|
||||
.Bind(configuration.GetSection(TenantProvisioningOptions.SectionName))
|
||||
.Validate(options => !string.IsNullOrWhiteSpace(options.DefaultBaseOfferingCode) &&
|
||||
@@ -57,17 +51,15 @@ internal static class NetworkConfigurationExtensions
|
||||
options.OwnerActivationMinutes is >= 5 and <= 1440 &&
|
||||
options.OwnerActivationUrlTemplate.Contains("{host}", StringComparison.Ordinal) &&
|
||||
Uri.TryCreate(
|
||||
options.OwnerActivationUrlTemplate.Replace("{host}", "tenant.example.com", StringComparison.Ordinal),
|
||||
options.OwnerActivationUrlTemplate.Replace("{host}", "tenant.example.com",
|
||||
StringComparison.Ordinal),
|
||||
UriKind.Absolute,
|
||||
out var activationOrigin) &&
|
||||
activationOrigin.Scheme == Uri.UriSchemeHttps &&
|
||||
ValidateDevelopmentActivationTemplate(options, environment.IsDevelopment()),
|
||||
"Tenant provisioning requires a default offering code, valid trial/activation durations, an HTTPS owner activation URL template, and permits an HTTP template only for Development .localhost sites.")
|
||||
.ValidateOnStart();
|
||||
if (environment.IsProduction())
|
||||
{
|
||||
services.AddHostedService<TenantProvisioningStartupValidator>();
|
||||
}
|
||||
if (environment.IsProduction()) services.AddHostedService<TenantProvisioningStartupValidator>();
|
||||
|
||||
services.AddOptions<CorsOptions>()
|
||||
.Bind(configuration.GetSection(CorsOptions.SectionName))
|
||||
@@ -90,19 +82,13 @@ internal static class NetworkConfigurationExtensions
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
|
||||
if (origins.Length > 0)
|
||||
{
|
||||
policy.WithOrigins(origins);
|
||||
}
|
||||
if (origins.Length > 0) policy.WithOrigins(origins);
|
||||
|
||||
policy
|
||||
.WithHeaders(corsOptions.AllowedHeaders)
|
||||
.WithMethods(corsOptions.AllowedMethods);
|
||||
|
||||
if (corsOptions.AllowCredentials)
|
||||
{
|
||||
policy.AllowCredentials();
|
||||
}
|
||||
if (corsOptions.AllowCredentials) policy.AllowCredentials();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -113,10 +99,7 @@ internal static class NetworkConfigurationExtensions
|
||||
TenantProvisioningOptions options,
|
||||
bool isDevelopment)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(options.DevelopmentLocalhostOwnerActivationUrlTemplate))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(options.DevelopmentLocalhostOwnerActivationUrlTemplate)) return true;
|
||||
|
||||
return isDevelopment &&
|
||||
options.DevelopmentLocalhostOwnerActivationUrlTemplate.Contains("{host}", StringComparison.Ordinal) &&
|
||||
@@ -128,4 +111,4 @@ internal static class NetworkConfigurationExtensions
|
||||
(developmentOrigin.Scheme == Uri.UriSchemeHttp ||
|
||||
developmentOrigin.Scheme == Uri.UriSchemeHttps);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user