spiffe_rs/workloadapi/
mod.rs1use std::sync::Arc;
2
3mod addr;
4mod backoff;
5mod bundlesource;
6mod client;
7mod convenience;
8mod jwtsource;
9mod option;
10mod watcher;
11mod x509context;
12mod x509source;
13
14pub mod proto {
15 pub mod google {
16 pub mod protobuf {
17 include!(concat!(env!("OUT_DIR"), "/google.protobuf.rs"));
18 }
19 }
20 include!(concat!(env!("OUT_DIR"), "/_.rs"));
21}
22
23#[derive(Debug, Clone)]
25pub struct Error {
26 message: String,
27 status: Option<tonic::Status>,
28}
29
30impl std::fmt::Display for Error {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 self.message.fmt(f)
33 }
34}
35
36impl std::error::Error for Error {}
37
38pub type Result<T> = std::result::Result<T, Error>;
40
41fn wrap_error(message: impl std::fmt::Display) -> Error {
42 Error {
43 message: format!("workloadapi: {}", message),
44 status: None,
45 }
46}
47
48impl Error {
49 pub fn status(&self) -> Option<&tonic::Status> {
51 self.status.as_ref()
52 }
53
54 pub(crate) fn new(message: impl Into<String>) -> Self {
55 Self {
56 message: message.into(),
57 status: None,
58 }
59 }
60}
61
62impl From<tonic::Status> for Error {
63 fn from(status: tonic::Status) -> Self {
64 Self {
65 message: format!("workloadapi: {}", status),
66 status: Some(status),
67 }
68 }
69}
70
71pub type Context = tokio_util::sync::CancellationToken;
73
74pub fn background() -> Context {
76 tokio_util::sync::CancellationToken::new()
77}
78
79pub use addr::{get_default_address, target_from_address, validate_address, SocketEnv};
80pub use backoff::{Backoff, BackoffStrategy, LinearBackoffStrategy};
81pub use bundlesource::BundleSource;
82pub use client::{Client, JWTBundleWatcher, X509BundleWatcher, X509ContextWatcher};
83pub use convenience::*;
84pub use jwtsource::JWTSource;
85pub use option::*;
86pub use watcher::Watcher;
87pub use x509context::X509Context;
88pub use x509source::X509Source;
89
90pub(crate) type LoggerRef = Arc<dyn crate::logger::Logger>;