Skip to main content

bitwarden_api_api/apis/
audit_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{AuthRequired, ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait AuditApi: Send + Sync {
29    /// GET /organizations/{orgId}/audit/items
30    async fn get_items<'a>(
31        &self,
32        org_id: uuid::Uuid,
33        start: Option<String>,
34        end: Option<String>,
35    ) -> Result<models::AccessAuditItemResponseModelListResponseModel, Error>;
36
37    /// GET /organizations/{orgId}/audit
38    async fn get_trail<'a>(
39        &self,
40        org_id: uuid::Uuid,
41        start: Option<String>,
42        end: Option<String>,
43        kind: Option<Vec<String>>,
44        actor_id: Option<Vec<uuid::Uuid>>,
45        include_automated_actor: Option<bool>,
46        requester_id: Option<Vec<uuid::Uuid>>,
47        cipher_id: Option<Vec<uuid::Uuid>>,
48        rule_id: Option<Vec<uuid::Uuid>>,
49        continuation_token: Option<&'a str>,
50    ) -> Result<models::AccessAuditEventResponseModelListResponseModel, Error>;
51}
52
53pub struct AuditApiClient {
54    configuration: Arc<configuration::Configuration>,
55}
56
57impl AuditApiClient {
58    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
59        Self { configuration }
60    }
61}
62
63#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
64#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
65impl AuditApi for AuditApiClient {
66    async fn get_items<'a>(
67        &self,
68        org_id: uuid::Uuid,
69        start: Option<String>,
70        end: Option<String>,
71    ) -> Result<models::AccessAuditItemResponseModelListResponseModel, Error> {
72        let local_var_configuration = &self.configuration;
73
74        let local_var_client = &local_var_configuration.client;
75
76        let local_var_uri_str = format!(
77            "{}/organizations/{orgId}/audit/items",
78            local_var_configuration.base_path,
79            orgId = org_id
80        );
81        let mut local_var_req_builder =
82            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
83
84        if let Some(ref param_value) = start {
85            local_var_req_builder =
86                local_var_req_builder.query(&[("start", &param_value.to_string())]);
87        }
88        if let Some(ref param_value) = end {
89            local_var_req_builder =
90                local_var_req_builder.query(&[("end", &param_value.to_string())]);
91        }
92        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
93
94        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
95    }
96
97    async fn get_trail<'a>(
98        &self,
99        org_id: uuid::Uuid,
100        start: Option<String>,
101        end: Option<String>,
102        kind: Option<Vec<String>>,
103        actor_id: Option<Vec<uuid::Uuid>>,
104        include_automated_actor: Option<bool>,
105        requester_id: Option<Vec<uuid::Uuid>>,
106        cipher_id: Option<Vec<uuid::Uuid>>,
107        rule_id: Option<Vec<uuid::Uuid>>,
108        continuation_token: Option<&'a str>,
109    ) -> Result<models::AccessAuditEventResponseModelListResponseModel, Error> {
110        let local_var_configuration = &self.configuration;
111
112        let local_var_client = &local_var_configuration.client;
113
114        let local_var_uri_str = format!(
115            "{}/organizations/{orgId}/audit",
116            local_var_configuration.base_path,
117            orgId = org_id
118        );
119        let mut local_var_req_builder =
120            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
121
122        if let Some(ref param_value) = start {
123            local_var_req_builder =
124                local_var_req_builder.query(&[("start", &param_value.to_string())]);
125        }
126        if let Some(ref param_value) = end {
127            local_var_req_builder =
128                local_var_req_builder.query(&[("end", &param_value.to_string())]);
129        }
130        if let Some(ref param_value) = kind {
131            local_var_req_builder = match "multi" {
132                "multi" => local_var_req_builder.query(
133                    &param_value
134                        .into_iter()
135                        .map(|p| ("kind".to_owned(), p.to_string()))
136                        .collect::<Vec<(std::string::String, std::string::String)>>(),
137                ),
138                _ => local_var_req_builder.query(&[(
139                    "kind",
140                    &param_value
141                        .into_iter()
142                        .map(|p| p.to_string())
143                        .collect::<Vec<String>>()
144                        .join(",")
145                        .to_string(),
146                )]),
147            };
148        }
149        if let Some(ref param_value) = actor_id {
150            local_var_req_builder = match "multi" {
151                "multi" => local_var_req_builder.query(
152                    &param_value
153                        .into_iter()
154                        .map(|p| ("actorId".to_owned(), p.to_string()))
155                        .collect::<Vec<(std::string::String, std::string::String)>>(),
156                ),
157                _ => local_var_req_builder.query(&[(
158                    "actorId",
159                    &param_value
160                        .into_iter()
161                        .map(|p| p.to_string())
162                        .collect::<Vec<String>>()
163                        .join(",")
164                        .to_string(),
165                )]),
166            };
167        }
168        if let Some(ref param_value) = include_automated_actor {
169            local_var_req_builder =
170                local_var_req_builder.query(&[("includeAutomatedActor", &param_value.to_string())]);
171        }
172        if let Some(ref param_value) = requester_id {
173            local_var_req_builder = match "multi" {
174                "multi" => local_var_req_builder.query(
175                    &param_value
176                        .into_iter()
177                        .map(|p| ("requesterId".to_owned(), p.to_string()))
178                        .collect::<Vec<(std::string::String, std::string::String)>>(),
179                ),
180                _ => local_var_req_builder.query(&[(
181                    "requesterId",
182                    &param_value
183                        .into_iter()
184                        .map(|p| p.to_string())
185                        .collect::<Vec<String>>()
186                        .join(",")
187                        .to_string(),
188                )]),
189            };
190        }
191        if let Some(ref param_value) = cipher_id {
192            local_var_req_builder = match "multi" {
193                "multi" => local_var_req_builder.query(
194                    &param_value
195                        .into_iter()
196                        .map(|p| ("cipherId".to_owned(), p.to_string()))
197                        .collect::<Vec<(std::string::String, std::string::String)>>(),
198                ),
199                _ => local_var_req_builder.query(&[(
200                    "cipherId",
201                    &param_value
202                        .into_iter()
203                        .map(|p| p.to_string())
204                        .collect::<Vec<String>>()
205                        .join(",")
206                        .to_string(),
207                )]),
208            };
209        }
210        if let Some(ref param_value) = rule_id {
211            local_var_req_builder = match "multi" {
212                "multi" => local_var_req_builder.query(
213                    &param_value
214                        .into_iter()
215                        .map(|p| ("ruleId".to_owned(), p.to_string()))
216                        .collect::<Vec<(std::string::String, std::string::String)>>(),
217                ),
218                _ => local_var_req_builder.query(&[(
219                    "ruleId",
220                    &param_value
221                        .into_iter()
222                        .map(|p| p.to_string())
223                        .collect::<Vec<String>>()
224                        .join(",")
225                        .to_string(),
226                )]),
227            };
228        }
229        if let Some(ref param_value) = continuation_token {
230            local_var_req_builder =
231                local_var_req_builder.query(&[("continuationToken", &param_value.to_string())]);
232        }
233        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
234
235        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
236    }
237}