reifydb_sub_server_admin/
config.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later
3
4//! Configuration for the admin server subsystem.
5
6use std::time::Duration;
7
8use reifydb_sub_server::SharedRuntime;
9
10/// Configuration for the admin server subsystem.
11#[derive(Clone)]
12pub struct AdminConfig {
13	/// Address to bind the admin server to (e.g., "127.0.0.1:9090").
14	pub bind_addr: String,
15	/// Maximum number of concurrent connections.
16	pub max_connections: usize,
17	/// Timeout for entire request lifecycle.
18	pub request_timeout: Duration,
19	/// Whether authentication is required.
20	pub auth_required: bool,
21	/// Authentication token (if auth is required).
22	pub auth_token: Option<String>,
23	/// Optional shared runtime. If not provided, a default one will be created.
24	pub runtime: Option<SharedRuntime>,
25}
26
27impl std::fmt::Debug for AdminConfig {
28	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29		f.debug_struct("AdminConfig")
30			.field("bind_addr", &self.bind_addr)
31			.field("max_connections", &self.max_connections)
32			.field("request_timeout", &self.request_timeout)
33			.field("auth_required", &self.auth_required)
34			.field("auth_token", &self.auth_token.as_ref().map(|_| "****"))
35			.field("runtime", &self.runtime.as_ref().map(|_| "SharedRuntime"))
36			.finish()
37	}
38}
39
40impl Default for AdminConfig {
41	fn default() -> Self {
42		Self {
43			bind_addr: "127.0.0.1:9090".to_string(),
44			max_connections: 1_000,
45			request_timeout: Duration::from_secs(30),
46			auth_required: false,
47			auth_token: None,
48			runtime: None,
49		}
50	}
51}
52
53impl AdminConfig {
54	/// Create a new AdminConfig with default values.
55	pub fn new() -> Self {
56		Self::default()
57	}
58
59	/// Set the bind address.
60	pub fn bind_addr(mut self, addr: impl Into<String>) -> Self {
61		self.bind_addr = addr.into();
62		self
63	}
64
65	/// Set the maximum number of connections.
66	pub fn max_connections(mut self, max: usize) -> Self {
67		self.max_connections = max;
68		self
69	}
70
71	/// Set the request timeout.
72	pub fn request_timeout(mut self, timeout: Duration) -> Self {
73		self.request_timeout = timeout;
74		self
75	}
76
77	/// Enable authentication with the given token.
78	pub fn with_auth(mut self, token: String) -> Self {
79		self.auth_required = true;
80		self.auth_token = Some(token);
81		self
82	}
83
84	/// Set the shared runtime.
85	pub fn runtime(mut self, runtime: SharedRuntime) -> Self {
86		self.runtime = Some(runtime);
87		self
88	}
89}