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