Skip to main content

surrealdb_server/cli/
config.rs

1use std::net::SocketAddr;
2use std::path::PathBuf;
3
4use anyhow::Result;
5use surrealdb_core::CommunityComposer;
6use surrealdb_core::options::EngineOptions;
7
8use crate::ntw::client_ip::ClientIp;
9
10/// Trait for validating configuration before system initialization.
11///
12/// This trait is part of the composer pattern and allows composers to perform
13/// validation checks on the configuration before the datastore and network
14/// components are initialized. Implementations can verify that the configuration
15/// is valid for the specific backend and features being used.
16#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
17#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
18pub trait ConfigCheck: ConfigCheckRequirements {
19	/// Validates the provided configuration.
20	///
21	/// # Parameters
22	/// - `cfg`: The configuration to validate
23	///
24	/// # Returns
25	/// - `Ok(())` if the configuration is valid
26	/// - `Err` if the configuration is invalid or incompatible
27	async fn check_config(&mut self, _cfg: &Config) -> Result<()>;
28}
29
30#[cfg(target_family = "wasm")]
31pub trait ConfigCheckRequirements {}
32
33#[cfg(not(target_family = "wasm"))]
34pub trait ConfigCheckRequirements: Send + Sync + 'static {}
35
36#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
37#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
38impl ConfigCheck for CommunityComposer {
39	async fn check_config(&mut self, _cfg: &Config) -> Result<()> {
40		Ok(())
41	}
42}
43impl ConfigCheckRequirements for CommunityComposer {}
44
45#[derive(Clone, Debug)]
46pub struct Config {
47	pub bind: SocketAddr,
48	pub path: String,
49	pub client_ip: ClientIp,
50	pub user: Option<String>,
51	pub pass: Option<String>,
52	pub crt: Option<PathBuf>,
53	pub key: Option<PathBuf>,
54	pub engine: EngineOptions,
55	pub no_identification_headers: bool,
56	pub allow_origin: Vec<String>,
57}