perfgate_server/lib.rs
1//! REST API server for centralized baseline management.
2//!
3//! This crate provides a REST API server for storing and managing performance
4//! baselines. It supports multiple storage backends (in-memory, SQLite, PostgreSQL)
5//! and includes authentication via API keys.
6//!
7//! Part of the [perfgate](https://github.com/EffortlessMetrics/perfgate) workspace.
8//!
9//! # Features
10//!
11//! - **Multi-tenancy**: Projects/namespaces for isolation
12//! - **Version history**: Track baseline versions over time
13//! - **Rich metadata**: Git refs, tags, custom metadata
14//! - **Access control**: Role-based permissions (Viewer, Contributor, Promoter, Admin)
15//! - **Multiple backends**: In-memory, SQLite, PostgreSQL (planned)
16//!
17//! # Quick Start
18//!
19//! ```rust,no_run
20//! use perfgate_server::{ServerConfig, StorageBackend, run_server};
21//!
22//! #[tokio::main]
23//! async fn main() {
24//! let config = ServerConfig::new()
25//! .bind("0.0.0.0:8080").unwrap()
26//! .storage_backend(StorageBackend::Sqlite)
27//! .sqlite_path("perfgate.db");
28//!
29//! run_server(config).await.unwrap();
30//! }
31//! ```
32//!
33//! # API Endpoints
34//!
35//! | Method | Path | Description |
36//! |--------|------|-------------|
37//! | POST | `/projects/{project}/baselines` | Upload a baseline |
38//! | GET | `/projects/{project}/baselines/{benchmark}/latest` | Get latest baseline |
39//! | GET | `/projects/{project}/baselines/{benchmark}/versions/{version}` | Get specific version |
40//! | GET | `/projects/{project}/baselines` | List baselines |
41//! | DELETE | `/projects/{project}/baselines/{benchmark}/versions/{version}` | Delete baseline |
42//! | POST | `/projects/{project}/baselines/{benchmark}/promote` | Promote version |
43//! | GET | `/audit` | List audit events (admin only) |
44//! | GET | `/health` | Health check |
45//! | GET | `/metrics` | Prometheus metrics |
46
47pub mod auth;
48pub mod cleanup;
49pub mod error;
50pub mod handlers;
51pub mod metrics;
52pub mod models;
53pub mod oidc;
54pub mod server;
55pub mod storage;
56
57#[cfg(any(test, feature = "test-utils"))]
58pub mod testing;
59
60pub use auth::{ApiKey, ApiKeyStore, AuthContext, AuthState, JwtClaims, JwtConfig, Role, Scope};
61pub use error::{AuthError, ConfigError, StoreError};
62pub use models::*;
63pub use oidc::{OidcConfig, OidcProvider, OidcProviderType, OidcRegistry};
64pub use server::{AppState, PostgresPoolConfig, ServerConfig, StorageBackend, run_server};
65pub use storage::{
66 AuditStore, BaselineStore, FleetStore, InMemoryFleetStore, InMemoryKeyStore, InMemoryStore,
67 KeyRecord, KeyStore, SqliteKeyStore, SqliteStore, StorageHealth,
68};
69
70/// Server version string.
71pub const VERSION: &str = env!("CARGO_PKG_VERSION");
72
73#[cfg(test)]
74mod tests {
75 use super::*;
76
77 #[test]
78 fn test_version() {
79 assert!(!VERSION.is_empty());
80 }
81}