sentinel_proxy/
lib.rs

1// Allow lints for work-in-progress features and code patterns
2#![allow(dead_code)]
3#![allow(unused_variables)]
4#![allow(unused_imports)]
5#![allow(clippy::too_many_arguments)]
6#![allow(clippy::match_like_matches_macro)]
7#![allow(clippy::manual_strip)]
8#![allow(clippy::only_used_in_recursion)]
9#![allow(clippy::type_complexity)]
10#![allow(clippy::manual_try_fold)]
11#![allow(private_interfaces)]
12
13//! Sentinel Proxy Library
14//!
15//! A security-first reverse proxy built on Pingora with sleepable ops at the edge.
16//!
17//! This library provides the core components for building a production-grade
18//! reverse proxy with:
19//!
20//! - **Routing**: Flexible path-based and header-based routing
21//! - **Upstream Management**: Load balancing, health checking, circuit breakers
22//! - **Static File Serving**: Compression, caching, range requests
23//! - **Validation**: JSON Schema validation for API requests/responses
24//! - **Error Handling**: Customizable error pages per service type
25//! - **Hot Reload**: Configuration changes without restarts
26//!
27//! # Example
28//!
29//! ```ignore
30//! use sentinel_proxy::{StaticFileServer, ErrorHandler, SchemaValidator};
31//! use sentinel_config::{StaticFileConfig, ServiceType};
32//!
33//! // Create a static file server
34//! let config = StaticFileConfig::default();
35//! let server = StaticFileServer::new(config);
36//!
37//! // Create an error handler for API responses
38//! let handler = ErrorHandler::new(ServiceType::Api, None);
39//! ```
40
41// ============================================================================
42// Module Declarations
43// ============================================================================
44
45pub mod agents;
46pub mod app;
47pub mod builtin_handlers;
48pub mod cache;
49pub mod discovery;
50pub mod distributed_rate_limit;
51pub mod errors;
52pub mod health;
53pub mod http_helpers;
54pub mod logging;
55pub mod memory_cache;
56pub mod otel;
57pub mod proxy;
58pub mod rate_limit;
59pub mod reload;
60pub mod routing;
61pub mod static_files;
62pub mod tls;
63pub mod trace_id;
64pub mod upstream;
65pub mod validation;
66pub mod websocket;
67
68// ============================================================================
69// Public API Re-exports
70// ============================================================================
71
72// Error handling
73pub use errors::ErrorHandler;
74
75// Static file serving
76pub use static_files::{CacheStats, CachedFile, FileCache, StaticFileServer};
77
78// Request validation
79pub use validation::SchemaValidator;
80
81// Routing
82pub use routing::{RequestInfo, RouteMatch, RouteMatcher};
83
84// Upstream management
85pub use upstream::{
86    LoadBalancer, PoolConfigSnapshot, PoolStats, RequestContext, TargetSelection, UpstreamPool,
87    UpstreamTarget,
88};
89
90// Health checking
91pub use health::{ActiveHealthChecker, PassiveHealthChecker, TargetHealthInfo};
92
93// Agents
94pub use agents::{AgentAction, AgentCallContext, AgentDecision, AgentManager};
95
96// Hot reload
97pub use reload::{ConfigManager, ReloadEvent, ReloadTrigger, SignalManager, SignalType};
98
99// Application state
100pub use app::AppState;
101
102// Proxy core
103pub use proxy::SentinelProxy;
104
105// Built-in handlers
106pub use builtin_handlers::{
107    execute_handler, BuiltinHandlerState, CachePurgeRequest, TargetHealthStatus, TargetStatus,
108    UpstreamHealthSnapshot, UpstreamStatus,
109};
110
111// HTTP helpers
112pub use http_helpers::{
113    extract_request_info, get_or_create_trace_id, write_error, write_json_error, write_response,
114    write_text_error, OwnedRequestInfo,
115};
116
117// Trace ID generation (TinyFlake)
118pub use trace_id::{
119    generate_for_format, generate_tinyflake, generate_uuid, TraceIdFormat, TINYFLAKE_LENGTH,
120};
121
122// OpenTelemetry tracing
123pub use otel::{
124    create_traceparent, generate_span_id, generate_trace_id, get_tracer, init_tracer,
125    shutdown_tracer, OtelError, OtelTracer, RequestSpan, TraceContext, TRACEPARENT_HEADER,
126    TRACESTATE_HEADER,
127};
128
129// TLS / SNI support
130pub use tls::{
131    build_server_config, build_upstream_tls_config, load_client_ca, validate_tls_config,
132    validate_upstream_tls_config, CertificateReloader, HotReloadableSniResolver, OcspCacheEntry,
133    OcspStapler, SniResolver, TlsError,
134};
135
136// Logging
137pub use logging::{
138    AccessLogEntry, AccessLogFormat, AuditEventType, AuditLogEntry, ErrorLogEntry, LogManager,
139    SharedLogManager,
140};
141
142// Rate limiting
143pub use rate_limit::{
144    RateLimitConfig, RateLimitManager, RateLimitOutcome, RateLimitResult, RateLimiterPool,
145};
146
147// Distributed rate limiting
148#[cfg(feature = "distributed-rate-limit")]
149pub use distributed_rate_limit::{
150    create_redis_rate_limiter, DistributedRateLimitStats, RedisRateLimiter,
151};
152
153// HTTP caching
154pub use cache::{
155    get_cache_eviction, get_cache_lock, get_cache_storage, CacheConfig, CacheManager,
156    HttpCacheStats,
157};
158
159// Memory caching
160pub use memory_cache::{
161    MemoryCacheConfig, MemoryCacheManager, MemoryCacheStats, RouteMatchEntry, TypedCache,
162};
163
164// Service discovery
165pub use discovery::{
166    ConsulDiscovery, DiscoveryConfig, DiscoveryManager, DnsDiscovery, KubernetesDiscovery,
167};
168
169// Re-export common error types for convenience
170pub use sentinel_common::errors::{LimitType, SentinelError, SentinelResult};