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