2026-08-11 16:15:41 +02:00
|
|
|
using Heimdall.Application.Agents.Queries.GetAgent;
|
2026-07-20 10:30:01 +00:00
|
|
|
using Heimdall.Application.Common;
|
|
|
|
|
using Heimdall.Application.DTOs;
|
|
|
|
|
using Heimdall.Application.Services;
|
2026-07-22 19:54:55 +00:00
|
|
|
using Heimdall.Application.Settings.Commands.CreateAppSetting;
|
|
|
|
|
using Heimdall.Application.Settings.Commands.UpdateAppSetting;
|
|
|
|
|
using Heimdall.Application.Settings.Commands.DeleteAppSetting;
|
|
|
|
|
using Heimdall.Application.Settings.Commands.SetAgentSetting;
|
|
|
|
|
using Heimdall.Application.Settings.Commands.RemoveAgentSetting;
|
|
|
|
|
using Heimdall.Application.Settings.Queries.GetSettings;
|
|
|
|
|
using Heimdall.Application.Settings.Queries.GetSettingByKey;
|
|
|
|
|
using Heimdall.Application.Settings.Queries.GetEffectiveAgentConfig;
|
|
|
|
|
using Heimdall.Application.Settings.Queries.GetAgentSettings;
|
2026-07-20 10:30:01 +00:00
|
|
|
using Heimdall.Api.Hubs;
|
|
|
|
|
using Heimdall.Infrastructure.Security;
|
2026-07-22 19:54:55 +00:00
|
|
|
using MediatR;
|
2026-07-20 10:30:01 +00:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.RateLimiting;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Api.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/settings")]
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies")]
|
2026-07-20 10:30:01 +00:00
|
|
|
[EnableRateLimiting("Api")]
|
|
|
|
|
public class SettingsController : ControllerBase
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
private readonly IMediator _mediator;
|
2026-07-20 10:30:01 +00:00
|
|
|
private readonly IConfigBroadcastService _broadcast;
|
|
|
|
|
private readonly ILogger<SettingsController> _logger;
|
|
|
|
|
|
|
|
|
|
public SettingsController(
|
2026-07-22 19:54:55 +00:00
|
|
|
IMediator mediator,
|
2026-07-20 10:30:01 +00:00
|
|
|
IConfigBroadcastService broadcast,
|
|
|
|
|
ILogger<SettingsController> logger)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
_mediator = mediator;
|
2026-07-20 10:30:01 +00:00
|
|
|
_broadcast = broadcast;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>List all global settings (Admin only).</summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(typeof(List<AppSettingDto>), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
public async Task<IActionResult> ListAll(CancellationToken ct)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
var result = await _mediator.Send(new GetSettingsQuery(), ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
|
|
|
|
|
|
|
|
|
// Redact sensitive values before returning to client
|
|
|
|
|
var redacted = result.Data!.Select(s => s with
|
|
|
|
|
{
|
|
|
|
|
Value = RedactValue(s.ValueType, s.Value, s.Key)
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
return Ok(redacted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Get a global setting by key (Admin only).</summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpGet("{key}")]
|
|
|
|
|
[ProducesResponseType(typeof(AppSettingDto), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
|
|
|
|
public async Task<IActionResult> GetByKey(string key, CancellationToken ct)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
var result = await _mediator.Send(new GetSettingByKeyQuery(key), ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
return NotFound(new { error = result.Error });
|
|
|
|
|
|
|
|
|
|
// Redact sensitive values before returning to client
|
|
|
|
|
var redacted = result.Data! with
|
|
|
|
|
{
|
|
|
|
|
Value = RedactValue(result.Data.ValueType, result.Data.Value, result.Data.Key)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Ok(redacted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Create a new global setting (Admin only).</summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(AppSettingDto), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
public async Task<IActionResult> Create(
|
|
|
|
|
[FromBody] CreateAppSettingRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
var command = new CreateAppSettingCommand(request.Key, request.Value, request.Category, request.Description, request.ValueType, request.AllowedValues);
|
|
|
|
|
var result = await _mediator.Send(command, ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
|
|
|
|
|
|
|
|
|
await _broadcast.NotifyGlobalSettingChanged(result.Data!.Key, result.Data.Value, ct);
|
|
|
|
|
_logger.LogInformation("Created global setting {Key} = {Value}", result.Data.Key, RedactValue(result.Data.ValueType, result.Data.Value));
|
|
|
|
|
return Ok(result.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Update a global setting (Admin only). Broadcasts the change to all agents.</summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpPut("{key}")]
|
|
|
|
|
[ProducesResponseType(typeof(AppSettingDto), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
|
|
|
|
public async Task<IActionResult> Update(
|
|
|
|
|
string key, [FromBody] UpdateAppSettingRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
var command = new UpdateAppSettingCommand(key, request.Value, request.Description, request.Category, request.ValueType, request.AllowedValues);
|
|
|
|
|
var result = await _mediator.Send(command, ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
|
|
|
|
|
|
|
|
|
await _broadcast.NotifyGlobalSettingChanged(result.Data!.Key, result.Data.Value, ct);
|
|
|
|
|
_logger.LogInformation("Updated global setting {Key} = {Value}", result.Data.Key, RedactValue(result.Data.ValueType, result.Data.Value));
|
|
|
|
|
return Ok(result.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>Delete a global setting (Admin only). Broadcasts the change to all agents.</summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpDelete("{key}")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
|
|
|
|
public async Task<IActionResult> Delete(string key, CancellationToken ct)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
var result = await _mediator.Send(new DeleteAppSettingCommand(key), ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
|
|
|
|
|
|
|
|
|
await _broadcast.NotifyAllAgentsReload(ct);
|
|
|
|
|
_logger.LogInformation("Deleted global setting {Key}", key);
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get the effective configuration for an agent: global defaults merged with
|
2026-08-11 16:15:41 +02:00
|
|
|
/// per-agent overrides, plus the site's camera credential pool inside an
|
|
|
|
|
/// encrypted envelope. Accessible by the agent itself (API key, same site)
|
|
|
|
|
/// or by an admin (JWT/Cookie).
|
2026-07-20 10:30:01 +00:00
|
|
|
/// </summary>
|
2026-08-11 16:15:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "ApiKey,JwtBearer,Cookies")]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpGet("agent/{agentId:guid}")]
|
|
|
|
|
[ProducesResponseType(typeof(Dictionary<string, string>), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
|
|
|
|
public async Task<IActionResult> GetEffectiveConfig(Guid agentId, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-11 16:15:41 +02:00
|
|
|
// API key callers: the agent may only read its own site's config.
|
|
|
|
|
var isApiKey = User.HasClaim(c => c.Type == "auth_method" && c.Value == "api_key");
|
|
|
|
|
if (isApiKey)
|
|
|
|
|
{
|
|
|
|
|
var siteClaim = User.FindFirst("site_id")?.Value;
|
|
|
|
|
if (!Guid.TryParse(siteClaim, out var apiKeySiteId))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var agentResult = await _mediator.Send(new GetAgentQuery(agentId), ct);
|
|
|
|
|
if (!agentResult.IsSuccess || agentResult.Data is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
if (agentResult.Data.SiteId != apiKeySiteId)
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
else if (!User.HasClaim("permission", AppPermissions.AdminManage))
|
|
|
|
|
{
|
|
|
|
|
return Forbid();
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-22 19:54:55 +00:00
|
|
|
var result = await _mediator.Send(new GetEffectiveAgentConfigQuery(agentId), ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
return result.IsSuccess
|
|
|
|
|
? Ok(result.Data)
|
|
|
|
|
: NotFound(new { error = result.Error });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>List all setting overrides for a specific agent (Admin only).</summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpGet("agent/{agentId:guid}/overrides")]
|
|
|
|
|
[ProducesResponseType(typeof(List<AgentSettingDto>), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
|
|
|
|
public async Task<IActionResult> ListAgentOverrides(Guid agentId, CancellationToken ct)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
var result = await _mediator.Send(new GetAgentSettingsQuery(agentId), ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
return result.IsSuccess
|
|
|
|
|
? Ok(result.Data)
|
|
|
|
|
: NotFound(new { error = result.Error });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Set (create or update) a per-agent setting override (Admin only).
|
|
|
|
|
/// Broadcasts the change to the affected agent in real-time.
|
|
|
|
|
/// </summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpPut("agent/{agentId:guid}/overrides")]
|
|
|
|
|
[ProducesResponseType(typeof(AgentSettingDto), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
|
|
|
|
public async Task<IActionResult> SetAgentOverride(
|
|
|
|
|
Guid agentId, [FromBody] SetAgentSettingRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
var command = new SetAgentSettingCommand(agentId, request.Key, request.Value);
|
|
|
|
|
var result = await _mediator.Send(command, ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
|
|
|
|
|
|
|
|
|
await _broadcast.NotifyAgentSettingChanged(agentId, result.Data!.Key, result.Data.Value, ct);
|
|
|
|
|
_logger.LogInformation("Set agent override Agent={AgentId}, {Key} = {Value}",
|
|
|
|
|
agentId, result.Data.Key, RedactValue(null, result.Data.Value, result.Data.Key));
|
|
|
|
|
return Ok(result.Data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove a per-agent setting override (Admin only).
|
|
|
|
|
/// Broadcasts a reload notification to the affected agent.
|
|
|
|
|
/// </summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpDelete("agent/{agentId:guid}/overrides/{key}")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status404NotFound)]
|
|
|
|
|
public async Task<IActionResult> RemoveAgentOverride(Guid agentId, string key, CancellationToken ct)
|
|
|
|
|
{
|
2026-07-22 19:54:55 +00:00
|
|
|
var result = await _mediator.Send(new RemoveAgentSettingCommand(agentId, key), ct);
|
2026-07-20 10:30:01 +00:00
|
|
|
if (!result.IsSuccess)
|
|
|
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
|
|
|
|
|
|
|
|
|
await _broadcast.NotifyAgentSettingChanged(agentId, key, string.Empty, ct);
|
|
|
|
|
_logger.LogInformation("Removed agent override Agent={AgentId}, {Key}", agentId, key);
|
|
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 10:14:40 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Test the active storage provider reachability (Admin only).
|
|
|
|
|
/// Returns the resolved provider name and health status.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
|
|
|
|
[HttpPost("storage/test")]
|
|
|
|
|
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
public async Task<IActionResult> TestStorage(
|
|
|
|
|
[FromServices] IStorageProvider storageProvider,
|
|
|
|
|
CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var ok = await storageProvider.HealthCheckAsync(ct);
|
|
|
|
|
return Ok(new
|
|
|
|
|
{
|
|
|
|
|
provider = storageProvider.Provider,
|
|
|
|
|
configured = storageProvider.IsConfigured,
|
|
|
|
|
healthy = ok,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 11:50:47 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Send a test email through the configured SMTP server (Admin only).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
|
|
|
|
[HttpPost("email/test")]
|
|
|
|
|
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(object), StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<IActionResult> TestEmail(
|
|
|
|
|
[FromServices] IEmailService emailService,
|
|
|
|
|
CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var settings = await _mediator.Send(new GetSettingsQuery(), ct);
|
|
|
|
|
if (!settings.IsSuccess)
|
|
|
|
|
return StatusCode(settings.StatusCode ?? 400, new { error = settings.Error });
|
|
|
|
|
|
|
|
|
|
var fromAddress = settings.Data!.FirstOrDefault(s => s.Key == "email.fromaddress")?.Value;
|
|
|
|
|
if (string.IsNullOrWhiteSpace(fromAddress))
|
|
|
|
|
return BadRequest(new { error = "Adresse expéditrice non configurée (email.fromaddress)." });
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await emailService.SendEmailAsync(fromAddress, "Heimdall — test de configuration",
|
|
|
|
|
"<h2>✅ Configuration email OK</h2><p>Ce message confirme que le serveur SMTP est joignable et que l'authentification fonctionne.</p>", ct);
|
|
|
|
|
return Ok(new { success = true, message = $"Email de test envoyé à {fromAddress}" });
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return Ok(new { success = false, message = $"Échec de l'envoi : {ex.Message}" });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Send a test notification through the configured ntfy server (Admin only).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
|
|
|
|
[HttpPost("ntfy/test")]
|
|
|
|
|
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
|
|
|
|
public async Task<IActionResult> TestNtfy(
|
|
|
|
|
[FromServices] INtfyService ntfyService,
|
|
|
|
|
[FromBody] TestNtfyRequest? request,
|
|
|
|
|
CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var topic = string.IsNullOrWhiteSpace(request?.Topic) ? "heimdall-test" : request.Topic;
|
|
|
|
|
var ok = await ntfyService.SendTestAsync(topic, "Heimdall — test de configuration",
|
2026-08-20 18:14:46 +02:00
|
|
|
"✅ Notification ntfy reçue : le serveur est joignable et le token est accepté.",
|
|
|
|
|
baseUrl: request?.BaseUrl, ct: ct);
|
2026-08-12 20:05:12 +02:00
|
|
|
return Ok(new
|
|
|
|
|
{
|
|
|
|
|
success = ok,
|
|
|
|
|
message = ok
|
2026-08-20 18:14:46 +02:00
|
|
|
? $"Notification test envoyée sur « {topic} » ({request?.BaseUrl ?? "serveur global"})"
|
2026-08-12 20:05:12 +02:00
|
|
|
: "Échec de l'envoi ntfy (serveur injoignable ou rejet — voir les logs)."
|
|
|
|
|
});
|
2026-08-12 11:50:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ping the configured AI backends (CodeProject.AI / Ollama) (Admin only).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
|
|
|
|
[HttpPost("ai/test")]
|
|
|
|
|
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
|
|
|
|
public async Task<IActionResult> TestAi(
|
|
|
|
|
[FromServices] Heimdall.Infrastructure.HealthChecks.AiHealthCheck aiHealthCheck,
|
|
|
|
|
CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var result = await aiHealthCheck.CheckHealthAsync(null!, ct);
|
|
|
|
|
return Ok(new
|
|
|
|
|
{
|
|
|
|
|
success = result.Status == Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus.Healthy,
|
|
|
|
|
status = result.Status.ToString(),
|
|
|
|
|
message = result.Description,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-20 18:14:46 +02:00
|
|
|
public sealed record TestNtfyRequest(string? Topic, string? BaseUrl);
|
2026-08-12 11:50:47 +02:00
|
|
|
|
2026-07-20 10:30:01 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Broadcast a "ConfigReload" signal to all connected agents so they
|
|
|
|
|
/// re-fetch their full configuration (Admin only).
|
|
|
|
|
/// </summary>
|
2026-08-11 08:32:41 +02:00
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
|
2026-07-20 10:30:01 +00:00
|
|
|
[HttpPost("reload")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status202Accepted)]
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
public async Task<IActionResult> ReloadAllAgents(CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
await _broadcast.NotifyAllAgentsReload(ct);
|
|
|
|
|
_logger.LogInformation("Broadcast ConfigReload to all agents");
|
|
|
|
|
return Accepted(new { message = "Config reload broadcast to all connected agents" });
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-22 20:36:04 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Sensitive key patterns whose values must never be returned to the client.
|
|
|
|
|
/// Centralized list — add new patterns here as needed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static readonly string[] SensitiveKeyPatterns =
|
|
|
|
|
["password", "token", "secret", "apikey", "api_key", "credential", "jwt", "privatekey", "connectionstring"];
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sensitive value type patterns whose values must never be returned to the client.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private static readonly string[] SensitiveValueTypePatterns =
|
|
|
|
|
["password", "token", "secret", "key", "credential"];
|
|
|
|
|
|
2026-07-20 10:30:01 +00:00
|
|
|
private static string RedactValue(string? valueType, string value, string? key = null)
|
|
|
|
|
{
|
2026-07-22 20:36:04 +00:00
|
|
|
if (key is not null && SensitiveKeyPatterns.Any(p =>
|
|
|
|
|
key.Contains(p, StringComparison.OrdinalIgnoreCase)))
|
2026-07-20 10:30:01 +00:00
|
|
|
return "***REDACTED***";
|
2026-07-22 20:36:04 +00:00
|
|
|
|
|
|
|
|
if (valueType is not null && SensitiveValueTypePatterns.Any(p =>
|
|
|
|
|
valueType.Contains(p, StringComparison.OrdinalIgnoreCase)))
|
2026-07-20 10:30:01 +00:00
|
|
|
return "***REDACTED***";
|
2026-07-22 20:36:04 +00:00
|
|
|
|
2026-07-20 10:30:01 +00:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
}
|