1use crate::event::EventLoggerConfig;
4use serde::{Deserialize, Serialize};
5use std::time::Duration;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct TapHttpConfig {
10 pub host: String,
12
13 pub port: u16,
15
16 pub didcomm_endpoint: String,
18
19 pub rate_limit: Option<RateLimitConfig>,
21
22 pub tls: Option<TlsConfig>,
24
25 pub request_timeout_secs: u64,
27
28 #[serde(skip_serializing_if = "Option::is_none")]
31 pub event_logger: Option<EventLoggerConfig>,
32
33 pub enable_web_did: bool,
37
38 pub max_agents: usize,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct RateLimitConfig {
46 pub max_requests: u32,
48
49 pub window_secs: u64,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct TlsConfig {
56 pub cert_path: String,
58
59 pub key_path: String,
61}
62
63impl Default for TapHttpConfig {
64 fn default() -> Self {
65 Self {
66 host: "127.0.0.1".to_string(),
67 port: 8000,
68 didcomm_endpoint: "/didcomm".to_string(),
69 rate_limit: None,
70 tls: None,
71 request_timeout_secs: 30,
72 event_logger: Some(EventLoggerConfig::default()),
73 enable_web_did: false,
74 max_agents: 100,
75 }
76 }
77}
78
79impl TapHttpConfig {
80 pub fn server_addr(&self) -> String {
82 format!("{}:{}", self.host, self.port)
83 }
84
85 pub fn didcomm_url(&self, secure: bool) -> String {
87 let protocol = if secure || self.tls.is_some() {
88 "https"
89 } else {
90 "http"
91 };
92 format!(
93 "{}://{}:{}{}",
94 protocol, self.host, self.port, self.didcomm_endpoint
95 )
96 }
97
98 pub fn request_timeout(&self) -> Duration {
100 Duration::from_secs(self.request_timeout_secs)
101 }
102}