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::{
25    DialectError, ObservabilityError, RouteError, RuntimeError, SignerError, UpstreamError,
26};
27#[allow(deprecated)]
28pub use traits::RouterPlugin;
29pub use traits::{
30    ApiKeyAwareSignerFactory, FilterError, FilterOutput, FilterPlugin, ObservabilityHook,
31    PluginRuntime, Signer, SignerFactory, UpstreamDialect,
32};
33pub use types::{
34    CredentialStrategy, GLOBAL_PRINCIPAL, InternalError, InternalErrorKind, InternalErrorStage,
35    ObserveEvent, PerCandidateReason, PluginManifest, PluginSlot, Principal, PrincipalKind,
36    PrincipalQuotas, RateLimitKind, RateLimitObservation, RequestContext, RetryDecision,
37    RouteDecision, RoutingTrace, ShapedRequest, ShapedRequestBuilder, SignedRequest,
38    SigningCapability, SlotKey, SubscriptionQuotaCandidateSnapshot, SubscriptionQuotaDataState,
39    TerminalStrategy, Upstream, UpstreamCandidate, UpstreamKind, default_pure, shape_request,
40    sign_request,
41};
42
43/// Stable registry id for the built-in cache-affinity router filter.
44pub const BUILTIN_CACHE_AFFINITY_ID: uuid::Uuid = uuid::Uuid::from_u128(1);
45
46/// Stable registry name for the built-in cache-affinity router filter.
47pub const BUILTIN_CACHE_AFFINITY_NAME: &str = "cache-affinity";
48
49/// Stable registry id for the built-in subscription-preference router filter.
50pub const BUILTIN_SUBSCRIPTION_PREFERENCE_ID: uuid::Uuid = uuid::Uuid::from_u128(2);
51
52/// Stable registry name for the built-in subscription-preference router filter.
53pub const BUILTIN_SUBSCRIPTION_PREFERENCE_NAME: &str = "subscription-preference";
54
55mod private {
56    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
57    pub(crate) struct Seal;
58}