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