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, JWT, and OIDC mappings.
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
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 | `/api/v1/projects/{project}/baselines` | Upload a baseline |
38//! | GET | `/api/v1/projects/{project}/baselines/{benchmark}/latest` | Get latest baseline |
39//! | GET | `/api/v1/projects/{project}/baselines/{benchmark}/versions/{version}` | Get specific version |
40//! | GET | `/api/v1/projects/{project}/baselines` | List baselines |
41//! | DELETE | `/api/v1/projects/{project}/baselines/{benchmark}/versions/{version}` | Delete baseline |
42//! | POST | `/api/v1/projects/{project}/baselines/{benchmark}/promote` | Promote version |
43//! | POST | `/api/v1/projects/{project}/decisions` | Upload a performance decision receipt |
44//! | GET | `/api/v1/projects/{project}/decisions/latest` | Get latest performance decision |
45//! | GET | `/api/v1/projects/{project}/decisions` | List performance decisions |
46//! | POST | `/api/v1/projects/{project}/decisions/prune` | Prune old performance decisions |
47//! | GET | `/api/v1/audit` | List audit events (admin only) |
48//! | POST | `/api/v1/keys` | Create an API key (admin only) |
49//! | GET | `/api/v1/keys` | List API keys (admin only) |
50//! | DELETE | `/api/v1/keys/{id}` | Revoke an API key (admin only) |
51//! | DELETE | `/api/v1/admin/cleanup` | Run artifact cleanup (admin only) |
52//! | GET | `/health` | Health check |
53//! | GET | `/metrics` | Prometheus metrics |
54
55pub mod auth;
56pub mod cleanup;
57pub mod credential_source;
58pub mod error;
59pub mod handlers;
60pub mod metrics;
61pub mod models;
62pub mod oidc;
63pub mod server;
64pub mod storage;
65
66#[cfg(any(test, feature = "test-utils"))]
67pub mod testing;
68
69pub use auth::{ApiKey, ApiKeyStore, AuthContext, AuthState, JwtClaims, JwtConfig, Role, Scope};
70pub use credential_source::{
71 CredentialSource, CredentialSourceError, KeyPolicy, LoadedCredential,
72 parse_credentials_document,
73};
74pub use error::{AuthError, ConfigError, StoreError};
75pub use models::*;
76pub use oidc::{OidcConfig, OidcProvider, OidcProviderType, OidcRegistry};
77pub use server::{
78 ApiKeyMetadata, AppState, PostgresPoolConfig, ServerConfig, StorageBackend, run_server,
79};
80pub use storage::{
81 AuditStore, BaselineStore, FleetStore, InMemoryFleetStore, InMemoryKeyStore, InMemoryStore,
82 KeyRecord, KeyStore, SqliteKeyStore, SqliteStore, StorageHealth,
83};
84
85/// Server version string.
86pub const VERSION: &str = env!("CARGO_PKG_VERSION");
87
88#[cfg(test)]
89mod tests {
90 use super::*;
91
92 #[test]
93 fn test_version() {
94 assert!(!VERSION.is_empty());
95 }
96}