Skip to main content

yeti_types/
platform.rs

1//! Platform utilities — path helpers + MQTT interface config.
2//!
3//! Plugins that observe telemetry events return a
4//! `yeti_types::plugins::lifecycle::TelemetryService` (Tower
5//! `Service<TelemetryEvent>`) from `Plugin::install_event_subscriber`
6//! (see ADR-006).
7
8use std::path::PathBuf;
9
10// ============================================================================
11// Path utilities
12// ============================================================================
13
14/// Expand `~/` prefix in directory paths to actual home directory.
15#[must_use]
16pub fn expand_root_directory(root_dir: &str) -> PathBuf {
17    if let Some(rest) = root_dir.strip_prefix("~/")
18        && let Some(home) = std::env::var_os("HOME")
19    {
20        PathBuf::from(home).join(rest)
21    } else {
22        PathBuf::from(root_dir)
23    }
24}
25
26// ============================================================================
27// MQTT Interface Configuration
28// ============================================================================
29
30/// MQTT broker interface configuration.
31#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
32#[serde(default)]
33pub struct MqttInterfaceConfig {
34    /// Whether MQTT is enabled
35    pub enabled: bool,
36    /// Whether audit logging is enabled for MQTT
37    pub audit: bool,
38    /// MQTT native TLS port (default: 8883)
39    pub port: u16,
40    /// Maximum simultaneous MQTT clients
41    pub max_clients: usize,
42    /// Default `QoS` level for bridge-published messages (0, 1, or 2)
43    pub qos: u8,
44    /// Bind the native MQTTS listener on `0.0.0.0:{port}`. Default `true` —
45    /// MQTT is exposed like every other interface (REST/WS/SSE/GraphQL/MCP),
46    /// for direct MQTT clients (requires the TLS cert/key at
47    /// `{root}/certs/{domain}-cert.pem`; a confined instance with no certs
48    /// stays loopback-only regardless). Set `false` to serve MQTT only through
49    /// the WebSocket proxy (`wss://host/mqtt`) and open no separate MQTT port.
50    #[serde(alias = "nativeListener")]
51    pub native_listener: bool,
52}
53
54impl Default for MqttInterfaceConfig {
55    fn default() -> Self {
56        Self {
57            enabled: true,
58            audit: false,
59            port: 8883,
60            max_clients: 10_000,
61            qos: 2,
62            native_listener: true,
63        }
64    }
65}