treetop_client/lib.rs
1//! Typed async Rust client for Treetop policy authorization servers.
2//!
3//! Treetop is a Cedar-based policy evaluation service. This crate provides a strongly typed,
4//! async client for evaluating authorization requests, managing policies, and querying
5//! server status over the Treetop REST API.
6//!
7//! # Quick start
8//!
9//! ```rust,no_run
10//! use treetop_client::{Action, Client, Request, Resource, User};
11//!
12//! # async fn example() -> treetop_client::Result<()> {
13//! let client = Client::builder("https://treetop.example.com").build()?;
14//!
15//! let allowed = client
16//! .is_allowed(Request::new(
17//! User::new("alice").unwrap(),
18//! Action::new("view").unwrap(),
19//! Resource::new("Document", "doc-42").unwrap(),
20//! ))
21//! .await?;
22//! # Ok(())
23//! # }
24//! ```
25//!
26//! # Connection pooling
27//!
28//! The [`Client`] reuses connections via reqwest's built-in connection pool. Create one
29//! `Client` and share it across your application. Cloning a `Client` (e.g. via
30//! [`Client::with_correlation_id`]) shares the same underlying pool at zero cost.
31//!
32//! # Security
33//!
34//! Upload tokens are stored using [`secrecy::SecretString`], which zeroizes memory on drop
35//! and is redacted in `Debug` output. TLS uses rustls by default without an OpenSSL/system-TLS
36//! dependency. Request-domain fields are private and validated before transport, redirects are
37//! disabled on the default HTTP client, and request and successful-response bodies have
38//! configurable size limits.
39
40#![forbid(unsafe_code)]
41#![warn(missing_docs)]
42
43pub mod client;
44pub mod error;
45pub mod token;
46pub mod types;
47
48pub use client::{
49 Authorization, CanUpload, Client, ClientBuilder, DetailedAuthorization, RawUserPoliciesRequest,
50 ReadOnly, UserPoliciesRequest,
51};
52pub use error::{Result, TreetopError};
53pub use token::UploadToken;
54pub use types::{
55 Action, AttrValue, AuthRequest, AuthorizeBriefResponse, AuthorizeDecisionBrief,
56 AuthorizeDecisionDetailed, AuthorizeDetailedResponse, AuthorizeRequest, AuthorizeResponse,
57 BatchResult, CedarIpAddr, Core, DecisionBrief, Group, IndexedResult, Metadata, MetadataSource,
58 PermitPolicy, PoliciesDownload, PoliciesMetadata, PolicyMatch, PolicyMatchReason,
59 PolicyVersion, Principal, Request, RequestContextFallbackReason, RequestContextStatus,
60 RequestLimits, Resource, SchemaDownload, SchemaVersion, StatusResponse, User, UserPolicies,
61 ValidationError, VersionInfo,
62};