use serde::{Deserialize, Serialize};
const fn default_statement_timeout_ms() -> u32 {
30_000
}
const fn default_max_rows() -> usize {
1_000
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AdminSqlConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default = "default_statement_timeout_ms")]
pub statement_timeout_ms: u32,
#[serde(default = "default_max_rows")]
pub max_rows: usize,
#[serde(default = "crate::server_config::defaults::default_true")]
pub allow_commit: bool,
}
impl Default for AdminSqlConfig {
fn default() -> Self {
Self {
enabled: false,
statement_timeout_ms: default_statement_timeout_ms(),
max_rows: default_max_rows(),
allow_commit: true,
}
}
}
impl AdminSqlConfig {
pub fn validate(&self) -> Result<(), String> {
if !self.enabled {
return Ok(());
}
if self.statement_timeout_ms == 0 {
return Err("[admin_sql] statement_timeout_ms must be greater than 0: \
PostgreSQL reads 0 as 'no timeout', so the one bound that stops a \
runaway console statement would be disabled by a value that looks \
like a limit."
.to_string());
}
if self.max_rows == 0 {
return Err("[admin_sql] max_rows must be greater than 0: a console that can \
return no rows answers every SELECT as truncated-to-nothing."
.to_string());
}
Ok(())
}
}