bitwarden_api_api/apis/
secrets_manager_events_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::{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    /// GET /sm/events/service-accounts/{serviceAccountId}
30    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", &param_value.to_string())]);
75        }
76        if let Some(ref param_value) = end {
77            local_var_req_builder =
78                local_var_req_builder.query(&[("end", &param_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", &param_value.to_string())]);
83        }
84        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
85            local_var_req_builder = local_var_req_builder
86                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
87        }
88        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
89            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
90        };
91
92        let local_var_req = local_var_req_builder.build()?;
93        let local_var_resp = local_var_client.execute(local_var_req).await?;
94
95        let local_var_status = local_var_resp.status();
96        let local_var_content_type = local_var_resp
97            .headers()
98            .get("content-type")
99            .and_then(|v| v.to_str().ok())
100            .unwrap_or("application/octet-stream");
101        let local_var_content_type = super::ContentType::from(local_var_content_type);
102        let local_var_content = local_var_resp.text().await?;
103
104        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
105            match local_var_content_type {
106                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
107                ContentType::Text => {
108                    return Err(Error::from(serde_json::Error::custom(
109                        "Received `text/plain` content type response that cannot be converted to `models::EventResponseModelListResponseModel`",
110                    )));
111                }
112                ContentType::Unsupported(local_var_unknown_type) => {
113                    return Err(Error::from(serde_json::Error::custom(format!(
114                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::EventResponseModelListResponseModel`"
115                    ))));
116                }
117            }
118        } else {
119            let local_var_entity: Option<GetServiceAccountEventsError> =
120                serde_json::from_str(&local_var_content).ok();
121            let local_var_error = ResponseContent {
122                status: local_var_status,
123                content: local_var_content,
124                entity: local_var_entity,
125            };
126            Err(Error::ResponseError(local_var_error))
127        }
128    }
129}
130
131/// struct for typed errors of method [`SecretsManagerEventsApi::get_service_account_events`]
132#[derive(Debug, Clone, Serialize, Deserialize)]
133#[serde(untagged)]
134pub enum GetServiceAccountEventsError {
135    UnknownValue(serde_json::Value),
136}