Skip to main content

windmill_api/apis/
granular_acl_api.rs

1/*
2 * Windmill API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.896.0
7 * Contact: contact@windmill.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`add_granular_acls`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddGranularAclsError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`browse_access_folders`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum BrowseAccessFoldersError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`browse_access_items`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum BrowseAccessItemsError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_granular_acls`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetGranularAclsError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_principal_access`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetPrincipalAccessError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`remove_granular_acls`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum RemoveGranularAclsError {
57    UnknownValue(serde_json::Value),
58}
59
60
61pub async fn add_granular_acls(configuration: &configuration::Configuration, workspace: &str, path: &str, kind: &str, remove_owner_to_folder_request: models::RemoveOwnerToFolderRequest) -> Result<String, Error<AddGranularAclsError>> {
62    let local_var_configuration = configuration;
63
64    let local_var_client = &local_var_configuration.client;
65
66    let local_var_uri_str = format!("{}/w/{workspace}/acls/add/{kind}/{path}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), path=crate::apis::urlencode(path), kind=crate::apis::urlencode(kind));
67    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
68
69    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
70        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
71    }
72    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
73        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
74    };
75    local_var_req_builder = local_var_req_builder.json(&remove_owner_to_folder_request);
76
77    let local_var_req = local_var_req_builder.build()?;
78    let local_var_resp = local_var_client.execute(local_var_req).await?;
79
80    let local_var_status = local_var_resp.status();
81    let local_var_content = local_var_resp.text().await?;
82
83    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
84        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
85    } else {
86        let local_var_entity: Option<AddGranularAclsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
87        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
88        Err(Error::ResponseError(local_var_error))
89    }
90}
91
92pub async fn browse_access_folders(configuration: &configuration::Configuration, workspace: &str, principal: &str) -> Result<Vec<models::BrowseAccessFolders200ResponseInner>, Error<BrowseAccessFoldersError>> {
93    let local_var_configuration = configuration;
94
95    let local_var_client = &local_var_configuration.client;
96
97    let local_var_uri_str = format!("{}/w/{workspace}/access/browse_folders", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
98    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
99
100    local_var_req_builder = local_var_req_builder.query(&[("principal", &principal.to_string())]);
101    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
102        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
103    }
104    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
105        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
106    };
107
108    let local_var_req = local_var_req_builder.build()?;
109    let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111    let local_var_status = local_var_resp.status();
112    let local_var_content = local_var_resp.text().await?;
113
114    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
115        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
116    } else {
117        let local_var_entity: Option<BrowseAccessFoldersError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
118        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
119        Err(Error::ResponseError(local_var_error))
120    }
121}
122
123pub async fn browse_access_items(configuration: &configuration::Configuration, workspace: &str, principal: &str, prefix: Option<&str>, kind: Option<&str>, search: Option<&str>, offset: Option<i32>) -> Result<models::BrowseAccessItems200Response, Error<BrowseAccessItemsError>> {
124    let local_var_configuration = configuration;
125
126    let local_var_client = &local_var_configuration.client;
127
128    let local_var_uri_str = format!("{}/w/{workspace}/access/browse_items", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
129    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
130
131    local_var_req_builder = local_var_req_builder.query(&[("principal", &principal.to_string())]);
132    if let Some(ref local_var_str) = prefix {
133        local_var_req_builder = local_var_req_builder.query(&[("prefix", &local_var_str.to_string())]);
134    }
135    if let Some(ref local_var_str) = kind {
136        local_var_req_builder = local_var_req_builder.query(&[("kind", &local_var_str.to_string())]);
137    }
138    if let Some(ref local_var_str) = search {
139        local_var_req_builder = local_var_req_builder.query(&[("search", &local_var_str.to_string())]);
140    }
141    if let Some(ref local_var_str) = offset {
142        local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
143    }
144    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
145        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
146    }
147    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
148        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
149    };
150
151    let local_var_req = local_var_req_builder.build()?;
152    let local_var_resp = local_var_client.execute(local_var_req).await?;
153
154    let local_var_status = local_var_resp.status();
155    let local_var_content = local_var_resp.text().await?;
156
157    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
158        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
159    } else {
160        let local_var_entity: Option<BrowseAccessItemsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
161        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
162        Err(Error::ResponseError(local_var_error))
163    }
164}
165
166pub async fn get_granular_acls(configuration: &configuration::Configuration, workspace: &str, path: &str, kind: &str) -> Result<std::collections::HashMap<String, bool>, Error<GetGranularAclsError>> {
167    let local_var_configuration = configuration;
168
169    let local_var_client = &local_var_configuration.client;
170
171    let local_var_uri_str = format!("{}/w/{workspace}/acls/get/{kind}/{path}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), path=crate::apis::urlencode(path), kind=crate::apis::urlencode(kind));
172    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
173
174    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
175        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
176    }
177    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
178        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
179    };
180
181    let local_var_req = local_var_req_builder.build()?;
182    let local_var_resp = local_var_client.execute(local_var_req).await?;
183
184    let local_var_status = local_var_resp.status();
185    let local_var_content = local_var_resp.text().await?;
186
187    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
188        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
189    } else {
190        let local_var_entity: Option<GetGranularAclsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
191        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
192        Err(Error::ResponseError(local_var_error))
193    }
194}
195
196/// Workspace admins can query any principal; other members only themselves and the groups they belong to. An admin principal reaches everything, so `items` is empty. 
197pub async fn get_principal_access(configuration: &configuration::Configuration, workspace: &str, principal: &str) -> Result<models::PrincipalAccess, Error<GetPrincipalAccessError>> {
198    let local_var_configuration = configuration;
199
200    let local_var_client = &local_var_configuration.client;
201
202    let local_var_uri_str = format!("{}/w/{workspace}/access/get", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
203    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
204
205    local_var_req_builder = local_var_req_builder.query(&[("principal", &principal.to_string())]);
206    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
207        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
208    }
209    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
210        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
211    };
212
213    let local_var_req = local_var_req_builder.build()?;
214    let local_var_resp = local_var_client.execute(local_var_req).await?;
215
216    let local_var_status = local_var_resp.status();
217    let local_var_content = local_var_resp.text().await?;
218
219    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
220        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
221    } else {
222        let local_var_entity: Option<GetPrincipalAccessError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
223        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
224        Err(Error::ResponseError(local_var_error))
225    }
226}
227
228pub async fn remove_granular_acls(configuration: &configuration::Configuration, workspace: &str, path: &str, kind: &str, add_owner_to_folder_request: models::AddOwnerToFolderRequest) -> Result<String, Error<RemoveGranularAclsError>> {
229    let local_var_configuration = configuration;
230
231    let local_var_client = &local_var_configuration.client;
232
233    let local_var_uri_str = format!("{}/w/{workspace}/acls/remove/{kind}/{path}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), path=crate::apis::urlencode(path), kind=crate::apis::urlencode(kind));
234    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
235
236    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
237        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
238    }
239    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
240        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
241    };
242    local_var_req_builder = local_var_req_builder.json(&add_owner_to_folder_request);
243
244    let local_var_req = local_var_req_builder.build()?;
245    let local_var_resp = local_var_client.execute(local_var_req).await?;
246
247    let local_var_status = local_var_resp.status();
248    let local_var_content = local_var_resp.text().await?;
249
250    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
251        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
252    } else {
253        let local_var_entity: Option<RemoveGranularAclsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
254        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
255        Err(Error::ResponseError(local_var_error))
256    }
257}
258