2026-07-18 14:11:47 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2026-08-12 11:29:03 +02:00
|
|
|
using System.Reflection;
|
2026-07-18 14:11:47 +00:00
|
|
|
|
|
|
|
|
namespace Heimdall.Agent;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Strongly-typed configuration for the Heimdall Agent.
|
|
|
|
|
/// Bound from environment variables or appsettings.json on startup.
|
|
|
|
|
/// Validated automatically — misconfiguration is caught before any service runs.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class AgentOptions
|
|
|
|
|
{
|
|
|
|
|
public const string SectionName = "Agent";
|
|
|
|
|
|
|
|
|
|
/// <summary>URL of the Heimdall Central server (e.g. http://heimdall-central:8080).</summary>
|
|
|
|
|
[Required, Url]
|
|
|
|
|
public string CentralUrl { get; init; } = string.Empty;
|
|
|
|
|
|
2026-10-22 06:56:06 +02:00
|
|
|
/// <summary>Allow an unencrypted HTTP Central URL for isolated development networks only.</summary>
|
|
|
|
|
public bool AllowInsecureHttp { get; init; }
|
|
|
|
|
|
2026-10-22 06:57:50 +02:00
|
|
|
/// <summary>Site token for initial agent registration.</summary>
|
2026-07-18 14:11:47 +00:00
|
|
|
[Required, MinLength(1)]
|
2026-10-22 06:57:50 +02:00
|
|
|
public string SiteToken
|
|
|
|
|
{
|
|
|
|
|
get => string.IsNullOrWhiteSpace(_siteToken)
|
|
|
|
|
? ReadSystemdCredential("site-token") ?? string.Empty
|
|
|
|
|
: _siteToken;
|
|
|
|
|
init => _siteToken = value ?? string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _siteToken = string.Empty;
|
2026-07-18 14:11:47 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Display name for this agent instance. Falls back to hostname if empty.
|
|
|
|
|
/// </summary>
|
2026-10-22 06:57:50 +02:00
|
|
|
public string? AgentName
|
|
|
|
|
{
|
|
|
|
|
get => string.IsNullOrWhiteSpace(_agentName)
|
|
|
|
|
? ReadSystemdCredential("agent-name")
|
|
|
|
|
: _agentName;
|
|
|
|
|
init => _agentName = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string? _agentName;
|
2026-07-18 14:11:47 +00:00
|
|
|
|
|
|
|
|
/// <summary>Interval between heartbeats in seconds (default: 30).</summary>
|
|
|
|
|
[Range(5, 300)]
|
|
|
|
|
public int HeartbeatIntervalSeconds { get; init; } = 30;
|
|
|
|
|
|
|
|
|
|
/// <summary>Directory for persisting agent identity state. Defaults to /var/lib/heimdall on Linux.</summary>
|
|
|
|
|
public string? StateDirectory { get; init; }
|
|
|
|
|
|
|
|
|
|
/// <summary>Max retries for agent registration (default: 5).</summary>
|
|
|
|
|
[Range(1, 20)]
|
|
|
|
|
public int RegistrationMaxRetries { get; init; } = 5;
|
|
|
|
|
|
2026-08-11 16:15:41 +02:00
|
|
|
/// <summary>Interval between automatic camera network scans in seconds (default: 900 = 15 min).</summary>
|
|
|
|
|
[Range(60, 86400)]
|
|
|
|
|
public int DiscoveryIntervalSeconds { get; init; } = 900;
|
|
|
|
|
|
2026-08-27 18:56:57 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Hours between automatic update checks from the central server (default: 12).
|
|
|
|
|
/// Set to 0 to disable automatic update checks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Range(0, 168)]
|
|
|
|
|
public int UpdateCheckIntervalHours { get; init; } = 12;
|
|
|
|
|
|
2026-08-11 16:15:41 +02:00
|
|
|
/// <summary>Enable automatic camera discovery on the local network (default: true).</summary>
|
|
|
|
|
public bool DiscoveryEnabled { get; init; } = true;
|
|
|
|
|
|
2026-08-12 11:29:03 +02:00
|
|
|
/// <summary>Agent software version reported to Central. Injected at build time by
|
|
|
|
|
/// GitVersion (GitVersion.Agent.yml) via `-p:Version=`. No longer hardcoded in appsettings.</summary>
|
|
|
|
|
public string Version { get; init; } = AssemblyVersion;
|
|
|
|
|
|
|
|
|
|
private static string AssemblyVersion =>
|
|
|
|
|
typeof(AgentOptions).Assembly
|
|
|
|
|
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
|
|
|
|
|
.InformationalVersion.Split('+')[0]
|
|
|
|
|
?? "0.0.0";
|
2026-08-11 21:16:28 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Local camera assignments used as a fallback until the Central ships its
|
|
|
|
|
/// camera list (per-agent settings pipeline). Useful for development or
|
|
|
|
|
/// agents that cannot reach the Central camera registry. When the Central
|
|
|
|
|
/// config arrives, it replaces this list entirely.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<AgentCameraOptions> Cameras { get; init; } = [];
|
2026-08-27 00:07:17 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines where video frame analysis runs.
|
|
|
|
|
/// Local (default): YOLO/ONNX inference on the agent.
|
|
|
|
|
/// Remote: motion frames are downscaled and published to a broker.
|
|
|
|
|
/// Falls back to Local if the broker is unreachable.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public AnalysisMode AnalysisMode { get; init; } = AnalysisMode.Local;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// URL of the remote analysis broker (required when AnalysisMode = Remote).
|
|
|
|
|
/// Example: http://heimdall-broker:8080
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? BrokerUrl { get; init; }
|
2026-08-27 18:56:57 +02:00
|
|
|
|
|
|
|
|
public string DockerSocketPath { get; init; } = "/var/run/docker.sock";
|
|
|
|
|
public bool AutoUpdateEnabled { get; set; }
|
2026-10-22 06:57:50 +02:00
|
|
|
|
2026-10-23 18:54:14 +02:00
|
|
|
/// <summary>Locally provisioned publisher public key; Central cannot change this setting.</summary>
|
|
|
|
|
public string? UpdatePublicKeyPath { get; init; }
|
|
|
|
|
|
2026-10-26 11:38:24 +01:00
|
|
|
/// <summary>Publisher public key provisioned by the trusted installation flow.</summary>
|
|
|
|
|
public string? UpdatePublicKeyPem { get; init; }
|
|
|
|
|
|
2026-10-23 18:54:14 +02:00
|
|
|
/// <summary>Locally installed agent release root containing current and releases.</summary>
|
|
|
|
|
public string? UpdateInstallRoot { get; init; }
|
|
|
|
|
|
2026-10-26 11:38:24 +01:00
|
|
|
/// <summary>Windows helper that replaces the running release after process shutdown and rolls back on failed health checks.</summary>
|
|
|
|
|
public string? UpdateSupervisorPath { get; init; }
|
|
|
|
|
|
|
|
|
|
/// <summary>Optional Windows Service name; empty means a foreground console installation.</summary>
|
|
|
|
|
public string? UpdateWindowsServiceName { get; init; }
|
|
|
|
|
|
2026-10-22 06:57:50 +02:00
|
|
|
private static string? ReadSystemdCredential(string name)
|
|
|
|
|
{
|
|
|
|
|
var directory = Environment.GetEnvironmentVariable("CREDENTIALS_DIRECTORY");
|
|
|
|
|
if (string.IsNullOrWhiteSpace(directory))
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(directory, name);
|
|
|
|
|
return File.Exists(path) ? File.ReadAllText(path).TrimEnd('\r', '\n') : null;
|
|
|
|
|
}
|
|
|
|
|
catch (IOException)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
catch (UnauthorizedAccessException)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-18 14:11:47 +00:00
|
|
|
}
|