Load and validate a TOML config file. Returns `Ok(ConfigFile::default())` for an empty file (the gateway then falls back entirely to CLI/env/built-in defaults).
(path: &Path)
| 193 | /// Returns `Ok(ConfigFile::default())` for an empty file (the gateway then |
| 194 | /// falls back entirely to CLI/env/built-in defaults). |
| 195 | pub fn load(path: &Path) -> Result<ConfigFile, ConfigFileError> { |
| 196 | let contents = std::fs::read_to_string(path).map_err(|source| ConfigFileError::Io { |
| 197 | path: path.to_path_buf(), |
| 198 | source, |
| 199 | })?; |
| 200 | if contents.trim().is_empty() { |
| 201 | return Ok(ConfigFile::default()); |
| 202 | } |
| 203 | let file: ConfigFile = toml::from_str(&contents).map_err(|source| ConfigFileError::Parse { |
| 204 | path: path.to_path_buf(), |
| 205 | source, |
| 206 | })?; |
| 207 | |
| 208 | if let Some(version) = file.openshell.version |
| 209 | && version > SCHEMA_VERSION |
| 210 | { |
| 211 | return Err(ConfigFileError::UnsupportedVersion { version }); |
| 212 | } |
| 213 | |
| 214 | if file.openshell.gateway.database_url.is_some() { |
| 215 | return Err(ConfigFileError::SecretInFile { |
| 216 | field: "database_url", |
| 217 | env: "OPENSHELL_DB_URL", |
| 218 | cli: "--db-url", |
| 219 | }); |
| 220 | } |
| 221 | |
| 222 | Ok(file) |
| 223 | } |
| 224 | |
| 225 | /// Build the merged TOML table for `driver` by overlaying inheritable |
| 226 | /// `[openshell.gateway]` defaults onto `[openshell.drivers.<name>]`. |