Skip to main content

spiral/resources/generated/
workloads.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;
5
6use crate::api::workloads::WorkloadsClient;
7use crate::api::workloads::objects::*;
8use crate::auth::TokenSource;
9use crate::http::HttpClient;
10/// Service operations sharing a connection pool and resolving credentials for every request.
11#[derive(Clone, Debug)]
12pub struct AuthenticatedClient {
13    http: HttpClient,
14    client: WorkloadsClient,
15}
16impl AuthenticatedClient {
17    /// Connect with bounded requests; configure credentials before authenticated calls.
18    pub fn new(base: &str) -> Result<Self, CallError<WorkloadsError>> {
19        Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
20    }
21    pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<WorkloadsError>> {
22        let client =
23            WorkloadsClient::from_transport(http.base_url().as_str(), http.middleware_client())?;
24        Ok(Self { http, client })
25    }
26    /// Reuse a connection pool with redirects disabled to protect bearer credentials.
27    pub fn with_client(mut self, client: impl Into<ClientWithMiddleware>) -> Self {
28        self.http = self.http.with_client(client);
29        self.client = self.client.with_transport(self.http.middleware_client());
30        self
31    }
32    /// Resolve the provider's current credential before each request and pagination fetch.
33    pub fn with_token_source(mut self, provider: TokenSource) -> Self {
34        self.http = self.http.with_token_source(provider);
35        self
36    }
37    /// Register a public key with workload manage credentials permission.
38    pub async fn add_key(
39        &self,
40        workload_id: String,
41        request: CreateKeyRequest,
42    ) -> Result<KeyResponse, CallError<WorkloadsError>> {
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.add_key_http(auth_header, workload_id, request),
51        )
52        .await
53        .map_err(CallError::transport)?
54    }
55    /// Trust an external issuer with workload manage policies permission.
56    pub async fn create_policy(
57        &self,
58        workload_id: String,
59        request: CreatePolicyRequest,
60    ) -> Result<PolicyResponse, CallError<WorkloadsError>> {
61        let auth_header = self
62            .http
63            .auth_header()
64            .await
65            .map_err(CallError::transport)?;
66        tokio::time::timeout(
67            std::time::Duration::from_secs(60),
68            self.client
69                .create_policy_http(auth_header, workload_id, request),
70        )
71        .await
72        .map_err(CallError::transport)?
73    }
74    /// Create a machine identity with workload create permission in the Project.
75    pub async fn create_workload(
76        &self,
77        project_id: String,
78        request: CreateWorkloadRequest,
79    ) -> Result<WorkloadResponse, CallError<WorkloadsError>> {
80        let auth_header = self
81            .http
82            .auth_header()
83            .await
84            .map_err(CallError::transport)?;
85        tokio::time::timeout(
86            std::time::Duration::from_secs(60),
87            self.client
88                .create_workload_http(auth_header, project_id, request),
89        )
90        .await
91        .map_err(CallError::transport)?
92    }
93    /// Deactivate a machine identity and revoke its credentials and trust policies with workload
94    /// create permission.
95    pub async fn deactivate_workload(
96        &self,
97        workload_id: String,
98    ) -> Result<(), CallError<WorkloadsError>> {
99        let auth_header = self
100            .http
101            .auth_header()
102            .await
103            .map_err(CallError::transport)?;
104        tokio::time::timeout(
105            std::time::Duration::from_secs(60),
106            self.client
107                .deactivate_workload_http(auth_header, workload_id),
108        )
109        .await
110        .map_err(CallError::transport)?
111    }
112    /// List public keys with workload view permission.
113    pub async fn list_keys(
114        &self,
115        workload_id: String,
116        request: PageRequest,
117    ) -> Result<KeyPage, CallError<WorkloadsError>> {
118        let auth_header = self
119            .http
120            .auth_header()
121            .await
122            .map_err(CallError::transport)?;
123        tokio::time::timeout(
124            std::time::Duration::from_secs(60),
125            self.client
126                .list_keys_http(auth_header, workload_id, request),
127        )
128        .await
129        .map_err(CallError::transport)?
130    }
131    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
132    pub fn list_keys_list(
133        &self,
134        workload_id: String,
135        request: PageRequest,
136    ) -> crate::List<'_, Key> {
137        let options = crate::pagination::PageOptions {
138            token: request.page_token.clone(),
139            size: request.page_size,
140        };
141        crate::List::new(move |options| {
142            let workload_id = ToOwned::to_owned(&workload_id);
143            let mut request = request.clone();
144            request.page_token = options.token;
145            request.page_size = options.size;
146            Box::pin(async move {
147                let page = self.list_keys(workload_id, request).await?;
148                Ok(crate::Page {
149                    items: page.items,
150                    next_page_token: page.next_page_token,
151                })
152            })
153        })
154        .with_options(options)
155    }
156    /// List trust policies with workload view permission.
157    pub async fn list_policies(
158        &self,
159        workload_id: String,
160        request: PageRequest,
161    ) -> Result<PolicyPage, CallError<WorkloadsError>> {
162        let auth_header = self
163            .http
164            .auth_header()
165            .await
166            .map_err(CallError::transport)?;
167        tokio::time::timeout(
168            std::time::Duration::from_secs(60),
169            self.client
170                .list_policies_http(auth_header, workload_id, request),
171        )
172        .await
173        .map_err(CallError::transport)?
174    }
175    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
176    pub fn list_policies_list(
177        &self,
178        workload_id: String,
179        request: PageRequest,
180    ) -> crate::List<'_, Policy> {
181        let options = crate::pagination::PageOptions {
182            token: request.page_token.clone(),
183            size: request.page_size,
184        };
185        crate::List::new(move |options| {
186            let workload_id = ToOwned::to_owned(&workload_id);
187            let mut request = request.clone();
188            request.page_token = options.token;
189            request.page_size = options.size;
190            Box::pin(async move {
191                let page = self.list_policies(workload_id, request).await?;
192                Ok(crate::Page {
193                    items: page.items,
194                    next_page_token: page.next_page_token,
195                })
196            })
197        })
198        .with_options(options)
199    }
200    /// List active machine identities with workload view permission in the Project.
201    pub async fn list_workloads(
202        &self,
203        project_id: String,
204        request: PageRequest,
205    ) -> Result<WorkloadPage, CallError<WorkloadsError>> {
206        let auth_header = self
207            .http
208            .auth_header()
209            .await
210            .map_err(CallError::transport)?;
211        tokio::time::timeout(
212            std::time::Duration::from_secs(60),
213            self.client
214                .list_workloads_http(auth_header, project_id, request),
215        )
216        .await
217        .map_err(CallError::transport)?
218    }
219    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
220    pub fn list_workloads_list(
221        &self,
222        project_id: String,
223        request: PageRequest,
224    ) -> crate::List<'_, Workload> {
225        let options = crate::pagination::PageOptions {
226            token: request.page_token.clone(),
227            size: request.page_size,
228        };
229        crate::List::new(move |options| {
230            let project_id = ToOwned::to_owned(&project_id);
231            let mut request = request.clone();
232            request.page_token = options.token;
233            request.page_size = options.size;
234            Box::pin(async move {
235                let page = self.list_workloads(project_id, request).await?;
236                Ok(crate::Page {
237                    items: page.items,
238                    next_page_token: page.next_page_token,
239                })
240            })
241        })
242        .with_options(options)
243    }
244    /// Read a machine identity with workload view permission.
245    pub async fn read_workload(
246        &self,
247        workload_id: String,
248    ) -> Result<Workload, CallError<WorkloadsError>> {
249        let auth_header = self
250            .http
251            .auth_header()
252            .await
253            .map_err(CallError::transport)?;
254        tokio::time::timeout(
255            std::time::Duration::from_secs(60),
256            self.client.read_workload_http(auth_header, workload_id),
257        )
258        .await
259        .map_err(CallError::transport)?
260    }
261    /// Remove a public key with workload manage credentials permission.
262    pub async fn remove_key(
263        &self,
264        workload_id: String,
265        kid: String,
266    ) -> Result<(), CallError<WorkloadsError>> {
267        let auth_header = self
268            .http
269            .auth_header()
270            .await
271            .map_err(CallError::transport)?;
272        tokio::time::timeout(
273            std::time::Duration::from_secs(60),
274            self.client.remove_key_http(auth_header, workload_id, kid),
275        )
276        .await
277        .map_err(CallError::transport)?
278    }
279    /// Remove a trust policy with workload manage policies permission.
280    pub async fn remove_policy(&self, policy_id: String) -> Result<(), CallError<WorkloadsError>> {
281        let auth_header = self
282            .http
283            .auth_header()
284            .await
285            .map_err(CallError::transport)?;
286        tokio::time::timeout(
287            std::time::Duration::from_secs(60),
288            self.client.remove_policy_http(auth_header, policy_id),
289        )
290        .await
291        .map_err(CallError::transport)?
292    }
293    /// Revoke an existing client credential with workload manage credentials permission.
294    pub async fn revoke_credentials(
295        &self,
296        client_id: String,
297    ) -> Result<(), CallError<WorkloadsError>> {
298        let auth_header = self
299            .http
300            .auth_header()
301            .await
302            .map_err(CallError::transport)?;
303        tokio::time::timeout(
304            std::time::Duration::from_secs(60),
305            self.client.revoke_credentials_http(auth_header, client_id),
306        )
307        .await
308        .map_err(CallError::transport)?
309    }
310}