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