fix(agent): heartbeat X-API-Key complet + métriques temps réel + hub config

- ApiKeyAuthenticationHandler accepte l'API key via query string access_token
  sur les chemins /hubs (WebSocket SignalR ne peut pas poser de header custom)
  → le ConfigReceiverService de l'agent peut se connecter au ConfigHub
- ConfigReceiverService.FetchFullConfigAsync : X-API-Key au lieu de Bearer
- Métriques heartbeat : CpuUsagePercent/MemoryUsageBytes/DiskUsagePercent/
  UptimeSeconds + IsOffline désormais transportées jusqu'à l'entité Agent
  (migration AddAgentLiveMetrics) ; IsOffline marque l'agent Offline
  immédiatement au lieu d'attendre le timeout 90s du HeartbeatMonitorJob
- docker-compose.local.yml : override aussi l'image agent (heimdall-agent:local)

Tests : +2 unit AgentRegistrationService (X-API-Key), +2 HeartbeatHandler
(métriques, offline), +3 intégration SignalR (ConfigHub query string) — verts.
This commit is contained in:
Arnaud Dartois committed 2026-08-10 10:26:31 +02:00
1 parent 4516761a3a
commit 1e3322cd1a
13 files changed
+2066 -20

No files matched your search

@@ -34,9 +34,20 @@ public class ApiKeyAuthenticationHandler : AuthenticationHandler<ApiKeyAuthentic
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
{
// X-API-Key header only (pas de Bearer — réservé au handler JWT)
// X-API-Key header only (pas de Bearer — réservé au handler JWT).
// SignalR WebSocket clients cannot set custom headers, so the API key
// is also accepted via the access_token query string on hub paths
// (same convention as the JwtBearer handler).
var apiKey = Request.Headers["X-API-Key"].FirstOrDefault();
if (string.IsNullOrEmpty(apiKey))
{
var path = Request.Path;
var queryToken = Request.Query["access_token"].FirstOrDefault();
if (!string.IsNullOrEmpty(queryToken) && path.StartsWithSegments("/hubs"))
apiKey = queryToken;
}
if (string.IsNullOrEmpty(apiKey) || apiKey.Length < 8)
return AuthenticateResult.NoResult();