Skip to main content

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