Skip to main content

reifydb_sub_server_admin/
config.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4//! Configuration for the admin server subsystem.
5
6use std::{fmt, time::Duration};
7
8use reifydb_runtime::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 .
24	pub runtime: Option<SharedRuntime>,
25}
26
27impl fmt::Debug for AdminConfig {
28	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> 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			.finish()
36	}
37}
38
39impl Default for AdminConfig {
40	fn default() -> Self {
41		Self {
42			bind_addr: "127.0.0.1:9090".to_string(),
43			max_connections: 1_000,
44			request_timeout: Duration::from_secs(30),
45			auth_required: false,
46			auth_token: None,
47			runtime: None,
48		}
49	}
50}
51
52impl AdminConfig {
53	/// Create a new AdminConfig with default values.
54	pub fn new() -> Self {
55		Self::default()
56	}
57
58	/// Set the bind address.
59	pub fn bind_addr(mut self, addr: impl Into<String>) -> Self {
60		self.bind_addr = addr.into();
61		self
62	}
63
64	/// Set the maximum number of connections.
65	pub fn max_connections(mut self, max: usize) -> Self {
66		self.max_connections = max;
67		self
68	}
69
70	/// Set the request timeout.
71	pub fn request_timeout(mut self, timeout: Duration) -> Self {
72		self.request_timeout = timeout;
73		self
74	}
75
76	/// Enable authentication with the given token.
77	pub fn with_auth(mut self, token: String) -> Self {
78		self.auth_required = true;
79		self.auth_token = Some(token);
80		self
81	}
82
83	/// Set the shared runtime.
84	pub fn runtime(mut self, runtime: SharedRuntime) -> Self {
85		self.runtime = Some(runtime);
86		self
87	}
88}