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.889.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 [`introspect_token`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum IntrospectTokenError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`list_available_scopes`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ListAvailableScopesError {
29    UnknownValue(serde_json::Value),
30}
31
32
33/// 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. 
34pub async fn introspect_token(configuration: &configuration::Configuration, workspace: Option<&str>, path: Option<&str>, method: Option<&str>) -> Result<models::TokenIntrospection, Error<IntrospectTokenError>> {
35    let local_var_configuration = configuration;
36
37    let local_var_client = &local_var_configuration.client;
38
39    let local_var_uri_str = format!("{}/tokens/introspect", local_var_configuration.base_path);
40    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
41
42    if let Some(ref local_var_str) = workspace {
43        local_var_req_builder = local_var_req_builder.query(&[("workspace", &local_var_str.to_string())]);
44    }
45    if let Some(ref local_var_str) = path {
46        local_var_req_builder = local_var_req_builder.query(&[("path", &local_var_str.to_string())]);
47    }
48    if let Some(ref local_var_str) = method {
49        local_var_req_builder = local_var_req_builder.query(&[("method", &local_var_str.to_string())]);
50    }
51    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
52        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
53    }
54    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
55        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
56    };
57
58    let local_var_req = local_var_req_builder.build()?;
59    let local_var_resp = local_var_client.execute(local_var_req).await?;
60
61    let local_var_status = local_var_resp.status();
62    let local_var_content = local_var_resp.text().await?;
63
64    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
65        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
66    } else {
67        let local_var_entity: Option<IntrospectTokenError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
68        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
69        Err(Error::ResponseError(local_var_error))
70    }
71}
72
73pub async fn list_available_scopes(configuration: &configuration::Configuration, ) -> Result<Vec<models::ScopeDomain>, Error<ListAvailableScopesError>> {
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/list/scopes", 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_user_agent) = local_var_configuration.user_agent {
82        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
83    }
84    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
85        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
86    };
87
88    let local_var_req = local_var_req_builder.build()?;
89    let local_var_resp = local_var_client.execute(local_var_req).await?;
90
91    let local_var_status = local_var_resp.status();
92    let local_var_content = local_var_resp.text().await?;
93
94    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
95        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
96    } else {
97        let local_var_entity: Option<ListAvailableScopesError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
98        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
99        Err(Error::ResponseError(local_var_error))
100    }
101}
102