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