Skip to main content

windmill_api/apis/
token_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 [`get_token_admin_reliance`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetTokenAdminRelianceError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`introspect_token`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum IntrospectTokenError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`list_available_scopes`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ListAvailableScopesError {
36    UnknownValue(serde_json::Value),
37}
38
39
40/// For each workspace the caller administers among `workspace_ids` (every one when omitted), what a token with these scopes reaches only through the caller's admin role: folders they are not a member of, other users' items not shared with them, resources the runnables the scopes name reference, and admin-only actions the scopes allow. Workspaces with nothing to report are left out. Refused to a credential that is scoped or withholds admin rights. 
41pub async fn get_token_admin_reliance(configuration: &configuration::Configuration, get_token_admin_reliance_request: models::GetTokenAdminRelianceRequest) -> Result<Vec<models::TokenAdminReliance>, Error<GetTokenAdminRelianceError>> {
42    let local_var_configuration = configuration;
43
44    let local_var_client = &local_var_configuration.client;
45
46    let local_var_uri_str = format!("{}/tokens/admin_reliance", local_var_configuration.base_path);
47    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
48
49    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
50        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
51    }
52    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
53        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
54    };
55    local_var_req_builder = local_var_req_builder.json(&get_token_admin_reliance_request);
56
57    let local_var_req = local_var_req_builder.build()?;
58    let local_var_resp = local_var_client.execute(local_var_req).await?;
59
60    let local_var_status = local_var_resp.status();
61    let local_var_content = local_var_resp.text().await?;
62
63    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
64        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
65    } else {
66        let local_var_entity: Option<GetTokenAdminRelianceError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
67        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
68        Err(Error::ResponseError(local_var_error))
69    }
70}
71
72/// Reports what the bearer credential of this request is: its row (label, expiry, bound workspace, scopes, carried admin rights), the identity it acts as in `workspace`, and whether the route layer would admit it on `method` `path`. Only the presented token is ever described. Every token may call it, whatever its scopes. 
73pub async fn introspect_token(configuration: &configuration::Configuration, workspace: Option<&str>, path: Option<&str>, method: Option<&str>) -> Result<models::TokenIntrospection, Error<IntrospectTokenError>> {
74    let local_var_configuration = configuration;
75
76    let local_var_client = &local_var_configuration.client;
77
78    let local_var_uri_str = format!("{}/tokens/introspect", local_var_configuration.base_path);
79    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
80
81    if let Some(ref local_var_str) = workspace {
82        local_var_req_builder = local_var_req_builder.query(&[("workspace", &local_var_str.to_string())]);
83    }
84    if let Some(ref local_var_str) = path {
85        local_var_req_builder = local_var_req_builder.query(&[("path", &local_var_str.to_string())]);
86    }
87    if let Some(ref local_var_str) = method {
88        local_var_req_builder = local_var_req_builder.query(&[("method", &local_var_str.to_string())]);
89    }
90    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
91        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
92    }
93    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
94        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
95    };
96
97    let local_var_req = local_var_req_builder.build()?;
98    let local_var_resp = local_var_client.execute(local_var_req).await?;
99
100    let local_var_status = local_var_resp.status();
101    let local_var_content = local_var_resp.text().await?;
102
103    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
104        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
105    } else {
106        let local_var_entity: Option<IntrospectTokenError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
107        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
108        Err(Error::ResponseError(local_var_error))
109    }
110}
111
112pub async fn list_available_scopes(configuration: &configuration::Configuration, ) -> Result<Vec<models::ScopeDomain>, Error<ListAvailableScopesError>> {
113    let local_var_configuration = configuration;
114
115    let local_var_client = &local_var_configuration.client;
116
117    let local_var_uri_str = format!("{}/tokens/list/scopes", local_var_configuration.base_path);
118    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
119
120    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
121        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
122    }
123    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
124        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
125    };
126
127    let local_var_req = local_var_req_builder.build()?;
128    let local_var_resp = local_var_client.execute(local_var_req).await?;
129
130    let local_var_status = local_var_resp.status();
131    let local_var_content = local_var_resp.text().await?;
132
133    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
134        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
135    } else {
136        let local_var_entity: Option<ListAvailableScopesError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
137        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
138        Err(Error::ResponseError(local_var_error))
139    }
140}
141