pub struct TokenPolicyTable { /* private fields */ }Expand description
Per-vendor policy lookup table.
The table is keyed by VendorId and consults the per-vendor
TokenPolicy::default_for when a vendor is not explicitly
registered. Callers can override per-vendor with
with_policy.
The default-on path is
TokenPolicyTable::with_builtin_defaults, which seeds the
table with every vendor the T89 classifier knows about
(Tier 1 + Tier 2 + the Unknown fallback).
§Example
use std::time::Duration;
use stygian_charon::token_lifecycle::TokenPolicyTable;
use stygian_charon::vendor_classifier::VendorId;
let mut table = TokenPolicyTable::with_builtin_defaults();
// Override Cloudflare to a stricter 5-minute default TTL.
let tighter = table.policy(VendorId::Cloudflare).with_default_ttl(Duration::from_mins(5));
table = table.with_policy(VendorId::Cloudflare, tighter);
assert_eq!(table.policy(VendorId::Cloudflare).default_ttl(), Duration::from_mins(5));Implementations§
Source§impl TokenPolicyTable
impl TokenPolicyTable
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Build an empty table (no overrides; every lookup returns
the TokenPolicy::default_for baseline).
§Example
use stygian_charon::token_lifecycle::TokenPolicyTable;
use stygian_charon::vendor_classifier::VendorId;
let table = TokenPolicyTable::empty();
assert!(table.is_empty());Sourcepub fn with_builtin_defaults() -> Self
pub fn with_builtin_defaults() -> Self
Build a table seeded with the per-vendor defaults for
every VendorId variant. The Unknown vendor is
always included as the catch-all fallback.
§Example
use stygian_charon::token_lifecycle::TokenPolicyTable;
use stygian_charon::vendor_classifier::VendorId;
let table = TokenPolicyTable::with_builtin_defaults();
assert!(!table.is_empty());
assert!(table.contains(VendorId::Cloudflare));
assert!(table.contains(VendorId::DataDome));
assert!(table.contains(VendorId::Unknown));Sourcepub fn contains(&self, vendor: VendorId) -> bool
pub fn contains(&self, vendor: VendorId) -> bool
true when the table has an override registered for
vendor.
§Example
use stygian_charon::token_lifecycle::TokenPolicyTable;
use stygian_charon::vendor_classifier::VendorId;
let table = TokenPolicyTable::with_builtin_defaults();
assert!(table.contains(VendorId::Cloudflare));Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of vendors currently registered (including the
Unknown fallback).
Sourcepub fn policy(&self, vendor: VendorId) -> TokenPolicy
pub fn policy(&self, vendor: VendorId) -> TokenPolicy
Per-vendor policy. Returns the override if one is
registered, otherwise the TokenPolicy::default_for
baseline for that vendor.
§Example
use stygian_charon::token_lifecycle::TokenPolicyTable;
use stygian_charon::vendor_classifier::VendorId;
let table = TokenPolicyTable::with_builtin_defaults();
let policy = table.policy(VendorId::Akamai);
assert!(policy.require_session_binding());Sourcepub fn with_policy(self, vendor: VendorId, policy: TokenPolicy) -> Self
pub fn with_policy(self, vendor: VendorId, policy: TokenPolicy) -> Self
Register an override for vendor. The override
replaces any existing entry.
§Example
use std::time::Duration;
use stygian_charon::token_lifecycle::{TokenPolicy, TokenPolicyTable};
use stygian_charon::vendor_classifier::VendorId;
let mut table = TokenPolicyTable::with_builtin_defaults();
let override_policy = TokenPolicy::new(
Duration::from_mins(1),
Duration::from_mins(2),
true,
true,
true,
);
table = table.with_policy(VendorId::PerimeterX, override_policy);
assert_eq!(table.policy(VendorId::PerimeterX).default_ttl(), Duration::from_mins(1));Trait Implementations§
Source§impl Clone for TokenPolicyTable
impl Clone for TokenPolicyTable
Source§fn clone(&self) -> TokenPolicyTable
fn clone(&self) -> TokenPolicyTable
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more