bitwarden_api_api/apis/
secrets_manager_events_api.rs1use 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 SecretsManagerEventsApi: Send + Sync {
29 async fn get_service_account_events<'a>(
31 &self,
32 service_account_id: uuid::Uuid,
33 start: Option<String>,
34 end: Option<String>,
35 continuation_token: Option<&'a str>,
36 ) -> Result<models::EventResponseModelListResponseModel, Error<GetServiceAccountEventsError>>;
37}
38
39pub struct SecretsManagerEventsApiClient {
40 configuration: Arc<configuration::Configuration>,
41}
42
43impl SecretsManagerEventsApiClient {
44 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
45 Self { configuration }
46 }
47}
48
49#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
50#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
51impl SecretsManagerEventsApi for SecretsManagerEventsApiClient {
52 async fn get_service_account_events<'a>(
53 &self,
54 service_account_id: uuid::Uuid,
55 start: Option<String>,
56 end: Option<String>,
57 continuation_token: Option<&'a str>,
58 ) -> Result<models::EventResponseModelListResponseModel, Error<GetServiceAccountEventsError>>
59 {
60 let local_var_configuration = &self.configuration;
61
62 let local_var_client = &local_var_configuration.client;
63
64 let local_var_uri_str = format!(
65 "{}/sm/events/service-accounts/{serviceAccountId}",
66 local_var_configuration.base_path,
67 serviceAccountId = service_account_id
68 );
69 let mut local_var_req_builder =
70 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
71
72 if let Some(ref param_value) = start {
73 local_var_req_builder =
74 local_var_req_builder.query(&[("start", ¶m_value.to_string())]);
75 }
76 if let Some(ref param_value) = end {
77 local_var_req_builder =
78 local_var_req_builder.query(&[("end", ¶m_value.to_string())]);
79 }
80 if let Some(ref param_value) = continuation_token {
81 local_var_req_builder =
82 local_var_req_builder.query(&[("continuationToken", ¶m_value.to_string())]);
83 }
84 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
85
86 let local_var_resp = local_var_req_builder.send().await?;
87
88 let local_var_status = local_var_resp.status();
89 let local_var_content_type = local_var_resp
90 .headers()
91 .get("content-type")
92 .and_then(|v| v.to_str().ok())
93 .unwrap_or("application/octet-stream");
94 let local_var_content_type = super::ContentType::from(local_var_content_type);
95 let local_var_content = local_var_resp.text().await?;
96
97 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
98 match local_var_content_type {
99 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
100 ContentType::Text => {
101 return Err(Error::from(serde_json::Error::custom(
102 "Received `text/plain` content type response that cannot be converted to `models::EventResponseModelListResponseModel`",
103 )));
104 }
105 ContentType::Unsupported(local_var_unknown_type) => {
106 return Err(Error::from(serde_json::Error::custom(format!(
107 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::EventResponseModelListResponseModel`"
108 ))));
109 }
110 }
111 } else {
112 let local_var_entity: Option<GetServiceAccountEventsError> =
113 serde_json::from_str(&local_var_content).ok();
114 let local_var_error = ResponseContent {
115 status: local_var_status,
116 content: local_var_content,
117 entity: local_var_entity,
118 };
119 Err(Error::ResponseError(local_var_error))
120 }
121 }
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
126#[serde(untagged)]
127pub enum GetServiceAccountEventsError {
128 UnknownValue(serde_json::Value),
129}