Skip to main content

hanzo_client/apis/
audit_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`get_audit`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAuditError {
22    UnknownValue(serde_json::Value),
23}
24
25
26/// List reads the caller's OWN org audit trail, newest first, with the total the filter matched so a console can page it.  Every filter is optional and applies WITHIN the caller's org — the org itself is the validated principal's and can never be widened by a request. Fails closed: an absent principal is a true \"not signed in\" (401), and a deployment with no local tamper-evident store answers an honest 501 rather than silently serving somebody else's trail.
27pub async fn get_audit(configuration: &configuration::Configuration, sub: Option<&str>, action: Option<&str>, resource: Option<&str>, resource_id: Option<&str>, result: Option<&str>, since: Option<&str>, until: Option<&str>, page_size: Option<&str>, p: Option<&str>) -> Result<models::TrailPage, Error<GetAuditError>> {
28    // add a prefix to parameters to efficiently prevent name collisions
29    let p_sub = sub;
30    let p_action = action;
31    let p_resource = resource;
32    let p_resource_id = resource_id;
33    let p_result = result;
34    let p_since = since;
35    let p_until = until;
36    let p_page_size = page_size;
37    let p_p = p;
38
39    let uri_str = format!("{}/v1/audit", configuration.base_path);
40    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
41
42    if let Some(ref param_value) = p_sub {
43        req_builder = req_builder.query(&[("sub", &param_value.to_string())]);
44    }
45    if let Some(ref param_value) = p_action {
46        req_builder = req_builder.query(&[("action", &param_value.to_string())]);
47    }
48    if let Some(ref param_value) = p_resource {
49        req_builder = req_builder.query(&[("resource", &param_value.to_string())]);
50    }
51    if let Some(ref param_value) = p_resource_id {
52        req_builder = req_builder.query(&[("resourceId", &param_value.to_string())]);
53    }
54    if let Some(ref param_value) = p_result {
55        req_builder = req_builder.query(&[("result", &param_value.to_string())]);
56    }
57    if let Some(ref param_value) = p_since {
58        req_builder = req_builder.query(&[("since", &param_value.to_string())]);
59    }
60    if let Some(ref param_value) = p_until {
61        req_builder = req_builder.query(&[("until", &param_value.to_string())]);
62    }
63    if let Some(ref param_value) = p_page_size {
64        req_builder = req_builder.query(&[("pageSize", &param_value.to_string())]);
65    }
66    if let Some(ref param_value) = p_p {
67        req_builder = req_builder.query(&[("p", &param_value.to_string())]);
68    }
69    if let Some(ref user_agent) = configuration.user_agent {
70        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71    }
72    if let Some(ref token) = configuration.bearer_access_token {
73        req_builder = req_builder.bearer_auth(token.to_owned());
74    };
75
76    let req = req_builder.build()?;
77    let resp = configuration.client.execute(req).await?;
78
79    let status = resp.status();
80    let content_type = resp
81        .headers()
82        .get("content-type")
83        .and_then(|v| v.to_str().ok())
84        .unwrap_or("application/octet-stream");
85    let content_type = super::ContentType::from(content_type);
86
87    if !status.is_client_error() && !status.is_server_error() {
88        let content = resp.text().await?;
89        match content_type {
90            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
91            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TrailPage`"))),
92            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::TrailPage`")))),
93        }
94    } else {
95        let content = resp.text().await?;
96        let entity: Option<GetAuditError> = serde_json::from_str(&content).ok();
97        Err(Error::ResponseError(ResponseContent { status, content, entity }))
98    }
99}
100