Skip to main content

cc_lb_plugin_api/
lib.rs

1//! Public plugin contract for the `cc-lb` proxy lifecycle.
2//!
3//! The core proxy owns the wire-level server loop and drives requests through
4//! `parse -> authenticate -> route -> shape -> sign -> relay_stream`.
5//! This crate defines the stable types and object-safe traits used at those
6//! boundaries: authentication plugins identify a [`Principal`], router plugins
7//! choose an [`Upstream`] and [`UpstreamDialect`], dialects build a
8//! [`ShapedRequest`], signers consume it into a [`SignedRequest`], and the core
9//! relays the signed request while emitting [`ObserveEvent`] values to
10//! observability hooks.
11//!
12//! The crate deliberately uses `http`, `bytes`, and `url` types instead of
13//! exposing the server's transport implementation. Request body validation,
14//! semantic JSON checks, and concrete HTTP client behavior live in downstream
15//! crates, not in this API contract.
16
17#![deny(unsafe_code)]
18#![warn(missing_docs)]
19
20mod errors;
21mod traits;
22pub mod types;
23
24pub use errors::{DialectError, ObservabilityError, RouteError, SignerError, UpstreamError};
25pub use traits::{
26    ApiKeyAwareSignerFactory, FilterError, FilterOutput, FilterPlugin, ObservabilityHook,
27    RouterPlugin, Signer, SignerFactory, UpstreamDialect,
28};
29pub use types::{
30    CredentialStrategy, GLOBAL_PRINCIPAL, InternalError, InternalErrorKind, InternalErrorStage,
31    ObserveEvent, PerCandidateReason, PluginManifest, PluginSlot, Principal, PrincipalKind,
32    PrincipalQuotas, RateLimitKind, RateLimitObservation, RequestContext, RetryDecision,
33    RouteDecision, RoutingTrace, ShapedRequest, ShapedRequestBuilder, SignedRequest,
34    SigningCapability, SlotKey, SubscriptionQuotaCandidateSnapshot, SubscriptionQuotaDataState,
35    TerminalStrategy, Upstream, UpstreamCandidate, UpstreamKind, default_pure, shape_request,
36    sign_request,
37};
38
39/// Stable registry id for the built-in cache-affinity router filter.
40pub const BUILTIN_CACHE_AFFINITY_ID: uuid::Uuid = uuid::Uuid::from_u128(1);
41
42/// Stable registry name for the built-in cache-affinity router filter.
43pub const BUILTIN_CACHE_AFFINITY_NAME: &str = "cache-affinity";
44
45/// Stable registry id for the built-in subscription-preference router filter.
46pub const BUILTIN_SUBSCRIPTION_PREFERENCE_ID: uuid::Uuid = uuid::Uuid::from_u128(2);
47
48/// Stable registry name for the built-in subscription-preference router filter.
49pub const BUILTIN_SUBSCRIPTION_PREFERENCE_NAME: &str = "subscription-preference";
50
51mod private {
52    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
53    pub(crate) struct Seal;
54}