ory_client/apis/
workspace_api.rs

1/*
2 * Ory APIs
3 *
4 * # Introduction Documentation for all public and administrative Ory APIs. Administrative APIs can only be accessed with a valid Personal Access Token. Public APIs are mostly used in browsers.  ## SDKs This document describes the APIs available in the Ory Network. The APIs are available as SDKs for the following languages:  | Language       | Download SDK                                                     | Documentation                                                                        | | -------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------ | | Dart           | [pub.dev](https://pub.dev/packages/ory_client)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/dart/README.md)       | | .NET           | [nuget.org](https://www.nuget.org/packages/Ory.Client/)          | [README](https://github.com/ory/sdk/blob/master/clients/client/dotnet/README.md)     | | Elixir         | [hex.pm](https://hex.pm/packages/ory_client)                     | [README](https://github.com/ory/sdk/blob/master/clients/client/elixir/README.md)     | | Go             | [github.com](https://github.com/ory/client-go)                   | [README](https://github.com/ory/sdk/blob/master/clients/client/go/README.md)         | | Java           | [maven.org](https://search.maven.org/artifact/sh.ory/ory-client) | [README](https://github.com/ory/sdk/blob/master/clients/client/java/README.md)       | | JavaScript     | [npmjs.com](https://www.npmjs.com/package/@ory/client)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript/README.md) | | JavaScript (With fetch) | [npmjs.com](https://www.npmjs.com/package/@ory/client-fetch)           | [README](https://github.com/ory/sdk/blob/master/clients/client/typescript-fetch/README.md) |  | PHP            | [packagist.org](https://packagist.org/packages/ory/client)       | [README](https://github.com/ory/sdk/blob/master/clients/client/php/README.md)        | | Python         | [pypi.org](https://pypi.org/project/ory-client/)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/python/README.md)     | | Ruby           | [rubygems.org](https://rubygems.org/gems/ory-client)             | [README](https://github.com/ory/sdk/blob/master/clients/client/ruby/README.md)       | | Rust           | [crates.io](https://crates.io/crates/ory-client)                 | [README](https://github.com/ory/sdk/blob/master/clients/client/rust/README.md)       | 
5 *
6 * The version of the OpenAPI document: v1.22.6
7 * Contact: support@ory.sh
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`create_workspace`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateWorkspaceError {
22    Status400(models::ErrorGeneric),
23    Status401(models::ErrorGeneric),
24    Status403(models::ErrorGeneric),
25    Status500(models::ErrorGeneric),
26    DefaultResponse(models::ErrorGeneric),
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`create_workspace_api_key`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum CreateWorkspaceApiKeyError {
34    DefaultResponse(models::ErrorGeneric),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`delete_workspace_api_key`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum DeleteWorkspaceApiKeyError {
42    DefaultResponse(models::ErrorGeneric),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_workspace`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetWorkspaceError {
50    Status400(models::ErrorGeneric),
51    Status401(models::ErrorGeneric),
52    Status403(models::ErrorGeneric),
53    Status500(models::ErrorGeneric),
54    DefaultResponse(models::ErrorGeneric),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`list_workspace_api_keys`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum ListWorkspaceApiKeysError {
62    DefaultResponse(models::ErrorGeneric),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`list_workspace_projects`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ListWorkspaceProjectsError {
70    Status400(models::ErrorGeneric),
71    Status401(models::ErrorGeneric),
72    Status403(models::ErrorGeneric),
73    Status500(models::ErrorGeneric),
74    DefaultResponse(models::ErrorGeneric),
75    UnknownValue(serde_json::Value),
76}
77
78/// struct for typed errors of method [`list_workspaces`]
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum ListWorkspacesError {
82    Status400(models::ErrorGeneric),
83    Status401(models::ErrorGeneric),
84    Status403(models::ErrorGeneric),
85    Status500(models::ErrorGeneric),
86    DefaultResponse(models::ErrorGeneric),
87    UnknownValue(serde_json::Value),
88}
89
90/// struct for typed errors of method [`update_workspace`]
91#[derive(Debug, Clone, Serialize, Deserialize)]
92#[serde(untagged)]
93pub enum UpdateWorkspaceError {
94    Status400(models::ErrorGeneric),
95    Status401(models::ErrorGeneric),
96    Status403(models::ErrorGeneric),
97    Status500(models::ErrorGeneric),
98    DefaultResponse(models::ErrorGeneric),
99    UnknownValue(serde_json::Value),
100}
101
102
103pub async fn create_workspace(configuration: &configuration::Configuration, create_workspace_body: Option<models::CreateWorkspaceBody>) -> Result<models::Workspace, Error<CreateWorkspaceError>> {
104    // add a prefix to parameters to efficiently prevent name collisions
105    let p_create_workspace_body = create_workspace_body;
106
107    let uri_str = format!("{}/workspaces", configuration.base_path);
108    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
109
110    if let Some(ref user_agent) = configuration.user_agent {
111        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112    }
113    if let Some(ref token) = configuration.bearer_access_token {
114        req_builder = req_builder.bearer_auth(token.to_owned());
115    };
116    req_builder = req_builder.json(&p_create_workspace_body);
117
118    let req = req_builder.build()?;
119    let resp = configuration.client.execute(req).await?;
120
121    let status = resp.status();
122    let content_type = resp
123        .headers()
124        .get("content-type")
125        .and_then(|v| v.to_str().ok())
126        .unwrap_or("application/octet-stream");
127    let content_type = super::ContentType::from(content_type);
128
129    if !status.is_client_error() && !status.is_server_error() {
130        let content = resp.text().await?;
131        match content_type {
132            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
133            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Workspace`"))),
134            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Workspace`")))),
135        }
136    } else {
137        let content = resp.text().await?;
138        let entity: Option<CreateWorkspaceError> = serde_json::from_str(&content).ok();
139        Err(Error::ResponseError(ResponseContent { status, content, entity }))
140    }
141}
142
143/// Create an API key for a workspace.
144pub async fn create_workspace_api_key(configuration: &configuration::Configuration, workspace: &str, create_workspace_api_key_body: Option<models::CreateWorkspaceApiKeyBody>) -> Result<models::WorkspaceApiKey, Error<CreateWorkspaceApiKeyError>> {
145    // add a prefix to parameters to efficiently prevent name collisions
146    let p_workspace = workspace;
147    let p_create_workspace_api_key_body = create_workspace_api_key_body;
148
149    let uri_str = format!("{}/workspaces/{workspace}/tokens", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
150    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
151
152    if let Some(ref user_agent) = configuration.user_agent {
153        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154    }
155    if let Some(ref token) = configuration.bearer_access_token {
156        req_builder = req_builder.bearer_auth(token.to_owned());
157    };
158    req_builder = req_builder.json(&p_create_workspace_api_key_body);
159
160    let req = req_builder.build()?;
161    let resp = configuration.client.execute(req).await?;
162
163    let status = resp.status();
164    let content_type = resp
165        .headers()
166        .get("content-type")
167        .and_then(|v| v.to_str().ok())
168        .unwrap_or("application/octet-stream");
169    let content_type = super::ContentType::from(content_type);
170
171    if !status.is_client_error() && !status.is_server_error() {
172        let content = resp.text().await?;
173        match content_type {
174            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
175            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WorkspaceApiKey`"))),
176            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::WorkspaceApiKey`")))),
177        }
178    } else {
179        let content = resp.text().await?;
180        let entity: Option<CreateWorkspaceApiKeyError> = serde_json::from_str(&content).ok();
181        Err(Error::ResponseError(ResponseContent { status, content, entity }))
182    }
183}
184
185/// Deletes an API key and immediately removes it.
186pub async fn delete_workspace_api_key(configuration: &configuration::Configuration, workspace: &str, token_id: &str) -> Result<(), Error<DeleteWorkspaceApiKeyError>> {
187    // add a prefix to parameters to efficiently prevent name collisions
188    let p_workspace = workspace;
189    let p_token_id = token_id;
190
191    let uri_str = format!("{}/workspaces/{workspace}/tokens/{token_id}", configuration.base_path, workspace=crate::apis::urlencode(p_workspace), token_id=crate::apis::urlencode(p_token_id));
192    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
193
194    if let Some(ref user_agent) = configuration.user_agent {
195        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
196    }
197    if let Some(ref token) = configuration.bearer_access_token {
198        req_builder = req_builder.bearer_auth(token.to_owned());
199    };
200
201    let req = req_builder.build()?;
202    let resp = configuration.client.execute(req).await?;
203
204    let status = resp.status();
205
206    if !status.is_client_error() && !status.is_server_error() {
207        Ok(())
208    } else {
209        let content = resp.text().await?;
210        let entity: Option<DeleteWorkspaceApiKeyError> = serde_json::from_str(&content).ok();
211        Err(Error::ResponseError(ResponseContent { status, content, entity }))
212    }
213}
214
215/// Any workspace member can access this endpoint.
216pub async fn get_workspace(configuration: &configuration::Configuration, workspace: &str) -> Result<models::Workspace, Error<GetWorkspaceError>> {
217    // add a prefix to parameters to efficiently prevent name collisions
218    let p_workspace = workspace;
219
220    let uri_str = format!("{}/workspaces/{workspace}", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
221    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
222
223    if let Some(ref user_agent) = configuration.user_agent {
224        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
225    }
226    if let Some(ref token) = configuration.bearer_access_token {
227        req_builder = req_builder.bearer_auth(token.to_owned());
228    };
229
230    let req = req_builder.build()?;
231    let resp = configuration.client.execute(req).await?;
232
233    let status = resp.status();
234    let content_type = resp
235        .headers()
236        .get("content-type")
237        .and_then(|v| v.to_str().ok())
238        .unwrap_or("application/octet-stream");
239    let content_type = super::ContentType::from(content_type);
240
241    if !status.is_client_error() && !status.is_server_error() {
242        let content = resp.text().await?;
243        match content_type {
244            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
245            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Workspace`"))),
246            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Workspace`")))),
247        }
248    } else {
249        let content = resp.text().await?;
250        let entity: Option<GetWorkspaceError> = serde_json::from_str(&content).ok();
251        Err(Error::ResponseError(ResponseContent { status, content, entity }))
252    }
253}
254
255/// A list of all the workspace's API keys.
256pub async fn list_workspace_api_keys(configuration: &configuration::Configuration, workspace: &str) -> Result<Vec<models::WorkspaceApiKey>, Error<ListWorkspaceApiKeysError>> {
257    // add a prefix to parameters to efficiently prevent name collisions
258    let p_workspace = workspace;
259
260    let uri_str = format!("{}/workspaces/{workspace}/tokens", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
261    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
262
263    if let Some(ref user_agent) = configuration.user_agent {
264        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
265    }
266    if let Some(ref token) = configuration.bearer_access_token {
267        req_builder = req_builder.bearer_auth(token.to_owned());
268    };
269
270    let req = req_builder.build()?;
271    let resp = configuration.client.execute(req).await?;
272
273    let status = resp.status();
274    let content_type = resp
275        .headers()
276        .get("content-type")
277        .and_then(|v| v.to_str().ok())
278        .unwrap_or("application/octet-stream");
279    let content_type = super::ContentType::from(content_type);
280
281    if !status.is_client_error() && !status.is_server_error() {
282        let content = resp.text().await?;
283        match content_type {
284            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
285            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::WorkspaceApiKey&gt;`"))),
286            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::WorkspaceApiKey&gt;`")))),
287        }
288    } else {
289        let content = resp.text().await?;
290        let entity: Option<ListWorkspaceApiKeysError> = serde_json::from_str(&content).ok();
291        Err(Error::ResponseError(ResponseContent { status, content, entity }))
292    }
293}
294
295/// Any workspace member can access this endpoint.
296pub async fn list_workspace_projects(configuration: &configuration::Configuration, workspace: &str) -> Result<models::ListWorkspaceProjects, Error<ListWorkspaceProjectsError>> {
297    // add a prefix to parameters to efficiently prevent name collisions
298    let p_workspace = workspace;
299
300    let uri_str = format!("{}/workspaces/{workspace}/projects", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
301    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
302
303    if let Some(ref user_agent) = configuration.user_agent {
304        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
305    }
306    if let Some(ref token) = configuration.bearer_access_token {
307        req_builder = req_builder.bearer_auth(token.to_owned());
308    };
309
310    let req = req_builder.build()?;
311    let resp = configuration.client.execute(req).await?;
312
313    let status = resp.status();
314    let content_type = resp
315        .headers()
316        .get("content-type")
317        .and_then(|v| v.to_str().ok())
318        .unwrap_or("application/octet-stream");
319    let content_type = super::ContentType::from(content_type);
320
321    if !status.is_client_error() && !status.is_server_error() {
322        let content = resp.text().await?;
323        match content_type {
324            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
325            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWorkspaceProjects`"))),
326            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListWorkspaceProjects`")))),
327        }
328    } else {
329        let content = resp.text().await?;
330        let entity: Option<ListWorkspaceProjectsError> = serde_json::from_str(&content).ok();
331        Err(Error::ResponseError(ResponseContent { status, content, entity }))
332    }
333}
334
335pub async fn list_workspaces(configuration: &configuration::Configuration, page_size: Option<i64>, page_token: Option<&str>) -> Result<models::ListWorkspaces, Error<ListWorkspacesError>> {
336    // add a prefix to parameters to efficiently prevent name collisions
337    let p_page_size = page_size;
338    let p_page_token = page_token;
339
340    let uri_str = format!("{}/workspaces", configuration.base_path);
341    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
342
343    if let Some(ref param_value) = p_page_size {
344        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
345    }
346    if let Some(ref param_value) = p_page_token {
347        req_builder = req_builder.query(&[("page_token", &param_value.to_string())]);
348    }
349    if let Some(ref user_agent) = configuration.user_agent {
350        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
351    }
352    if let Some(ref token) = configuration.bearer_access_token {
353        req_builder = req_builder.bearer_auth(token.to_owned());
354    };
355
356    let req = req_builder.build()?;
357    let resp = configuration.client.execute(req).await?;
358
359    let status = resp.status();
360    let content_type = resp
361        .headers()
362        .get("content-type")
363        .and_then(|v| v.to_str().ok())
364        .unwrap_or("application/octet-stream");
365    let content_type = super::ContentType::from(content_type);
366
367    if !status.is_client_error() && !status.is_server_error() {
368        let content = resp.text().await?;
369        match content_type {
370            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
371            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWorkspaces`"))),
372            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListWorkspaces`")))),
373        }
374    } else {
375        let content = resp.text().await?;
376        let entity: Option<ListWorkspacesError> = serde_json::from_str(&content).ok();
377        Err(Error::ResponseError(ResponseContent { status, content, entity }))
378    }
379}
380
381/// Workspace members with the role `OWNER` can access this endpoint.
382pub async fn update_workspace(configuration: &configuration::Configuration, workspace: &str, update_workspace_body: Option<models::UpdateWorkspaceBody>) -> Result<models::Workspace, Error<UpdateWorkspaceError>> {
383    // add a prefix to parameters to efficiently prevent name collisions
384    let p_workspace = workspace;
385    let p_update_workspace_body = update_workspace_body;
386
387    let uri_str = format!("{}/workspaces/{workspace}", configuration.base_path, workspace=crate::apis::urlencode(p_workspace));
388    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
389
390    if let Some(ref user_agent) = configuration.user_agent {
391        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
392    }
393    if let Some(ref token) = configuration.bearer_access_token {
394        req_builder = req_builder.bearer_auth(token.to_owned());
395    };
396    req_builder = req_builder.json(&p_update_workspace_body);
397
398    let req = req_builder.build()?;
399    let resp = configuration.client.execute(req).await?;
400
401    let status = resp.status();
402    let content_type = resp
403        .headers()
404        .get("content-type")
405        .and_then(|v| v.to_str().ok())
406        .unwrap_or("application/octet-stream");
407    let content_type = super::ContentType::from(content_type);
408
409    if !status.is_client_error() && !status.is_server_error() {
410        let content = resp.text().await?;
411        match content_type {
412            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
413            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Workspace`"))),
414            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Workspace`")))),
415        }
416    } else {
417        let content = resp.text().await?;
418        let entity: Option<UpdateWorkspaceError> = serde_json::from_str(&content).ok();
419        Err(Error::ResponseError(ResponseContent { status, content, entity }))
420    }
421}
422