Skip to main content

spiral/resources/generated/
connections.rs

1// Generated by tools/service-contracts/rust.py. Do not edit.
2#![doc = "Generated implementation of authenticated SDK resource facades."]
3use reqwest_middleware::ClientWithMiddleware;
4use spiral_contract::call::CallError;
5use uuid::Uuid;
6
7use crate::api::connections::ConnectionsClient;
8use crate::api::connections::objects::*;
9use crate::auth::TokenSource;
10use crate::http::HttpClient;
11/// Service operations sharing a connection pool and resolving credentials for every request.
12#[derive(Clone, Debug)]
13pub struct AuthenticatedClient {
14    http: HttpClient,
15    client: ConnectionsClient,
16}
17impl AuthenticatedClient {
18    /// Connect with bounded requests; configure credentials before authenticated calls.
19    pub fn new(base: &str) -> Result<Self, CallError<ConnectionsError>> {
20        Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
21    }
22    pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<ConnectionsError>> {
23        let client =
24            ConnectionsClient::from_transport(http.base_url().as_str(), http.middleware_client())?;
25        Ok(Self { http, client })
26    }
27    /// Reuse a connection pool with redirects disabled to protect bearer credentials.
28    pub fn with_client(mut self, client: impl Into<ClientWithMiddleware>) -> Self {
29        self.http = self.http.with_client(client);
30        self.client = self.client.with_transport(self.http.middleware_client());
31        self
32    }
33    /// Resolve the provider's current credential before each request and pagination fetch.
34    pub fn with_token_source(mut self, provider: TokenSource) -> Self {
35        self.http = self.http.with_token_source(provider);
36        self
37    }
38    /// Create a Connection scoped to one Project.
39    pub async fn create_connection(
40        &self,
41        request: CreateConnectionRequest,
42    ) -> Result<CreateConnectionResponse, CallError<ConnectionsError>> {
43        let auth_header = self
44            .http
45            .auth_header()
46            .await
47            .map_err(CallError::transport)?;
48        tokio::time::timeout(
49            std::time::Duration::from_secs(60),
50            self.client.create_connection_http(auth_header, request),
51        )
52        .await
53        .map_err(CallError::transport)?
54    }
55    /// Drop a Connection and remove its stored secret.
56    pub async fn drop_connection(
57        &self,
58        connection_id: Uuid,
59    ) -> Result<DropResponse, CallError<ConnectionsError>> {
60        let auth_header = self
61            .http
62            .auth_header()
63            .await
64            .map_err(CallError::transport)?;
65        tokio::time::timeout(
66            std::time::Duration::from_secs(60),
67            self.client.drop_connection_http(auth_header, connection_id),
68        )
69        .await
70        .map_err(CallError::transport)?
71    }
72    /// Read a Connection without exposing its stored secret.
73    pub async fn read_connection(
74        &self,
75        connection_id: Uuid,
76    ) -> Result<ConnectionResponse, CallError<ConnectionsError>> {
77        let auth_header = self
78            .http
79            .auth_header()
80            .await
81            .map_err(CallError::transport)?;
82        tokio::time::timeout(
83            std::time::Duration::from_secs(60),
84            self.client.read_connection_http(auth_header, connection_id),
85        )
86        .await
87        .map_err(CallError::transport)?
88    }
89    /// Test credential vending and provider access. Provider refusals are reported in the response.
90    pub async fn test_connection(
91        &self,
92        connection_id: Uuid,
93    ) -> Result<TestResponse, CallError<ConnectionsError>> {
94        let auth_header = self
95            .http
96            .auth_header()
97            .await
98            .map_err(CallError::transport)?;
99        tokio::time::timeout(
100            std::time::Duration::from_secs(60),
101            self.client.test_connection_http(auth_header, connection_id),
102        )
103        .await
104        .map_err(CallError::transport)?
105    }
106    /// Change the maximum access granted by this Connection. Increasing access first verifies it
107    /// with the provider.
108    pub async fn update_allowed_access(
109        &self,
110        connection_id: Uuid,
111        request: UpdateAllowedAccessRequest,
112    ) -> Result<ConnectionResponse, CallError<ConnectionsError>> {
113        let auth_header = self
114            .http
115            .auth_header()
116            .await
117            .map_err(CallError::transport)?;
118        tokio::time::timeout(
119            std::time::Duration::from_secs(60),
120            self.client
121                .update_allowed_access_http(auth_header, connection_id, request),
122        )
123        .await
124        .map_err(CallError::transport)?
125    }
126    /// Replace the entire credential with one for the same provider. Include every required secret.
127    pub async fn update_credential(
128        &self,
129        connection_id: Uuid,
130        request: UpdateCredentialRequest,
131    ) -> Result<ConnectionResponse, CallError<ConnectionsError>> {
132        let auth_header = self
133            .http
134            .auth_header()
135            .await
136            .map_err(CallError::transport)?;
137        tokio::time::timeout(
138            std::time::Duration::from_secs(60),
139            self.client
140                .update_credential_http(auth_header, connection_id, request),
141        )
142        .await
143        .map_err(CallError::transport)?
144    }
145    /// Replace the description. Omit it to clear the description.
146    pub async fn update_description(
147        &self,
148        connection_id: Uuid,
149        request: UpdateDescriptionRequest,
150    ) -> Result<ConnectionResponse, CallError<ConnectionsError>> {
151        let auth_header = self
152            .http
153            .auth_header()
154            .await
155            .map_err(CallError::transport)?;
156        tokio::time::timeout(
157            std::time::Duration::from_secs(60),
158            self.client
159                .update_description_http(auth_header, connection_id, request),
160        )
161        .await
162        .map_err(CallError::transport)?
163    }
164    /// Obtain a short-lived read credential for a URI within the Connection.
165    pub async fn vend_credential(
166        &self,
167        connection_id: Uuid,
168        request: VendRequest,
169    ) -> Result<VendResponse, CallError<ConnectionsError>> {
170        let auth_header = self
171            .http
172            .auth_header()
173            .await
174            .map_err(CallError::transport)?;
175        tokio::time::timeout(
176            std::time::Duration::from_secs(60),
177            self.client
178                .vend_credential_http(auth_header, connection_id, request),
179        )
180        .await
181        .map_err(CallError::transport)?
182    }
183}