spiffe/workload_api/mod.rs
1//! A client to interact with the Workload API to fetch X.509 and JWT materials.
2//!
3//! # Examples
4//!
5//! ```no_run
6//!
7//! use std::error::Error;
8//! use spiffe::WorkloadApiClient;
9//!
10//! use spiffe::X509Svid;
11//! use spiffe::X509BundleSet;
12//! use spiffe::X509Context;
13//!
14//! # async fn example() -> Result<(), Box< dyn Error>> {
15//!
16//! // create a new Workload API client connecting to an socket path defined by the environment variable:
17//! // `export SPIFFE_ENDPOINT_SOCKET = "unix:/tmp/spire-agent/api/public.sock"`
18//! let mut client = WorkloadApiClient::default().await?;
19//!
20//! let target_audience = &["service1", "service2"];
21//! // fetch a jwt token for the default identity with target audience
22//! let jwt_token = client.fetch_jwt_token(target_audience, None).await?;
23//!
24//! // fetch the jwt token for the default identity and parses it as a `JwtSvid`
25//! let jwt_svid = client.fetch_jwt_svid(target_audience, None).await?;
26//!
27//! // fetch a set of jwt bundles (public keys for validating jwt token)
28//! let jwt_bundles = client.fetch_jwt_bundles().await?;
29//!
30//! // fetch the default X.509 SVID
31//! let x509_svid: X509Svid = client.fetch_x509_svid().await?;
32//!
33//! // fetch a set of X.509 bundles (X.509 public key authorities)
34//! let x509_bundles: X509BundleSet = client.fetch_x509_bundles().await?;
35//!
36//! // fetch all the X.509 materials (SVIDs and bundles)
37//! let x509_context: X509Context = client.fetch_x509_context().await?;
38//!
39//! # Ok(())
40//! # }
41//! ```
42#![allow(clippy::result_large_err)]
43pub mod client;
44pub mod x509_context;
45pub mod x509_source;