helios_subscriptions/config.rs
1//! Subscription engine configuration.
2
3use std::time::Duration;
4
5/// Configuration for the subscription engine.
6#[derive(Debug, Clone)]
7pub struct SubscriptionConfig {
8 /// Maximum number of retry attempts for failed deliveries.
9 pub max_retries: u32,
10
11 /// Initial delay before the first retry.
12 pub retry_initial_delay: Duration,
13
14 /// Maximum delay between retries.
15 pub retry_max_delay: Duration,
16
17 /// Backoff multiplier for exponential backoff.
18 pub retry_backoff_factor: f64,
19
20 /// Delay before the first activation handshake attempt.
21 pub handshake_initial_delay: Duration,
22
23 /// Maximum number of activation handshake attempts.
24 pub handshake_max_attempts: u32,
25
26 /// Initial delay before retrying a failed activation handshake.
27 pub handshake_retry_initial_delay: Duration,
28
29 /// Maximum delay between activation handshake retries.
30 pub handshake_retry_max_delay: Duration,
31
32 /// How often to check for heartbeats that are due.
33 pub heartbeat_check_interval: Duration,
34
35 /// Number of consecutive failures before transitioning to `error` status.
36 pub error_threshold: u32,
37
38 /// Number of consecutive failures before transitioning to `off` status.
39 pub off_threshold: u32,
40
41 /// Supported channel types.
42 pub supported_channel_types: Vec<String>,
43
44 /// Lifetime of WebSocket binding tokens in seconds.
45 pub ws_token_lifetime_secs: i64,
46
47 /// SMTP settings for the email channel. `None` disables the email dispatcher.
48 pub smtp: Option<SmtpSettings>,
49
50 /// FHIR Messaging channel settings. `None` disables the messaging dispatcher.
51 pub messaging: Option<MessagingSettings>,
52}
53
54/// FHIR Messaging channel configuration.
55#[derive(Debug, Clone)]
56pub struct MessagingSettings {
57 /// Endpoint URL placed in `MessageHeader.source.endpoint`. Typically the
58 /// HFS base URL (`HFS_BASE_URL`).
59 pub source_endpoint: String,
60
61 /// When `true`, dispatch to private/loopback/link-local IPs is permitted.
62 /// Default `false` (SSRF guard on). Set
63 /// `HFS_SUBSCRIPTION_ALLOW_PRIVATE_ENDPOINTS=true` to opt in.
64 pub allow_private_endpoints: bool,
65}
66
67impl Default for SubscriptionConfig {
68 fn default() -> Self {
69 Self {
70 max_retries: 10,
71 retry_initial_delay: Duration::from_secs(1),
72 retry_max_delay: Duration::from_secs(60),
73 retry_backoff_factor: 2.0,
74 handshake_initial_delay: Duration::ZERO,
75 handshake_max_attempts: 1,
76 handshake_retry_initial_delay: Duration::from_secs(1),
77 handshake_retry_max_delay: Duration::from_secs(60),
78 heartbeat_check_interval: Duration::from_secs(30),
79 error_threshold: 3,
80 off_threshold: 10,
81 supported_channel_types: vec!["rest-hook".to_string()],
82 ws_token_lifetime_secs: 30,
83 smtp: None,
84 messaging: None,
85 }
86 }
87}
88
89/// SMTP transport encryption mode.
90#[derive(Debug, Clone, Copy, PartialEq, Eq)]
91pub enum SmtpEncryption {
92 /// Plain SMTP with no transport encryption.
93 None,
94 /// STARTTLS — begin in plaintext and upgrade before AUTH.
95 StartTls,
96 /// Implicit TLS from connect (SMTPS, typically port 465).
97 Tls,
98}
99
100/// SMTP client configuration for the email channel.
101#[derive(Debug, Clone)]
102pub struct SmtpSettings {
103 /// SMTP relay host.
104 pub host: String,
105 /// SMTP relay port.
106 pub port: u16,
107 /// Optional SMTP auth username.
108 pub username: Option<String>,
109 /// Optional SMTP auth password.
110 pub password: Option<String>,
111 /// Transport encryption mode.
112 pub encryption: SmtpEncryption,
113 /// Default `From:` mailbox (RFC 5322). Required when email is enabled;
114 /// subscription headers may override on a per-message basis.
115 pub from_address: String,
116 /// Optional default subject template. If absent, a built-in template is used.
117 pub default_subject: Option<String>,
118 /// Per-send timeout in seconds.
119 pub timeout_secs: u64,
120}