Skip to main content

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