ave-http 0.11.0

HTTP API server for the Ave runtime, auth system, and admin surface
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
//! Configuration wrapper types for OpenAPI documentation
//!
//! These types wrap the core configuration types to provide Serialize and ToSchema support

use ave_bridge::{
    AveExternalDBConfig, AveInternalDBConfig, HttpConfig, ProxyConfig,
    SelfSignedCertConfig,
    auth::{
        ApiKeyConfig, AuthConfig, EndpointRateLimit, LockoutConfig,
        RateLimitConfig, SessionConfig,
    },
};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use utoipa::ToSchema;

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct ConfigHttp {
    /// Core AVE configuration
    pub node: AveConfigHttp,
    /// Path to cryptographic keys
    pub keys_path: String,
    /// Logging configuration
    pub logging: LoggingHttp,
    /// Event sink configuration
    pub sink: SinkConfigHttp,
    pub auth: AuthConfigHttp,
    pub http: HttpConfigHttp,
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub enum MachineSpecHttp {
    /// Use a predefined profile.
    Profile(String),
    /// Supply exact machine dimensions.
    Custom {
        /// Total RAM in megabytes.
        ram_mb: u64,
        /// Available CPU cores.
        cpu_cores: usize,
    },
}

impl From<ave_bridge::MachineSpec> for MachineSpecHttp {
    fn from(value: ave_bridge::MachineSpec) -> Self {
        match value {
            ave_bridge::MachineSpec::Profile(machine_profile) => {
                Self::Profile(machine_profile.to_string())
            }
            ave_bridge::MachineSpec::Custom { ram_mb, cpu_cores } => {
                Self::Custom { ram_mb, cpu_cores }
            }
        }
    }
}

impl From<ave_bridge::config::Config> for ConfigHttp {
    fn from(value: ave_bridge::config::Config) -> Self {
        Self {
            node: AveConfigHttp::from(value.node),
            keys_path: value.keys_path.to_string_lossy().to_string(),
            logging: LoggingHttp::from(value.logging),
            sink: SinkConfigHttp::from(value.sink),
            auth: AuthConfigHttp::from(value.auth),
            http: HttpConfigHttp::from(value.http),
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct AuthConfigHttp {
    pub enable: bool,
    pub durability: bool,
    pub database_path: String,
    pub superadmin: String,
    pub api_key: ApiKeyConfigHttp,
    pub lockout: LockoutConfigHttp,
    pub rate_limit: RateLimitConfigHttp,
    pub session: SessionConfigHttp,
}

impl From<AuthConfig> for AuthConfigHttp {
    fn from(value: AuthConfig) -> Self {
        Self {
            enable: value.enable,
            database_path: value.database_path.to_string_lossy().to_string(),
            superadmin: value.superadmin,
            durability: value.durability,
            api_key: ApiKeyConfigHttp::from(value.api_key),
            lockout: LockoutConfigHttp::from(value.lockout),
            rate_limit: RateLimitConfigHttp::from(value.rate_limit),
            session: SessionConfigHttp::from(value.session),
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct ApiKeyConfigHttp {
    pub default_ttl_seconds: i64,
    pub max_keys_per_user: u32,
    pub prefix: String,
}

impl From<ApiKeyConfig> for ApiKeyConfigHttp {
    fn from(value: ApiKeyConfig) -> Self {
        Self {
            default_ttl_seconds: value.default_ttl_seconds,
            max_keys_per_user: value.max_keys_per_user,
            prefix: value.prefix,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct LockoutConfigHttp {
    pub max_attempts: u32,
    pub duration_seconds: i64,
}

impl From<LockoutConfig> for LockoutConfigHttp {
    fn from(value: LockoutConfig) -> Self {
        Self {
            max_attempts: value.max_attempts,
            duration_seconds: value.duration_seconds,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct RateLimitConfigHttp {
    pub enable: bool,
    pub window_seconds: i64,
    pub max_requests: u32,
    pub limit_by_key: bool,
    pub limit_by_ip: bool,
    pub cleanup_interval_seconds: i64,
    pub sensitive_endpoints: Vec<EndpointRateLimitHttp>,
}

impl From<RateLimitConfig> for RateLimitConfigHttp {
    fn from(value: RateLimitConfig) -> Self {
        Self {
            enable: value.enable,
            window_seconds: value.window_seconds,
            max_requests: value.max_requests,
            limit_by_key: value.limit_by_key,
            limit_by_ip: value.limit_by_ip,
            cleanup_interval_seconds: value.cleanup_interval_seconds,
            sensitive_endpoints: value
                .sensitive_endpoints
                .into_iter()
                .map(EndpointRateLimitHttp::from)
                .collect(),
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct EndpointRateLimitHttp {
    pub endpoint: String,
    pub max_requests: u32,
    pub window_seconds: Option<i64>,
}

impl From<EndpointRateLimit> for EndpointRateLimitHttp {
    fn from(value: EndpointRateLimit) -> Self {
        Self {
            endpoint: value.endpoint,
            max_requests: value.max_requests,
            window_seconds: value.window_seconds,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct SessionConfigHttp {
    pub audit_enable: bool,
    pub audit_retention_days: u32,
    pub audit_max_entries: u32,
}

impl From<SessionConfig> for SessionConfigHttp {
    fn from(value: SessionConfig) -> Self {
        Self {
            audit_enable: value.audit_enable,
            audit_retention_days: value.audit_retention_days,
            audit_max_entries: value.audit_max_entries,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct HttpConfigHttp {
    pub http_address: String,
    pub https_address: Option<String>,
    pub https_cert_path: Option<String>,
    pub https_private_key_path: Option<String>,
    pub enable_doc: bool,
    pub proxy: ProxyConfigHttp,
    pub cors: CorsConfigHttp,
    pub self_signed_cert: SelfSignedCertConfigHttp,
}

impl From<HttpConfig> for HttpConfigHttp {
    fn from(value: HttpConfig) -> Self {
        Self {
            http_address: value.http_address,
            https_address: value.https_address,
            https_cert_path: value
                .https_cert_path
                .map(|x| x.to_string_lossy().to_string()),
            https_private_key_path: value
                .https_private_key_path
                .map(|x| x.to_string_lossy().to_string()),
            enable_doc: value.enable_doc,
            proxy: ProxyConfigHttp::from(value.proxy),
            cors: CorsConfigHttp::from(value.cors),
            self_signed_cert: SelfSignedCertConfigHttp::from(
                value.self_signed_cert,
            ),
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct ProxyConfigHttp {
    pub trusted_proxies: Vec<String>,
    pub trust_x_forwarded_for: bool,
    pub trust_x_real_ip: bool,
}

impl From<ProxyConfig> for ProxyConfigHttp {
    fn from(value: ProxyConfig) -> Self {
        Self {
            trusted_proxies: value.trusted_proxies,
            trust_x_forwarded_for: value.trust_x_forwarded_for,
            trust_x_real_ip: value.trust_x_real_ip,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct SelfSignedCertConfigHttp {
    /// Enable automatic self-signed certificate generation
    pub enabled: bool,
    /// Common Name for the certificate (e.g., "localhost")
    pub common_name: String,
    /// Subject Alternative Names (additional hostnames/IPs)
    pub san: Vec<String>,
    /// Certificate validity in days
    pub validity_days: u32,
    /// Days before expiration to trigger renewal
    pub renew_before_days: u32,
    /// Check interval in seconds for certificate expiration
    pub check_interval_secs: u64,
}

impl From<SelfSignedCertConfig> for SelfSignedCertConfigHttp {
    fn from(value: SelfSignedCertConfig) -> Self {
        Self {
            enabled: value.enabled,
            common_name: value.common_name,
            san: value.san,
            validity_days: value.validity_days,
            renew_before_days: value.renew_before_days,
            check_interval_secs: value.check_interval_secs,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct CorsConfigHttp {
    pub enabled: bool,
    pub allow_any_origin: bool,
    pub allowed_origins: Vec<String>,
    pub allow_credentials: bool,
}

impl From<ave_bridge::CorsConfig> for CorsConfigHttp {
    fn from(value: ave_bridge::CorsConfig) -> Self {
        Self {
            enabled: value.enabled,
            allow_any_origin: value.allow_any_origin,
            allowed_origins: value.allowed_origins,
            allow_credentials: value.allow_credentials,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct AveConfigHttp {
    /// Keypair algorithm
    pub keypair_algorithm: String,
    /// Hash algorithm
    pub hash_algorithm: String,
    /// AVE database path
    pub internal_db: AveStoreConfigHttp,
    /// External database path
    pub external_db: AveStoreConfigHttp,
    /// Network configuration
    pub network: NetworkConfigHttp,
    /// Directory for smart contracts
    pub contracts_path: String,
    /// Whether to automatically accept all events (development mode)
    pub always_accept: bool,
    /// Whether the node is running in safe mode
    pub safe_mode: bool,
    /// Garbage collector interval in seconds
    pub tracking_size: usize,
    /// Is a service node
    pub is_service: bool,
    /// Whether the node rejects tracker opaque events
    pub only_clear_events: bool,
    /// Sync protocol configuration
    pub sync: SyncConfigHttp,

    pub spec: Option<MachineSpecHttp>,
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct SyncConfigHttp {
    pub ledger_batch_size: usize,
    pub governance: GovernanceSyncConfigHttp,
    pub tracker: TrackerSyncConfigHttp,
    pub update: UpdateSyncConfigHttp,
    pub reboot: RebootSyncConfigHttp,
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct GovernanceSyncConfigHttp {
    pub interval_secs: u64,
    pub sample_size: usize,
    pub response_timeout_secs: u64,
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct TrackerSyncConfigHttp {
    pub interval_secs: u64,
    pub page_size: usize,
    pub response_timeout_secs: u64,
    pub update_batch_size: usize,
    pub update_timeout_secs: u64,
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct UpdateSyncConfigHttp {
    pub round_retry_interval_secs: u64,
    pub max_round_retries: usize,
    pub witness_retry_count: usize,
    pub witness_retry_interval_secs: u64,
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct RebootSyncConfigHttp {
    pub stability_check_interval_secs: u64,
    pub stability_check_max_retries: u64,
    pub diff_retry_schedule_secs: Vec<u64>,
    pub timeout_retry_schedule_secs: Vec<u64>,
}

impl From<ave_bridge::AveConfig> for AveConfigHttp {
    fn from(value: ave_bridge::AveConfig) -> Self {
        Self {
            keypair_algorithm: format!("{:?}", value.keypair_algorithm),
            hash_algorithm: format!("{:?}", value.hash_algorithm),
            internal_db: AveStoreConfigHttp::from(value.internal_db),
            external_db: AveStoreConfigHttp::from(value.external_db),
            network: NetworkConfigHttp::from(value.network),
            contracts_path: value.contracts_path.to_string_lossy().to_string(),
            always_accept: value.always_accept,
            safe_mode: value.safe_mode,
            tracking_size: value.tracking_size,
            is_service: value.is_service,
            only_clear_events: value.only_clear_events,
            sync: SyncConfigHttp {
                ledger_batch_size: value.sync.ledger_batch_size,
                governance: GovernanceSyncConfigHttp {
                    interval_secs: value.sync.governance.interval_secs,
                    sample_size: value.sync.governance.sample_size,
                    response_timeout_secs: value
                        .sync
                        .governance
                        .response_timeout_secs,
                },
                tracker: TrackerSyncConfigHttp {
                    interval_secs: value.sync.tracker.interval_secs,
                    page_size: value.sync.tracker.page_size,
                    response_timeout_secs: value
                        .sync
                        .tracker
                        .response_timeout_secs,
                    update_batch_size: value.sync.tracker.update_batch_size,
                    update_timeout_secs: value.sync.tracker.update_timeout_secs,
                },
                update: UpdateSyncConfigHttp {
                    round_retry_interval_secs: value
                        .sync
                        .update
                        .round_retry_interval_secs,
                    max_round_retries: value.sync.update.max_round_retries,
                    witness_retry_count: value.sync.update.witness_retry_count,
                    witness_retry_interval_secs: value
                        .sync
                        .update
                        .witness_retry_interval_secs,
                },
                reboot: RebootSyncConfigHttp {
                    stability_check_interval_secs: value
                        .sync
                        .reboot
                        .stability_check_interval_secs,
                    stability_check_max_retries: value
                        .sync
                        .reboot
                        .stability_check_max_retries,
                    diff_retry_schedule_secs: value
                        .sync
                        .reboot
                        .diff_retry_schedule_secs,
                    timeout_retry_schedule_secs: value
                        .sync
                        .reboot
                        .timeout_retry_schedule_secs,
                },
            },
            spec: value.spec.map(MachineSpecHttp::from),
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct AveStoreConfigHttp {
    pub db: String,
    pub durability: bool,
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct AveActorsStoreConfigHttp {
    pub ram_mb: Option<u64>,
    pub cpu_cores: Option<usize>,
    pub profile: Option<String>,
    pub durability: bool,
}

impl From<AveInternalDBConfig> for AveStoreConfigHttp {
    fn from(value: AveInternalDBConfig) -> Self {
        Self {
            db: value.db.to_string(),
            durability: value.durability,
        }
    }
}

impl From<AveExternalDBConfig> for AveStoreConfigHttp {
    fn from(value: AveExternalDBConfig) -> Self {
        Self {
            db: value.db.to_string(),
            durability: value.durability,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct NetworkConfigHttp {
    /// The node type (Bootstrap, Addressable, Ephemeral)
    pub node_type: String,
    /// Listen addresses for the network
    pub listen_addresses: Vec<String>,
    /// External addresses advertised to the network
    pub external_addresses: Vec<String>,
    /// Bootstrap nodes to connect to
    pub boot_nodes: Vec<RoutingNodeHttp>,
    /// Routing configuration (DHT and discovery settings)
    pub routing: RoutingConfigHttp,
    /// Control list configuration (allow/deny lists)
    pub control_list: ControlListConfigHttp,
    /// Memory-based connection limit policy ("disabled", "80% of system RAM", "512 MB")
    pub memory_limits: String,
    /// Maximum accepted application message payload in bytes.
    pub max_app_message_bytes: usize,
    /// Maximum buffered inbound bytes per peer while waiting for helper delivery.
    pub max_pending_inbound_bytes_per_peer: usize,
    /// Maximum buffered outbound bytes per peer while disconnected.
    pub max_pending_outbound_bytes_per_peer: usize,
    /// Maximum total buffered inbound bytes across all peers while waiting for helper delivery.
    /// `0` means no global limit.
    pub max_pending_inbound_bytes_total: usize,
    /// Maximum total buffered outbound bytes across all peers while disconnected.
    /// `0` means no global limit.
    pub max_pending_outbound_bytes_total: usize,
}

impl From<ave_bridge::NetworkConfig> for NetworkConfigHttp {
    fn from(value: ave_bridge::NetworkConfig) -> Self {
        Self {
            node_type: format!("{:?}", value.node_type),
            listen_addresses: value.listen_addresses,
            external_addresses: value.external_addresses,
            boot_nodes: value
                .boot_nodes
                .into_iter()
                .map(RoutingNodeHttp::from)
                .collect(),
            routing: RoutingConfigHttp::from(value.routing),
            control_list: ControlListConfigHttp::from(value.control_list),
            memory_limits: value.memory_limits.to_string(),
            max_app_message_bytes: value.max_app_message_bytes,
            max_pending_outbound_bytes_per_peer: value
                .max_pending_outbound_bytes_per_peer,
            max_pending_inbound_bytes_per_peer: value
                .max_pending_inbound_bytes_per_peer,
            max_pending_outbound_bytes_total: value
                .max_pending_outbound_bytes_total,
            max_pending_inbound_bytes_total: value
                .max_pending_inbound_bytes_total,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct RoutingConfigHttp {
    /// Whether to enable random walks in the Kademlia DHT
    pub dht_random_walk: bool,
    /// Number of active connections over which we interrupt the discovery process
    pub discovery_only_if_under_num: u64,
    /// Allow private addresses in DHT
    pub allow_private_address_in_dht: bool,
    /// Allow DNS addresses in DHT
    pub allow_dns_address_in_dht: bool,
    /// Allow loopback addresses in DHT
    pub allow_loop_back_address_in_dht: bool,
    /// Use disjoint query paths in Kademlia
    pub kademlia_disjoint_query_paths: bool,
}

impl From<ave_bridge::RoutingConfig> for RoutingConfigHttp {
    fn from(value: ave_bridge::RoutingConfig) -> Self {
        Self {
            dht_random_walk: value.get_dht_random_walk(),
            discovery_only_if_under_num: value.get_discovery_limit(),
            allow_private_address_in_dht: value
                .get_allow_private_address_in_dht(),
            allow_dns_address_in_dht: value.get_allow_dns_address_in_dht(),
            allow_loop_back_address_in_dht: value
                .get_allow_loop_back_address_in_dht(),
            kademlia_disjoint_query_paths: value
                .get_kademlia_disjoint_query_paths(),
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct ControlListConfigHttp {
    /// Enable control lists (allow/block)
    pub enable: bool,
    /// Nodes allowed to make and receive connections
    pub allow_list: Vec<String>,
    /// Nodes that are not allowed to make and receive connections
    pub block_list: Vec<String>,
    /// Services where the node will query the list of allowed nodes
    pub service_allow_list: Vec<String>,
    /// Services where the node will query the list of blocked nodes
    pub service_block_list: Vec<String>,
    /// Time interval in seconds for updating the lists
    pub interval_request_secs: u64,
    /// Timeout in seconds for each control-list HTTP request
    pub request_timeout_secs: u64,
    /// Maximum number of concurrent HTTP requests while refreshing lists
    pub max_concurrent_requests: usize,
}

impl From<ave_bridge::ControlListConfig> for ControlListConfigHttp {
    fn from(value: ave_bridge::ControlListConfig) -> Self {
        Self {
            enable: value.get_enable(),
            allow_list: value.get_allow_list(),
            block_list: value.get_block_list(),
            service_allow_list: value.get_service_allow_list(),
            service_block_list: value.get_service_block_list(),
            interval_request_secs: value.get_interval_request().as_secs(),
            request_timeout_secs: value.get_request_timeout().as_secs(),
            max_concurrent_requests: value.get_max_concurrent_requests(),
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct RoutingNodeHttp {
    /// Peer ID of the routing node
    pub peer_id: String,
    /// Addresses to connect to this node
    pub address: Vec<String>,
}

impl From<ave_bridge::RoutingNode> for RoutingNodeHttp {
    fn from(value: ave_bridge::RoutingNode) -> Self {
        Self {
            peer_id: value.peer_id.to_string(),
            address: value.address.iter().map(|a| a.to_string()).collect(),
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct LoggingHttp {
    /// Logging output configuration
    pub output: LoggingOutputHttp,
    /// API URL for remote logging (optional)
    pub api_url: Option<String>,
    /// Path to the log file
    pub file_path: String,
    /// Log rotation policy (Size, Hourly, Daily, Weekly, Monthly, Yearly, Never)
    pub rotation: String,
    /// Maximum size of the log file in bytes
    pub max_size: usize,
    /// Maximum number of log files to keep
    pub max_files: usize,
    /// Log level filter (e.g. "info", "debug", "info,ave=debug")
    pub level: String,
}

impl From<ave_bridge::LoggingConfig> for LoggingHttp {
    fn from(value: ave_bridge::LoggingConfig) -> Self {
        Self {
            output: LoggingOutputHttp::from(value.output),
            api_url: value.api_url,
            file_path: value.file_path.to_string_lossy().to_string(),
            rotation: format!("{:?}", value.rotation),
            max_size: value.max_size,
            max_files: value.max_files,
            level: value.level,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct LoggingOutputHttp {
    /// Enable logging to stdout
    pub stdout: bool,
    /// Enable logging to file
    pub file: bool,
    /// Enable logging to remote API
    pub api: bool,
}

impl From<ave_bridge::LoggingOutput> for LoggingOutputHttp {
    fn from(value: ave_bridge::LoggingOutput) -> Self {
        Self {
            stdout: value.stdout,
            file: value.file,
            api: value.api,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct SinkConfigHttp {
    /// Map of sink configurations by name
    pub sinks: BTreeMap<String, Vec<SinkServerHttp>>,
    /// Authentication method for sinks
    pub auth: String,
    /// Username for sink authentication
    pub username: String,
}

impl From<ave_bridge::SinkConfig> for SinkConfigHttp {
    fn from(value: ave_bridge::SinkConfig) -> Self {
        Self {
            sinks: value
                .sinks
                .into_iter()
                .map(|(k, v)| {
                    (k, v.into_iter().map(SinkServerHttp::from).collect())
                })
                .collect(),
            auth: value.auth,
            username: value.username,
        }
    }
}

#[derive(Debug, Serialize, Clone, ToSchema, Deserialize)]
pub struct SinkServerHttp {
    /// Server identifier
    pub server: String,
    /// Event types to send to this sink (Create, Fact, Transfer, Confirm, Reject, EOL, All)
    pub events: Vec<String>,
    /// URL endpoint for the sink
    pub url: String,
    /// Whether authentication is required for this sink
    pub auth: bool,
    /// Parallel sends allowed for this sink
    pub concurrency: usize,
    /// Maximum queued events for this sink
    pub queue_capacity: usize,
    /// Queue policy when the sink queue is full
    pub queue_policy: String,
    /// Routing strategy across sink workers
    pub routing_strategy: String,
    /// TCP connect timeout in milliseconds
    pub connect_timeout_ms: u64,
    /// Request timeout in milliseconds
    pub request_timeout_ms: u64,
    /// Maximum transient retries per delivery
    pub max_retries: usize,
}

impl From<ave_bridge::SinkServer> for SinkServerHttp {
    fn from(value: ave_bridge::SinkServer) -> Self {
        Self {
            server: value.server,
            events: value.events.into_iter().map(|e| e.to_string()).collect(),
            url: value.url,
            auth: value.auth,
            concurrency: value.concurrency,
            queue_capacity: value.queue_capacity,
            queue_policy: match value.queue_policy {
                ave_bridge::SinkQueuePolicy::DropOldest => {
                    "drop_oldest".to_owned()
                }
                ave_bridge::SinkQueuePolicy::DropNewest => {
                    "drop_newest".to_owned()
                }
            },
            routing_strategy: match value.routing_strategy {
                ave_bridge::SinkRoutingStrategy::OrderedBySubject => {
                    "ordered_by_subject".to_owned()
                }
                ave_bridge::SinkRoutingStrategy::UnorderedRoundRobin => {
                    "unordered_round_robin".to_owned()
                }
            },
            connect_timeout_ms: value.connect_timeout_ms,
            request_timeout_ms: value.request_timeout_ms,
            max_retries: value.max_retries,
        }
    }
}