Skip to main content

cloud_sdk/authentication/
transport.rs

1use core::fmt;
2use core::future::Future;
3
4use crate::transport::{ResponseWriter, TransportRequest};
5
6use super::AuthenticationScopePolicy;
7
8/// Request plus mandatory provider or operation-owned authentication policy.
9#[derive(Clone, Copy)]
10pub struct AuthenticatedRequest<'request, 'policy> {
11    request: TransportRequest<'request>,
12    policy: AuthenticationScopePolicy<'policy>,
13}
14
15impl<'request, 'policy> AuthenticatedRequest<'request, 'policy> {
16    /// Binds a transport request to its complete authentication policy.
17    #[must_use]
18    pub const fn new(
19        request: TransportRequest<'request>,
20        policy: AuthenticationScopePolicy<'policy>,
21    ) -> Self {
22        Self { request, policy }
23    }
24
25    /// Returns the credential-free transport request.
26    #[must_use]
27    pub const fn transport_request(self) -> TransportRequest<'request> {
28        self.request
29    }
30
31    /// Returns the complete authentication policy.
32    #[must_use]
33    pub const fn policy(self) -> AuthenticationScopePolicy<'policy> {
34        self.policy
35    }
36}
37
38impl fmt::Debug for AuthenticatedRequest<'_, '_> {
39    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
40        formatter
41            .debug_struct("AuthenticatedRequest")
42            .field("request", &self.request)
43            .field("policy", &self.policy)
44            .finish()
45    }
46}
47
48/// Blocking transport that cannot execute without an authentication policy.
49pub trait BlockingAuthenticatedTransport {
50    /// Transport-specific failure.
51    type Error;
52
53    /// Validates scope and sends one authenticated request.
54    fn send_authenticated(
55        &self,
56        request: AuthenticatedRequest<'_, '_>,
57        response: &mut ResponseWriter<'_>,
58    ) -> Result<(), Self::Error>;
59}
60
61/// Executor-neutral async transport requiring an authentication policy.
62pub trait AsyncAuthenticatedTransport {
63    /// Transport-specific failure.
64    type Error;
65
66    /// Validates scope and sends one authenticated request.
67    fn send_authenticated<'transport, 'request, 'policy, 'writer>(
68        &'transport self,
69        request: AuthenticatedRequest<'request, 'policy>,
70        response: &'writer mut ResponseWriter<'_>,
71    ) -> impl Future<Output = Result<(), Self::Error>> + Send + 'writer
72    where
73        'transport: 'writer,
74        'request: 'writer,
75        'policy: 'writer;
76}