harbor_api/apis/
statistic_api.rs

1/*
2 * Harbor API
3 *
4 * These APIs provide services for manipulating Harbor project.
5 *
6 * The version of the OpenAPI document: 2.0
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/// struct for passing parameters to the method [`get_statistic`]
18#[derive(Clone, Debug)]
19pub struct GetStatisticParams {
20    /// An unique ID for the request
21    pub x_request_id: Option<String>
22}
23
24
25/// struct for typed errors of method [`get_statistic`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetStatisticError {
29    Status401(models::Errors),
30    Status500(models::Errors),
31    UnknownValue(serde_json::Value),
32}
33
34
35/// Get the statistic information about the projects and repositories
36pub async fn get_statistic(configuration: &configuration::Configuration, params: GetStatisticParams) -> Result<models::Statistic, Error<GetStatisticError>> {
37
38    let uri_str = format!("{}/statistics", configuration.base_path);
39    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
40
41    if let Some(ref user_agent) = configuration.user_agent {
42        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
43    }
44    if let Some(param_value) = params.x_request_id {
45        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
46    }
47    if let Some(ref auth_conf) = configuration.basic_auth {
48        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
49    };
50
51    let req = req_builder.build()?;
52    let resp = configuration.client.execute(req).await?;
53
54    let status = resp.status();
55    let content_type = resp
56        .headers()
57        .get("content-type")
58        .and_then(|v| v.to_str().ok())
59        .unwrap_or("application/octet-stream");
60    let content_type = super::ContentType::from(content_type);
61
62    if !status.is_client_error() && !status.is_server_error() {
63        let content = resp.text().await?;
64        match content_type {
65            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Statistic`"))),
67            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::Statistic`")))),
68        }
69    } else {
70        let content = resp.text().await?;
71        let entity: Option<GetStatisticError> = serde_json::from_str(&content).ok();
72        Err(Error::ResponseError(ResponseContent { status, content, entity }))
73    }
74}
75