Files
AutopilotMonitor/src/Backend/AutopilotMonitor.Functions/Helpers/EndpointNormalizer.cs
T
Oliver Kieselbach 085f1f0f0f fixed normalizer
2026-03-29 14:37:53 +02:00

31 lines
1.0 KiB
C#

using System.Text.RegularExpressions;
namespace AutopilotMonitor.Functions.Helpers;
/// <summary>
/// Normalizes request paths for usage grouping by replacing GUIDs with {id}.
/// E.g. "/api/sessions/abc-def-123/events" -> "sessions/{id}/events"
/// </summary>
public static class EndpointNormalizer
{
private static readonly Regex GuidPattern = new(
@"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}",
RegexOptions.Compiled);
public static string Normalize(string path)
{
// Strip /api/ prefix
var normalized = path.StartsWith("/api/", StringComparison.OrdinalIgnoreCase)
? path.Substring(5)
: path.TrimStart('/');
// Replace GUIDs with {id}
normalized = GuidPattern.Replace(normalized, "{id}");
// Replace characters that are illegal in Azure Table Storage keys (/, \, #, ?)
normalized = normalized.Replace('/', '_').Replace('\\', '_').Replace('#', '_').Replace('?', '_');
return normalized.ToLowerInvariant();
}
}