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 decompression;
50pub mod discovery;
51pub mod distributed_rate_limit;
52pub mod memcached_rate_limit;
53pub mod errors;
54
55// Kubernetes kubeconfig parsing (requires kubernetes feature)
56#[cfg(feature = "kubernetes")]
57pub mod kubeconfig;
58pub mod geo_filter;
59pub mod grpc_health;
60pub mod health;
61pub mod http_helpers;
62pub mod inference;
63pub mod logging;
64pub mod memory_cache;
65pub mod otel;
66pub mod proxy;
67pub mod rate_limit;
68pub mod reload;
69pub mod scoped_circuit_breaker;
70pub mod scoped_rate_limit;
71pub mod routing;
72pub mod scoped_routing;
73pub mod shadow;
74pub mod static_files;
75pub mod tls;
76pub mod trace_id;
77pub mod upstream;
78pub mod validation;
79pub mod websocket;
80
81// ============================================================================
82// Public API Re-exports
83// ============================================================================
84
85// Error handling
86pub use errors::ErrorHandler;
87
88// Static file serving
89pub use static_files::{CacheStats, CachedFile, FileCache, StaticFileServer};
90
91// Request validation
92pub use validation::SchemaValidator;
93
94// Routing
95pub use routing::{RequestInfo, RouteMatch, RouteMatcher};
96pub use scoped_routing::{ScopedRouteMatch, ScopedRouteMatcher};
97
98// Upstream management
99pub use upstream::{
100    LoadBalancer, PoolConfigSnapshot, PoolStats, RequestContext, ShadowTarget, TargetSelection,
101    UpstreamPool, UpstreamTarget,
102};
103
104// Health checking
105pub use health::{ActiveHealthChecker, PassiveHealthChecker, TargetHealthInfo};
106
107// Agents
108pub use agents::{AgentAction, AgentCallContext, AgentDecision, AgentManager};
109
110// Hot reload
111pub use reload::{ConfigManager, ReloadEvent, ReloadTrigger, SignalManager, SignalType};
112
113// Application state
114pub use app::AppState;
115
116// Proxy core
117pub use proxy::SentinelProxy;
118
119// Built-in handlers
120pub use builtin_handlers::{
121    execute_handler, BuiltinHandlerState, CachePurgeRequest, TargetHealthStatus, TargetStatus,
122    UpstreamHealthSnapshot, UpstreamStatus,
123};
124
125// HTTP helpers
126pub use http_helpers::{
127    extract_request_info, get_or_create_trace_id, write_error, write_json_error, write_response,
128    write_text_error, OwnedRequestInfo,
129};
130
131// Trace ID generation (TinyFlake)
132pub use trace_id::{
133    generate_for_format, generate_tinyflake, generate_uuid, TraceIdFormat, TINYFLAKE_LENGTH,
134};
135
136// OpenTelemetry tracing
137pub use otel::{
138    create_traceparent, generate_span_id, generate_trace_id, get_tracer, init_tracer,
139    shutdown_tracer, OtelError, OtelTracer, RequestSpan, TraceContext, TRACEPARENT_HEADER,
140    TRACESTATE_HEADER,
141};
142
143// TLS / SNI support
144pub use tls::{
145    build_server_config, build_upstream_tls_config, load_client_ca, validate_tls_config,
146    validate_upstream_tls_config, CertificateReloader, HotReloadableSniResolver, OcspCacheEntry,
147    OcspStapler, SniResolver, TlsError,
148};
149
150// Logging
151pub use logging::{
152    AccessLogEntry, AccessLogFormat, AuditEventType, AuditLogEntry, ErrorLogEntry, LogManager,
153    SharedLogManager,
154};
155
156// Rate limiting
157pub use rate_limit::{
158    RateLimitConfig, RateLimitManager, RateLimitOutcome, RateLimitResult, RateLimiterPool,
159};
160
161// Scoped rate limiting
162pub use scoped_rate_limit::{ScopedRateLimitManager, ScopedRateLimitResult};
163
164// Scoped circuit breakers
165pub use scoped_circuit_breaker::{ScopedBreakerStatus, ScopedCircuitBreakerManager};
166
167// Traffic mirroring / shadowing
168pub use shadow::{buffer_request_body, clone_body_for_shadow, should_buffer_method, ShadowManager};
169
170// GeoIP filtering
171pub use geo_filter::{
172    GeoDatabaseWatcher, GeoFilterManager, GeoFilterPool, GeoFilterResult, GeoLookupError,
173};
174
175// Body decompression with ratio limits
176pub use decompression::{
177    decompress_body, decompress_body_with_stats, is_supported_encoding, parse_content_encoding,
178    DecompressionConfig, DecompressionError, DecompressionResult, DecompressionStats,
179};
180
181// Distributed rate limiting - Redis
182#[cfg(feature = "distributed-rate-limit")]
183pub use distributed_rate_limit::{
184    create_redis_rate_limiter, DistributedRateLimitStats, RedisRateLimiter,
185};
186
187// Distributed rate limiting - Memcached
188#[cfg(feature = "distributed-rate-limit-memcached")]
189pub use memcached_rate_limit::{
190    create_memcached_rate_limiter, MemcachedRateLimitStats, MemcachedRateLimiter,
191};
192
193// HTTP caching
194pub use cache::{
195    configure_cache, get_cache_eviction, get_cache_lock, get_cache_storage, is_cache_enabled,
196    CacheConfig, CacheManager, HttpCacheStats,
197};
198
199// Memory caching
200pub use memory_cache::{
201    MemoryCacheConfig, MemoryCacheManager, MemoryCacheStats, RouteMatchEntry, TypedCache,
202};
203
204// Service discovery
205pub use discovery::{
206    ConsulDiscovery, DiscoveryConfig, DiscoveryManager, DnsDiscovery, KubernetesDiscovery,
207};
208
209// Kubernetes kubeconfig parsing
210#[cfg(feature = "kubernetes")]
211pub use kubeconfig::{KubeAuth, Kubeconfig, KubeconfigError, ResolvedKubeConfig};
212
213// Re-export common error types for convenience
214pub use sentinel_common::errors::{LimitType, SentinelError, SentinelResult};