save checkpoint

This commit is contained in:
master
2026-02-12 21:02:43 +02:00
parent 5bca406787
commit 9911b7d73c
593 changed files with 174390 additions and 1376 deletions

View File

@@ -1,3 +1,6 @@
using System.Text.RegularExpressions;
using StellaOps.Router.Gateway.Configuration;
namespace StellaOps.Gateway.WebService.Configuration;
public static class GatewayOptionsValidator
@@ -35,5 +38,85 @@ public static class GatewayOptionsValidator
_ = GatewayValueParser.ParseDuration(options.Health.StaleThreshold, TimeSpan.FromSeconds(30));
_ = GatewayValueParser.ParseDuration(options.Health.DegradedThreshold, TimeSpan.FromSeconds(15));
_ = GatewayValueParser.ParseDuration(options.Health.CheckInterval, TimeSpan.FromSeconds(5));
ValidateRoutes(options.Routes);
}
private static void ValidateRoutes(List<StellaOpsRoute> routes)
{
for (var i = 0; i < routes.Count; i++)
{
var route = routes[i];
var prefix = $"Route[{i}]";
if (string.IsNullOrWhiteSpace(route.Path))
{
throw new InvalidOperationException($"{prefix}: Path must not be empty.");
}
if (route.IsRegex)
{
try
{
_ = new Regex(route.Path, RegexOptions.Compiled, TimeSpan.FromSeconds(1));
}
catch (ArgumentException ex)
{
throw new InvalidOperationException($"{prefix}: Path is not a valid regex pattern: {ex.Message}");
}
}
switch (route.Type)
{
case StellaOpsRouteType.ReverseProxy:
if (string.IsNullOrWhiteSpace(route.TranslatesTo) ||
!Uri.TryCreate(route.TranslatesTo, UriKind.Absolute, out var proxyUri) ||
(proxyUri.Scheme != "http" && proxyUri.Scheme != "https"))
{
throw new InvalidOperationException($"{prefix}: ReverseProxy requires a valid HTTP(S) URL in TranslatesTo.");
}
break;
case StellaOpsRouteType.StaticFiles:
if (string.IsNullOrWhiteSpace(route.TranslatesTo))
{
throw new InvalidOperationException($"{prefix}: StaticFiles requires a directory path in TranslatesTo.");
}
break;
case StellaOpsRouteType.StaticFile:
if (string.IsNullOrWhiteSpace(route.TranslatesTo))
{
throw new InvalidOperationException($"{prefix}: StaticFile requires a file path in TranslatesTo.");
}
break;
case StellaOpsRouteType.WebSocket:
if (string.IsNullOrWhiteSpace(route.TranslatesTo) ||
!Uri.TryCreate(route.TranslatesTo, UriKind.Absolute, out var wsUri) ||
(wsUri.Scheme != "ws" && wsUri.Scheme != "wss"))
{
throw new InvalidOperationException($"{prefix}: WebSocket requires a valid ws:// or wss:// URL in TranslatesTo.");
}
break;
case StellaOpsRouteType.NotFoundPage:
if (string.IsNullOrWhiteSpace(route.TranslatesTo))
{
throw new InvalidOperationException($"{prefix}: NotFoundPage requires a file path in TranslatesTo.");
}
break;
case StellaOpsRouteType.ServerErrorPage:
if (string.IsNullOrWhiteSpace(route.TranslatesTo))
{
throw new InvalidOperationException($"{prefix}: ServerErrorPage requires a file path in TranslatesTo.");
}
break;
case StellaOpsRouteType.Microservice:
break;
}
}
}
}