Skip to main content

spiral/resources/generated/
project.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::project::ProjectClient;
7use crate::api::project::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: ProjectClient,
15}
16impl AuthenticatedClient {
17    /// Connect with bounded requests; configure credentials before authenticated calls.
18    pub fn new(base: &str) -> Result<Self, CallError<ProjectError>> {
19        Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
20    }
21    pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<ProjectError>> {
22        let client =
23            ProjectClient::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    /// Create a Project with the same provisioning and default grants as the legacy API. Requires
38    /// Organization create-project permission.
39    pub async fn create_project(
40        &self,
41        request: CreateProjectRequest,
42    ) -> Result<CreateProjectResponse, CallError<ProjectError>> {
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_project_http(auth_header, request),
51        )
52        .await
53        .map_err(CallError::transport)?
54    }
55    /// Drop a Project with Project drop permission. Existing resource guards must permit deletion.
56    pub async fn delete_project(&self, project_id: String) -> Result<(), CallError<ProjectError>> {
57        let auth_header = self
58            .http
59            .auth_header()
60            .await
61            .map_err(CallError::transport)?;
62        tokio::time::timeout(
63            std::time::Duration::from_secs(60),
64            self.client.delete_project_http(auth_header, project_id),
65        )
66        .await
67        .map_err(CallError::transport)?
68    }
69    /// List Projects the caller can access, ordered by Project ID. Authorization is evaluated for
70    /// every page.
71    pub async fn list_projects(
72        &self,
73        request: ListProjectsRequest,
74    ) -> Result<ProjectPage, CallError<ProjectError>> {
75        let auth_header = self
76            .http
77            .auth_header()
78            .await
79            .map_err(CallError::transport)?;
80        tokio::time::timeout(
81            std::time::Duration::from_secs(60),
82            self.client.list_projects_http(auth_header, request),
83        )
84        .await
85        .map_err(CallError::transport)?
86    }
87    /// Build a lazy collection, retaining filters and resolving fresh credentials for each page.
88    pub fn list_projects_list(&self, request: ListProjectsRequest) -> crate::List<'_, Project> {
89        let options = crate::pagination::PageOptions {
90            token: request.page_token.clone(),
91            size: request.page_size,
92        };
93        crate::List::new(move |options| {
94            let mut request = request.clone();
95            request.page_token = options.token;
96            request.page_size = options.size;
97            Box::pin(async move {
98                let page = self.list_projects(request).await?;
99                Ok(crate::Page {
100                    items: page.items,
101                    next_page_token: page.next_page_token,
102                })
103            })
104        })
105        .with_options(options)
106    }
107    /// Read shared presentation state with Project view permission.
108    pub async fn read_presentation(
109        &self,
110        project_id: String,
111        request: PresentationKey,
112    ) -> Result<Presentation, CallError<ProjectError>> {
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                .read_presentation_http(auth_header, project_id, request),
122        )
123        .await
124        .map_err(CallError::transport)?
125    }
126    /// Read a Project with Project view permission.
127    pub async fn read_project(
128        &self,
129        project_id: String,
130    ) -> Result<Project, CallError<ProjectError>> {
131        let auth_header = self
132            .http
133            .auth_header()
134            .await
135            .map_err(CallError::transport)?;
136        tokio::time::timeout(
137            std::time::Duration::from_secs(60),
138            self.client.read_project_http(auth_header, project_id),
139        )
140        .await
141        .map_err(CallError::transport)?
142    }
143    /// Save shared presentation state with Catalog publish permission. An outdated revision returns
144    /// Conflict.
145    pub async fn save_presentation(
146        &self,
147        project_id: String,
148        request: SavePresentation,
149    ) -> Result<Presentation, CallError<ProjectError>> {
150        let auth_header = self
151            .http
152            .auth_header()
153            .await
154            .map_err(CallError::transport)?;
155        tokio::time::timeout(
156            std::time::Duration::from_secs(60),
157            self.client
158                .save_presentation_http(auth_header, project_id, request),
159        )
160        .await
161        .map_err(CallError::transport)?
162    }
163}