harbor_api/apis/
ping_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_ping`]
18#[derive(Clone, Debug)]
19pub struct GetPingParams {
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_ping`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetPingError {
29    UnknownValue(serde_json::Value),
30}
31
32
33/// This API simply replies a pong to indicate the process to handle API is up, disregarding the health status of dependent components. This path does not require any authentication.
34pub async fn get_ping(configuration: &configuration::Configuration, params: GetPingParams) -> Result<String, Error<GetPingError>> {
35
36    let uri_str = format!("{}/ping", configuration.base_path);
37    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
38
39    if let Some(ref user_agent) = configuration.user_agent {
40        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
41    }
42    if let Some(param_value) = params.x_request_id {
43        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
44    }
45    if let Some(ref auth_conf) = configuration.basic_auth {
46        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
47    };
48
49    let req = req_builder.build()?;
50    let resp = configuration.client.execute(req).await?;
51
52    let status = resp.status();
53    let content_type = resp
54        .headers()
55        .get("content-type")
56        .and_then(|v| v.to_str().ok())
57        .unwrap_or("application/octet-stream");
58    let content_type = super::ContentType::from(content_type);
59
60    if !status.is_client_error() && !status.is_server_error() {
61        let content = resp.text().await?;
62        match content_type {
63            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
64            ContentType::Text => return Ok(content),
65            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
66        }
67    } else {
68        let content = resp.text().await?;
69        let entity: Option<GetPingError> = serde_json::from_str(&content).ok();
70        Err(Error::ResponseError(ResponseContent { status, content, entity }))
71    }
72}
73