harbor_api/apis/
systeminfo_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_cert`]
18#[derive(Clone, Debug)]
19pub struct GetCertParams {
20    /// An unique ID for the request
21    pub x_request_id: Option<String>
22}
23
24/// struct for passing parameters to the method [`get_system_info`]
25#[derive(Clone, Debug)]
26pub struct GetSystemInfoParams {
27    /// An unique ID for the request
28    pub x_request_id: Option<String>
29}
30
31/// struct for passing parameters to the method [`get_volumes`]
32#[derive(Clone, Debug)]
33pub struct GetVolumesParams {
34    /// An unique ID for the request
35    pub x_request_id: Option<String>
36}
37
38
39/// struct for typed errors of method [`get_cert`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetCertError {
43    Status404(),
44    Status500(models::Errors),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`get_system_info`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetSystemInfoError {
52    Status500(models::Errors),
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed errors of method [`get_volumes`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum GetVolumesError {
60    Status401(models::Errors),
61    Status403(models::Errors),
62    Status404(models::Errors),
63    Status500(models::Errors),
64    UnknownValue(serde_json::Value),
65}
66
67
68/// This endpoint is for downloading a default root certificate. 
69pub async fn get_cert(configuration: &configuration::Configuration, params: GetCertParams) -> Result<reqwest::Response, Error<GetCertError>> {
70
71    let uri_str = format!("{}/systeminfo/getcert", configuration.base_path);
72    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
73
74    if let Some(ref user_agent) = configuration.user_agent {
75        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76    }
77    if let Some(param_value) = params.x_request_id {
78        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
79    }
80    if let Some(ref auth_conf) = configuration.basic_auth {
81        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
82    };
83
84    let req = req_builder.build()?;
85    let resp = configuration.client.execute(req).await?;
86
87    let status = resp.status();
88
89    if !status.is_client_error() && !status.is_server_error() {
90        Ok(resp)
91    } else {
92        let content = resp.text().await?;
93        let entity: Option<GetCertError> = serde_json::from_str(&content).ok();
94        Err(Error::ResponseError(ResponseContent { status, content, entity }))
95    }
96}
97
98/// This API is for retrieving general system info, this can be called by anonymous request.  Some attributes will be omitted in the response when this API is called by anonymous request. 
99pub async fn get_system_info(configuration: &configuration::Configuration, params: GetSystemInfoParams) -> Result<models::GeneralInfo, Error<GetSystemInfoError>> {
100
101    let uri_str = format!("{}/systeminfo", configuration.base_path);
102    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
103
104    if let Some(ref user_agent) = configuration.user_agent {
105        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
106    }
107    if let Some(param_value) = params.x_request_id {
108        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
109    }
110    if let Some(ref auth_conf) = configuration.basic_auth {
111        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
112    };
113
114    let req = req_builder.build()?;
115    let resp = configuration.client.execute(req).await?;
116
117    let status = resp.status();
118    let content_type = resp
119        .headers()
120        .get("content-type")
121        .and_then(|v| v.to_str().ok())
122        .unwrap_or("application/octet-stream");
123    let content_type = super::ContentType::from(content_type);
124
125    if !status.is_client_error() && !status.is_server_error() {
126        let content = resp.text().await?;
127        match content_type {
128            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
129            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GeneralInfo`"))),
130            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::GeneralInfo`")))),
131        }
132    } else {
133        let content = resp.text().await?;
134        let entity: Option<GetSystemInfoError> = serde_json::from_str(&content).ok();
135        Err(Error::ResponseError(ResponseContent { status, content, entity }))
136    }
137}
138
139/// This endpoint is for retrieving system volume info that only provides for admin user.  Note that the response only reflects the storage status of local disk. 
140pub async fn get_volumes(configuration: &configuration::Configuration, params: GetVolumesParams) -> Result<models::SystemInfo, Error<GetVolumesError>> {
141
142    let uri_str = format!("{}/systeminfo/volumes", configuration.base_path);
143    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
144
145    if let Some(ref user_agent) = configuration.user_agent {
146        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147    }
148    if let Some(param_value) = params.x_request_id {
149        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
150    }
151    if let Some(ref auth_conf) = configuration.basic_auth {
152        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
153    };
154
155    let req = req_builder.build()?;
156    let resp = configuration.client.execute(req).await?;
157
158    let status = resp.status();
159    let content_type = resp
160        .headers()
161        .get("content-type")
162        .and_then(|v| v.to_str().ok())
163        .unwrap_or("application/octet-stream");
164    let content_type = super::ContentType::from(content_type);
165
166    if !status.is_client_error() && !status.is_server_error() {
167        let content = resp.text().await?;
168        match content_type {
169            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
170            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SystemInfo`"))),
171            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::SystemInfo`")))),
172        }
173    } else {
174        let content = resp.text().await?;
175        let entity: Option<GetVolumesError> = serde_json::from_str(&content).ok();
176        Err(Error::ResponseError(ResponseContent { status, content, entity }))
177    }
178}
179