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 reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`sm_events_service_accounts_service_account_id_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum SmEventsServiceAccountsServiceAccountIdGetError {
21    UnknownValue(serde_json::Value),
22}
23
24pub async fn sm_events_service_accounts_service_account_id_get(
25    configuration: &configuration::Configuration,
26    service_account_id: uuid::Uuid,
27    start: Option<String>,
28    end: Option<String>,
29    continuation_token: Option<&str>,
30) -> Result<
31    models::EventResponseModelListResponseModel,
32    Error<SmEventsServiceAccountsServiceAccountIdGetError>,
33> {
34    // add a prefix to parameters to efficiently prevent name collisions
35    let p_service_account_id = service_account_id;
36    let p_start = start;
37    let p_end = end;
38    let p_continuation_token = continuation_token;
39
40    let uri_str = format!(
41        "{}/sm/events/service-accounts/{serviceAccountId}",
42        configuration.base_path,
43        serviceAccountId = crate::apis::urlencode(p_service_account_id.to_string())
44    );
45    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
46
47    if let Some(ref param_value) = p_start {
48        req_builder = req_builder.query(&[("start", &param_value.to_string())]);
49    }
50    if let Some(ref param_value) = p_end {
51        req_builder = req_builder.query(&[("end", &param_value.to_string())]);
52    }
53    if let Some(ref param_value) = p_continuation_token {
54        req_builder = req_builder.query(&[("continuationToken", &param_value.to_string())]);
55    }
56    if let Some(ref user_agent) = configuration.user_agent {
57        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58    }
59    if let Some(ref token) = configuration.oauth_access_token {
60        req_builder = req_builder.bearer_auth(token.to_owned());
61    };
62
63    let req = req_builder.build()?;
64    let resp = configuration.client.execute(req).await?;
65
66    let status = resp.status();
67    let content_type = resp
68        .headers()
69        .get("content-type")
70        .and_then(|v| v.to_str().ok())
71        .unwrap_or("application/octet-stream");
72    let content_type = super::ContentType::from(content_type);
73
74    if !status.is_client_error() && !status.is_server_error() {
75        let content = resp.text().await?;
76        match content_type {
77            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
78            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EventResponseModelListResponseModel`"))),
79            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::EventResponseModelListResponseModel`")))),
80        }
81    } else {
82        let content = resp.text().await?;
83        let entity: Option<SmEventsServiceAccountsServiceAccountIdGetError> =
84            serde_json::from_str(&content).ok();
85        Err(Error::ResponseError(ResponseContent {
86            status,
87            content,
88            entity,
89        }))
90    }
91}