Track manual snapshots and apply versioned camera config
This commit is contained in:
1 parent
f4a8f4a668
commit
8f00f69a5f
30 files changed
+645
-63
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using Heimdall.Application.Agents.Queries.GetAgent;
|
||||
using Heimdall.Application.Agents.Commands.AcknowledgeCameraConfig;
|
||||
using Heimdall.Application.Common;
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Application.Services;
|
||||
@@ -138,7 +139,7 @@ public class SettingsController : ControllerBase
|
||||
/// <summary>
|
||||
/// Get the effective configuration for an agent: global defaults merged with
|
||||
/// per-agent overrides, plus the site's camera credential pool inside an
|
||||
/// encrypted envelope. Accessible by the agent itself (API key, same site)
|
||||
/// encrypted envelope. Accessible by the agent itself (API key)
|
||||
/// or by an admin (JWT/Cookie).
|
||||
/// </summary>
|
||||
[Authorize(AuthenticationSchemes = "ApiKey,JwtBearer,Cookies")]
|
||||
@@ -147,10 +148,13 @@ public class SettingsController : ControllerBase
|
||||
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetEffectiveConfig(Guid agentId, CancellationToken ct)
|
||||
{
|
||||
// API key callers: the agent may only read its own site's config.
|
||||
// The API key is bound to exactly one agent. Same-site agents must not
|
||||
// be able to read each other's RTSP URLs or credential envelopes.
|
||||
var isApiKey = User.HasClaim(c => c.Type == "auth_method" && c.Value == "api_key");
|
||||
if (isApiKey)
|
||||
{
|
||||
if (User.FindFirst("agent_id")?.Value != agentId.ToString())
|
||||
return Forbid();
|
||||
var siteClaim = User.FindFirst("site_id")?.Value;
|
||||
if (!Guid.TryParse(siteClaim, out var apiKeySiteId))
|
||||
return Forbid();
|
||||
@@ -167,9 +171,38 @@ public class SettingsController : ControllerBase
|
||||
}
|
||||
|
||||
var result = await _mediator.Send(new GetEffectiveAgentConfigQuery(agentId), ct);
|
||||
return result.IsSuccess
|
||||
? Ok(result.Data)
|
||||
: NotFound(new { error = result.Error });
|
||||
if (!result.IsSuccess || result.Data is null)
|
||||
return NotFound(new { error = result.Error });
|
||||
Response.Headers["X-Camera-Config-Version"] = CameraConfigVersion.Compute(result.Data);
|
||||
return Ok(result.Data);
|
||||
}
|
||||
|
||||
public sealed record CameraConfigAckRequest(string Version);
|
||||
|
||||
/// <summary>Acknowledge the exact camera snapshot applied by this agent.</summary>
|
||||
[Authorize(AuthenticationSchemes = "ApiKey")]
|
||||
[HttpPost("agent/{agentId:guid}/camera-config-ack")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status409Conflict)]
|
||||
public async Task<IActionResult> AcknowledgeCameraConfig(Guid agentId,
|
||||
[FromBody] CameraConfigAckRequest request, CancellationToken ct)
|
||||
{
|
||||
if (User.FindFirst("agent_id")?.Value != agentId.ToString())
|
||||
return Forbid();
|
||||
if (request.Version?.Length != 64 || !request.Version.All(Uri.IsHexDigit))
|
||||
return BadRequest(new { error = "Invalid camera configuration version" });
|
||||
|
||||
var result = await _mediator.Send(new GetEffectiveAgentConfigQuery(agentId), ct);
|
||||
if (!result.IsSuccess || result.Data is null)
|
||||
return NotFound(new { error = result.Error });
|
||||
if (!string.Equals(CameraConfigVersion.Compute(result.Data), request.Version,
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
return Conflict(new { error = "Camera configuration changed before acknowledgement" });
|
||||
|
||||
if (!await _mediator.Send(new AcknowledgeCameraConfigCommand(agentId, request.Version), ct))
|
||||
return NotFound();
|
||||
_logger.LogInformation("Agent {AgentId} applied camera configuration {Version}", agentId, request.Version);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>List all setting overrides for a specific agent (Admin only).</summary>
|
||||
|
||||
Reference in new issue
Block a user