mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-24 20:53:06 +00:00
31 lines
1.0 KiB
C#
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();
|
|
}
|
|
}
|