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 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
85 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
86 };
87 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
88
89 let local_var_req = local_var_req_builder.build()?;
90 let local_var_resp = local_var_client.execute(local_var_req).await?;
91
92 let local_var_status = local_var_resp.status();
93 let local_var_content_type = local_var_resp
94 .headers()
95 .get("content-type")
96 .and_then(|v| v.to_str().ok())
97 .unwrap_or("application/octet-stream");
98 let local_var_content_type = super::ContentType::from(local_var_content_type);
99 let local_var_content = local_var_resp.text().await?;
100
101 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
102 match local_var_content_type {
103 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
104 ContentType::Text => {
105 return Err(Error::from(serde_json::Error::custom(
106 "Received `text/plain` content type response that cannot be converted to `models::EventResponseModelListResponseModel`",
107 )));
108 }
109 ContentType::Unsupported(local_var_unknown_type) => {
110 return Err(Error::from(serde_json::Error::custom(format!(
111 "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::EventResponseModelListResponseModel`"
112 ))));
113 }
114 }
115 } else {
116 let local_var_entity: Option<GetServiceAccountEventsError> =
117 serde_json::from_str(&local_var_content).ok();
118 let local_var_error = ResponseContent {
119 status: local_var_status,
120 content: local_var_content,
121 entity: local_var_entity,
122 };
123 Err(Error::ResponseError(local_var_error))
124 }
125 }
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize)]
130#[serde(untagged)]
131pub enum GetServiceAccountEventsError {
132 UnknownValue(serde_json::Value),
133}