Skip to main content

chamber_api/
lib.rs

1pub mod auth;
2pub mod error;
3pub mod handlers;
4pub mod models;
5pub mod server;
6
7pub use auth::{AuthState, TokenClaims};
8pub use error::{ApiError, ApiResult};
9pub use models::{
10    HealthReportResponse, OldPasswordItem, ReusedPasswordGroup, SearchParams, SearchResponse, StatsResponse,
11};
12pub use server::ApiServer;
13
14use chamber_vault::VaultManager;
15use color_eyre::Result;
16
17/// Initializes and starts the API server.
18///
19/// This asynchronous function takes a `chamber_vault::Vault` instance, which provides access
20/// to sensitive configuration or secrets, and a bind address (e.g., "127.0.0.1:8080") that determines
21/// where the API server will be hosted.
22///
23/// # Arguments
24///
25/// * `vault` - An instance of `chamber_vault::Vault` used to manage secrets or configuration needed by the server.
26/// * `bind_address` - A `&str` that specifies the address and port the server will bind to (e.g., "0.0.0.0:8080").
27///
28/// # Returns
29///
30/// Returns a `Result` containing an `ApiServer` instance if the server is initialized successfully,
31/// or an error if the initialization fails.
32///
33/// # Errors
34///
35/// This function may return an error if:
36/// * The server fails to bind to the specified address and port.
37/// * There is an issue initializing the server with the given vault.
38pub async fn init_api_server(
39    vault: chamber_vault::Vault,
40    vault_manager: VaultManager,
41    bind_address: &str,
42) -> Result<ApiServer> {
43    ApiServer::new(vault, vault_manager, bind_address).await
44}