windmill_api/apis/
audit_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.505.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_audit_log`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAuditLogError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`list_audit_logs`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum ListAuditLogsError {
29    UnknownValue(serde_json::Value),
30}
31
32
33pub async fn get_audit_log(configuration: &configuration::Configuration, workspace: &str, id: i32) -> Result<models::AuditLog, Error<GetAuditLogError>> {
34    let local_var_configuration = configuration;
35
36    let local_var_client = &local_var_configuration.client;
37
38    let local_var_uri_str = format!("{}/w/{workspace}/audit/get/{id}", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace), id=id);
39    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
40
41    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
42        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
43    }
44    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
45        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
46    };
47
48    let local_var_req = local_var_req_builder.build()?;
49    let local_var_resp = local_var_client.execute(local_var_req).await?;
50
51    let local_var_status = local_var_resp.status();
52    let local_var_content = local_var_resp.text().await?;
53
54    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
55        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
56    } else {
57        let local_var_entity: Option<GetAuditLogError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
58        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
59        Err(Error::ResponseError(local_var_error))
60    }
61}
62
63pub async fn list_audit_logs(configuration: &configuration::Configuration, workspace: &str, page: Option<i32>, per_page: Option<i32>, before: Option<String>, after: Option<String>, username: Option<&str>, operation: Option<&str>, operations: Option<&str>, exclude_operations: Option<&str>, resource: Option<&str>, action_kind: Option<&str>, all_workspaces: Option<bool>) -> Result<Vec<models::AuditLog>, Error<ListAuditLogsError>> {
64    let local_var_configuration = configuration;
65
66    let local_var_client = &local_var_configuration.client;
67
68    let local_var_uri_str = format!("{}/w/{workspace}/audit/list", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
69    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
70
71    if let Some(ref local_var_str) = page {
72        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
73    }
74    if let Some(ref local_var_str) = per_page {
75        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
76    }
77    if let Some(ref local_var_str) = before {
78        local_var_req_builder = local_var_req_builder.query(&[("before", &local_var_str.to_string())]);
79    }
80    if let Some(ref local_var_str) = after {
81        local_var_req_builder = local_var_req_builder.query(&[("after", &local_var_str.to_string())]);
82    }
83    if let Some(ref local_var_str) = username {
84        local_var_req_builder = local_var_req_builder.query(&[("username", &local_var_str.to_string())]);
85    }
86    if let Some(ref local_var_str) = operation {
87        local_var_req_builder = local_var_req_builder.query(&[("operation", &local_var_str.to_string())]);
88    }
89    if let Some(ref local_var_str) = operations {
90        local_var_req_builder = local_var_req_builder.query(&[("operations", &local_var_str.to_string())]);
91    }
92    if let Some(ref local_var_str) = exclude_operations {
93        local_var_req_builder = local_var_req_builder.query(&[("exclude_operations", &local_var_str.to_string())]);
94    }
95    if let Some(ref local_var_str) = resource {
96        local_var_req_builder = local_var_req_builder.query(&[("resource", &local_var_str.to_string())]);
97    }
98    if let Some(ref local_var_str) = action_kind {
99        local_var_req_builder = local_var_req_builder.query(&[("action_kind", &local_var_str.to_string())]);
100    }
101    if let Some(ref local_var_str) = all_workspaces {
102        local_var_req_builder = local_var_req_builder.query(&[("all_workspaces", &local_var_str.to_string())]);
103    }
104    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
105        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
106    }
107    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
108        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
109    };
110
111    let local_var_req = local_var_req_builder.build()?;
112    let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114    let local_var_status = local_var_resp.status();
115    let local_var_content = local_var_resp.text().await?;
116
117    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
119    } else {
120        let local_var_entity: Option<ListAuditLogsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
121        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
122        Err(Error::ResponseError(local_var_error))
123    }
124}
125