capy-core 0.10.0

Typed configuration, application context, and errors for the Capy web framework.
Documentation
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
use crate::{AppError, Result};
use figment::{
    providers::{Env, Format, Serialized, Toml},
    Figment,
};
use serde::{Deserialize, Serialize};
use std::{collections::BTreeMap, path::Path};

/// Application and database settings, resolved before startup.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct AppConfig {
    /// Optional private object storage settings (`STORAGE_*`).
    #[serde(default)]
    pub storage: crate::StorageSettings,
    /// Optional outbound communication settings (`MAIL_*`).
    #[serde(default)]
    pub mail: crate::MailSettings,
    /// Optional durable worker settings (`JOBS_*`).
    #[serde(default)]
    pub jobs: crate::JobsSettings,
    /// Optional identity subsystem settings (`AUTH_*`); activated by `App::auth`.
    #[serde(default)]
    pub auth: crate::AuthSettings,
    /// HTTP server settings.
    pub app: AppSettings,
    /// Database connection settings.
    pub database: DatabaseSettings,
    /// Listener overrides and bounded graceful shutdown (`SERVER_*`).
    pub server: ServerSettings,
    /// Request and readiness bounds (`HTTP_*`).
    pub http: HttpSettings,
    /// API document metadata and explicit documentation exposure (`API_*`).
    pub api: ApiSettings,
}

/// Small application-owned API metadata. Documentation is disabled by default.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct ApiSettings {
    /// Reject undocumented public `/api` routes, unless explicitly exempted in Rust.
    pub require_documented_routes: bool,
    /// Document title; defaults to the application name when omitted.
    pub title: Option<String>,
    /// Public API contract version, independent of the Capy package version.
    pub version: String,
    /// Explicitly expose GET /openapi.json, including in production.
    pub openapi: bool,
    /// Expose Scalar at /docs/api in development/test only; also enables the schema there.
    pub docs: bool,
}

impl Default for ApiSettings {
    fn default() -> Self {
        Self {
            require_documented_routes: false,
            title: None,
            version: "1.0.0".into(),
            openapi: false,
            docs: false,
        }
    }
}

/// Listener settings. Unspecified host/port retain legacy `APP_HOST`/`APP_PORT`.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct ServerSettings {
    /// Explicit listener interface or hostname; overrides `app.host`.
    pub host: Option<String>,
    /// Explicit listener port; overrides `app.port`.
    pub port: Option<u16>,
    /// Maximum graceful drain time in seconds (1..=3600).
    pub shutdown_timeout_seconds: u64,
}

impl Default for ServerSettings {
    fn default() -> Self {
        Self {
            host: None,
            port: None,
            shutdown_timeout_seconds: 10,
        }
    }
}

/// Small HTTP policy surface, expressed in seconds and bytes to avoid ambiguous units.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct HttpSettings {
    /// Explicit socket/trusted proxy client identity policy.
    pub client_ip: crate::ClientIpSettings,
    /// Deadline until response headers (0 disables it, otherwise at most 86400).
    pub request_timeout_seconds: u64,
    /// Independent readiness database probe timeout (1..=30 seconds).
    pub readiness_timeout_seconds: u64,
    /// Default body limit in bytes (1..=1073741824); native route overrides remain possible.
    pub max_body_bytes: usize,
    /// Enable negotiated gzip response compression with Tower's default predicate.
    pub compression: bool,
}

impl Default for HttpSettings {
    fn default() -> Self {
        Self {
            client_ip: crate::ClientIpSettings::default(),
            request_timeout_seconds: 30,
            readiness_timeout_seconds: 2,
            max_body_bytes: 2 * 1024 * 1024,
            compression: true,
        }
    }
}

/// HTTP server and logging settings. Environment variables use `APP_`.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct AppSettings {
    /// Explicit public application URL, never inferred from request headers.
    pub url: Option<String>,
    /// Display name of this application.
    pub name: String,
    /// `development`, `test`, or `production`.
    pub environment: String,
    /// Interface or hostname to bind.
    pub host: String,
    /// TCP port to bind (zero allows the OS to choose).
    pub port: u16,
}

impl Default for AppSettings {
    fn default() -> Self {
        Self {
            url: None,
            name: "Capy".into(),
            environment: "development".into(),
            host: "127.0.0.1".into(),
            port: 8000,
        }
    }
}

/// SeaORM connection settings. Environment variables use `DATABASE_`.
#[derive(Clone, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct DatabaseSettings {
    /// PostgreSQL or SQLite connection URL. Debug output redacts this value.
    pub url: String,
    /// Maximum pool size; SQLite in-memory databases always use one connection.
    pub max_connections: u32,
    /// Maximum time to initialize the connection pool, in seconds.
    pub connect_timeout_seconds: u64,
    /// Minimum idle connections; cannot exceed the configured maximum.
    pub min_connections: u32,
    /// Maximum wait for an available connection, in seconds.
    pub acquire_timeout_seconds: u64,
    /// Maximum idle lifetime in seconds (1..=86400).
    pub idle_timeout_seconds: u64,
}

impl std::fmt::Debug for DatabaseSettings {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("DatabaseSettings")
            .field("url", &"[redacted]")
            .field("max_connections", &self.max_connections)
            .field("connect_timeout_seconds", &self.connect_timeout_seconds)
            .field("min_connections", &self.min_connections)
            .field("acquire_timeout_seconds", &self.acquire_timeout_seconds)
            .field("idle_timeout_seconds", &self.idle_timeout_seconds)
            .finish()
    }
}

impl Default for DatabaseSettings {
    fn default() -> Self {
        Self {
            url: String::new(),
            max_connections: 10,
            connect_timeout_seconds: 10,
            min_connections: 0,
            acquire_timeout_seconds: 10,
            idle_timeout_seconds: 600,
        }
    }
}

impl AppConfig {
    /// Load from the current project directory.
    pub fn load() -> Result<Self> {
        Self::load_from(".")
    }

    /// Resolve defaults < TOML files < `.env` < process environment.
    /// Reading `.env` never mutates the process environment.
    pub fn load_from(root: impl AsRef<Path>) -> Result<Self> {
        Self::load_sections(root.as_ref(), true, false)
    }

    /// Load metadata for offline contract export. A database URL is not required.
    /// All supplied configuration is parsed, but no connection is ever opened.
    pub fn load_for_contracts() -> Result<Self> {
        Self::load_sections(Path::new("."), false, false)
    }

    /// Load normal configuration plus a sectioned `config/test.toml` overlay.
    /// The environment is always `test` and the URL always isolated SQLite; the test
    /// harness may explicitly provision PostgreSQL afterward. Never mutates process env.
    pub fn load_for_tests(root: impl AsRef<Path>) -> Result<Self> {
        let root = root.as_ref();
        let base = Self::load_sections(root, false, true)?;
        let mut config: Self = Figment::from(Serialized::defaults(base))
            .merge(Toml::file(root.join("config/test.toml")))
            .extract()
            .map_err(|_| {
                AppError::Configuration("Invalid test settings in config/test.toml.".into())
            })?;
        config.app.environment = "test".into();
        config.database.url = "sqlite::memory:".into();
        config.validate()?;
        Ok(config)
    }

    fn load_sections(root: &Path, require_database: bool, test: bool) -> Result<Self> {
        let mut app_env = BTreeMap::new();
        let mut db_env = BTreeMap::new();
        let mut server_env = BTreeMap::new();
        let mut http_env = serde_json::Map::new();
        let mut client_ip_env = serde_json::Map::new();
        let mut api_env = BTreeMap::new();
        let mut auth_env = serde_json::Map::new();
        let mut password_env = serde_json::Map::new();
        let mut throttle_env = serde_json::Map::new();
        let mut throttle_ip_env = serde_json::Map::new();
        let mut throttle_account_env = serde_json::Map::new();
        let mut jobs_env = BTreeMap::new();
        let mut storage_env = BTreeMap::new();
        let mut mail_env = serde_json::Map::new();
        let mut smtp_env = serde_json::Map::new();
        match dotenvy::from_path_iter(root.join(".env")) {
            Ok(entries) => {
                for entry in entries {
                    let (key, value) = entry.map_err(|_| {
                        AppError::Configuration("Could not parse .env. Check its syntax.".into())
                    })?;
                    let value = if matches!(
                        key.as_str(),
                        "MAIL_SMTP_USERNAME"
                            | "MAIL_SMTP_PASSWORD"
                            | "STORAGE_ACCESS_KEY_ID"
                            | "STORAGE_SECRET_ACCESS_KEY"
                            | "STORAGE_SESSION_TOKEN"
                    ) {
                        serde_json::Value::String(value)
                    } else {
                        serde_json::from_str::<serde_json::Value>(&value)
                            .unwrap_or(serde_json::Value::String(value))
                    };
                    if let Some(key) = key.strip_prefix("MAIL_SMTP_") {
                        smtp_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("MAIL_") {
                        mail_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("JOBS_") {
                        jobs_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("STORAGE_") {
                        storage_env.insert(key.to_lowercase(), value);
                    } else if key.starts_with("AUTH_PASSWORD_")
                        && key != "AUTH_PASSWORD_RESET_LIFETIME_SECONDS"
                    {
                        password_env.insert(key[14..].to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("AUTH_THROTTLE_IP_") {
                        throttle_ip_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("AUTH_THROTTLE_ACCOUNT_") {
                        throttle_account_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("AUTH_THROTTLE_") {
                        throttle_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("AUTH_") {
                        auth_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("APP_") {
                        app_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("DATABASE_") {
                        db_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("SERVER_") {
                        server_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("HTTP_CLIENT_IP_") {
                        client_ip_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("HTTP_") {
                        http_env.insert(key.to_lowercase(), value);
                    } else if let Some(key) = key.strip_prefix("API_") {
                        api_env.insert(key.to_lowercase(), value);
                    }
                }
            }
            Err(dotenvy::Error::Io(e)) if e.kind() == std::io::ErrorKind::NotFound => {}
            Err(_) => return Err(AppError::Configuration("Could not read .env.".into())),
        }
        let app = Figment::from(Serialized::defaults(AppSettings::default()))
            .merge(Toml::file(root.join("config/app.toml")))
            .merge(Serialized::defaults(app_env))
            .merge(Env::prefixed("APP_"))
            .extract()
            .map_err(|_| {
                AppError::Configuration(
                    "Invalid application settings. Check config/app.toml and APP_* variables."
                        .into(),
                )
            })?;
        let database = Figment::from(Serialized::defaults(DatabaseSettings::default()))
            .merge(Toml::file(root.join("config/database.toml")))
            .merge(Serialized::defaults(db_env))
            .merge(Env::prefixed("DATABASE_"))
            .extract()
            .map_err(|_| AppError::Configuration(
                "Invalid database settings. Check config/database.toml and DATABASE_* variables.".into(),
            ))?;
        let server = Figment::from(Serialized::defaults(ServerSettings::default()))
            .merge(Toml::file(root.join("config/server.toml")))
            .merge(Serialized::defaults(server_env))
            .merge(Env::prefixed("SERVER_"))
            .extract()
            .map_err(|_| AppError::Configuration(
                "Invalid server settings. Check config/server.toml and SERVER_* variables; ports must be 0..=65535 and deadlines integer seconds.".into()))?;
        http_env.insert("client_ip".into(), serde_json::Value::Object(client_ip_env));
        let http = Figment::from(Serialized::defaults(HttpSettings::default()))
            .merge(Toml::file(root.join("config/http.toml")))
            .merge(Serialized::defaults(http_env))
            .merge(Env::prefixed("HTTP_").map(|key| key.as_str().to_lowercase().replacen("client_ip_", "client_ip.", 1).into()))
            .extract()
            .map_err(|_| AppError::Configuration(
                "Invalid HTTP settings. Check config/http.toml and HTTP_* variables: deadlines use integer seconds, body limits integer bytes; client_ip.strategy must be direct/forwarded/x-forwarded-for/x-real-ip, trusted_proxies a CIDR array, and require_proxy a boolean.".into()))?;
        let api = Figment::from(Serialized::defaults(ApiSettings::default()))
            .merge(Toml::file(root.join("config/api.toml")))
            .merge(Serialized::defaults(api_env))
            .merge(Env::prefixed("API_"))
            .extract()
            .map_err(|_| {
                AppError::Configuration(
                    "Invalid API settings. Check config/api.toml and API_* variables.".into(),
                )
            })?;
        throttle_env.insert("ip".into(), serde_json::Value::Object(throttle_ip_env));
        throttle_env.insert(
            "account".into(),
            serde_json::Value::Object(throttle_account_env),
        );
        auth_env.insert("throttle".into(), serde_json::Value::Object(throttle_env));
        auth_env.insert("password".into(), serde_json::Value::Object(password_env));
        let auth = Figment::from(Serialized::defaults(crate::AuthSettings::default()))
            .merge(Toml::file(root.join("config/auth.toml")))
            .merge(Serialized::defaults(auth_env))
            .merge(Env::prefixed("AUTH_").map(|key| {
                let key = key.as_str().to_lowercase();
                if let Some(setting) = key.strip_prefix("throttle_") {
                    return format!("throttle.{}", setting.replacen("ip_", "ip.", 1).replacen("account_", "account.", 1)).into();
                }
                match key.strip_prefix("password_") {
                    Some(setting) if setting != "reset_lifetime_seconds" => {
                        format!("password.{setting}").into()
                    }
                    _ => key.into(),
                }
            }))
            .extract()
            .map_err(|_| {
                AppError::Configuration(
                    "Invalid auth settings. Check config/auth.toml and AUTH_* variables; use [password] hash_concurrency = \"auto\" or an integer, integer cost/queue limits, and AUTH_PASSWORD_* environment overrides.".into(),
                )
            })?;
        let jobs = Figment::from(Serialized::defaults(crate::JobsSettings::default()))
            .merge(Toml::file(root.join("config/jobs.toml")))
            .merge(Serialized::defaults(jobs_env))
            .merge(Env::prefixed("JOBS_"))
            .extract()
            .map_err(|_| {
                AppError::Configuration(
                    "Invalid jobs settings. Check config/jobs.toml and JOBS_* variables.".into(),
                )
            })?;
        for (key, variable) in [
            ("access_key_id", "STORAGE_ACCESS_KEY_ID"),
            ("secret_access_key", "STORAGE_SECRET_ACCESS_KEY"),
            ("session_token", "STORAGE_SESSION_TOKEN"),
        ] {
            match std::env::var(variable) {
                Ok(value) => {
                    storage_env.insert(key.into(), serde_json::Value::String(value));
                }
                Err(std::env::VarError::NotPresent) => {}
                Err(_) => {
                    return Err(AppError::Configuration(
                        "Storage credentials must be valid UTF-8 (values redacted).".into(),
                    ))
                }
            }
        }
        let storage = Figment::from(Serialized::defaults(crate::StorageSettings::default()))
            .merge(Toml::file(root.join("config/storage.toml")))
            .merge(Serialized::defaults(storage_env))
            .merge(Env::prefixed("STORAGE_").ignore(&["access_key_id", "secret_access_key", "session_token"]))
            .extract()
            .map_err(|_| AppError::Configuration("Invalid storage settings. Check config/storage.toml and STORAGE_* variables (credentials redacted).".into()))?;
        // Credentials are literal text, even when they resemble numbers, booleans
        // or JSON. Preserve their bytes instead of applying environment coercion.
        for (key, variable) in [
            ("username", "MAIL_SMTP_USERNAME"),
            ("password", "MAIL_SMTP_PASSWORD"),
        ] {
            match std::env::var(variable) {
                Ok(value) => {
                    smtp_env.insert(key.into(), serde_json::Value::String(value));
                }
                Err(std::env::VarError::NotPresent) => {}
                Err(_) => {
                    return Err(AppError::Configuration(
                        "SMTP credentials must be valid UTF-8 (values redacted).".into(),
                    ));
                }
            }
        }
        mail_env.insert("smtp".into(), serde_json::Value::Object(smtp_env));
        let mail = Figment::from(Serialized::defaults(crate::MailSettings::default()))
            .merge(Toml::file(root.join("config/mail.toml")))
            .merge(Serialized::defaults(mail_env))
            .merge(Env::prefixed("MAIL_").ignore(&["smtp_username", "smtp_password"]).map(|key| key.as_str().to_lowercase().replacen("smtp_", "smtp.", 1).into()))
            .extract()
            .map_err(|_| AppError::Configuration("Invalid mail settings. Check config/mail.toml and MAIL_* variables (credentials redacted).".into()))?;
        let mut config = Self {
            storage,
            mail,
            jobs,
            auth,
            app,
            database,
            server,
            http,
            api,
        };
        if test {
            config.app.environment = "test".into();
            config.database.url = "sqlite::memory:".into();
        }
        config.validate_application()?;
        if require_database {
            config.database.validate()?;
        }
        Ok(config)
    }

    /// Validate manually constructed configuration as well as loaded settings.
    pub fn validate(&self) -> Result<()> {
        self.validate_application()?;
        self.database.validate()
    }

    fn validate_application(&self) -> Result<()> {
        self.http.client_ip.validate()?;
        self.auth.password.concurrency()?;
        self.auth.throttle.validate()?;
        self.jobs.validate()?;
        self.mail.validate()?;
        self.storage
            .validate(self.app.environment == "production")?;
        if self
            .api
            .title
            .as_ref()
            .is_some_and(|title| title.trim().is_empty())
            || self.api.version.trim().is_empty()
        {
            return Err(AppError::Configuration(
                "API_TITLE (when set) and API_VERSION must not be empty.".into(),
            ));
        }
        if self.app.name.trim().is_empty() || self.app.host.trim().is_empty() {
            return Err(AppError::Configuration(
                "APP_NAME and APP_HOST cannot be empty.".into(),
            ));
        }
        if !matches!(
            self.app.environment.as_str(),
            "development" | "test" | "production"
        ) {
            return Err(AppError::Configuration(
                "APP_ENVIRONMENT must be development, test, or production.".into(),
            ));
        }
        if self.host().trim().is_empty() || self.host().chars().any(char::is_whitespace) {
            return Err(AppError::Configuration(
                "SERVER_HOST must be a hostname or IP address without whitespace.".into(),
            ));
        }
        if self.app.environment == "production" && self.port() == 0 {
            return Err(AppError::Configuration(
                "The production server port must be 1..=65535.".into(),
            ));
        }
        if !(1..=3600).contains(&self.server.shutdown_timeout_seconds) {
            return Err(AppError::Configuration(
                "SERVER_SHUTDOWN_TIMEOUT_SECONDS must be 1..=3600.".into(),
            ));
        }
        if self.http.request_timeout_seconds > 86400 {
            return Err(AppError::Configuration("HTTP_REQUEST_TIMEOUT_SECONDS must be 0..=86400 (0 intentionally disables the deadline).".into()));
        }
        if !(1..=30).contains(&self.http.readiness_timeout_seconds) {
            return Err(AppError::Configuration(
                "HTTP_READINESS_TIMEOUT_SECONDS must be 1..=30.".into(),
            ));
        }
        if !(1..=1024 * 1024 * 1024).contains(&self.http.max_body_bytes) {
            return Err(AppError::Configuration(
                "HTTP_MAX_BODY_BYTES must be 1..=1073741824.".into(),
            ));
        }
        Ok(())
    }

    /// Effective listener host, including explicit server overrides.
    pub fn host(&self) -> &str {
        self.server.host.as_deref().unwrap_or(&self.app.host)
    }

    /// Effective listener port, including explicit server overrides.
    pub fn port(&self) -> u16 {
        self.server.port.unwrap_or(self.app.port)
    }
}

impl DatabaseSettings {
    /// Validate supported backends and pool limits without exposing credentials.
    pub fn validate(&self) -> Result<()> {
        if self.url.trim().is_empty() {
            return Err(AppError::Configuration(
                "Database configuration error: DATABASE_URL is missing.".into(),
            ));
        }
        if !(self.url.starts_with("postgres://")
            || self.url.starts_with("postgresql://")
            || self.url.starts_with("sqlite:"))
        {
            return Err(AppError::Configuration(
                "DATABASE_URL must use PostgreSQL or SQLite.".into(),
            ));
        }
        if self.max_connections == 0
            || self.max_connections > 10_000
            || self.min_connections > self.max_connections
            || !(1..=3600).contains(&self.connect_timeout_seconds)
            || !(1..=3600).contains(&self.acquire_timeout_seconds)
            || !(1..=86400).contains(&self.idle_timeout_seconds)
        {
            return Err(AppError::Configuration(
                "Invalid database pool: max_connections must be 1..=10000, min_connections <= max_connections, connect/acquire timeouts 1..=3600 seconds, idle timeout 1..=86400 seconds.".into(),
            ));
        }
        Ok(())
    }
}