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