harbor_api/apis/
configure_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_configurations`]
18#[derive(Clone, Debug)]
19pub struct GetConfigurationsParams {
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_internalconfig`]
25#[derive(Clone, Debug)]
26pub struct GetInternalconfigParams {
27    /// An unique ID for the request
28    pub x_request_id: Option<String>
29}
30
31/// struct for passing parameters to the method [`update_configurations`]
32#[derive(Clone, Debug)]
33pub struct UpdateConfigurationsParams {
34    /// The configuration map can contain a subset of the attributes of the schema, which are to be updated.
35    pub configurations: models::Configurations,
36    /// An unique ID for the request
37    pub x_request_id: Option<String>
38}
39
40
41/// struct for typed errors of method [`get_configurations`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum GetConfigurationsError {
45    Status401(),
46    Status403(),
47    Status500(),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`get_internalconfig`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum GetInternalconfigError {
55    Status401(),
56    Status403(),
57    Status500(),
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`update_configurations`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum UpdateConfigurationsError {
65    Status401(),
66    Status403(),
67    Status500(),
68    UnknownValue(serde_json::Value),
69}
70
71
72/// This endpoint is for retrieving system configurations that only provides for admin user. 
73pub async fn get_configurations(configuration: &configuration::Configuration, params: GetConfigurationsParams) -> Result<models::ConfigurationsResponse, Error<GetConfigurationsError>> {
74
75    let uri_str = format!("{}/configurations", configuration.base_path);
76    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
77
78    if let Some(ref user_agent) = configuration.user_agent {
79        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
80    }
81    if let Some(param_value) = params.x_request_id {
82        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
83    }
84    if let Some(ref auth_conf) = configuration.basic_auth {
85        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
86    };
87
88    let req = req_builder.build()?;
89    let resp = configuration.client.execute(req).await?;
90
91    let status = resp.status();
92    let content_type = resp
93        .headers()
94        .get("content-type")
95        .and_then(|v| v.to_str().ok())
96        .unwrap_or("application/octet-stream");
97    let content_type = super::ContentType::from(content_type);
98
99    if !status.is_client_error() && !status.is_server_error() {
100        let content = resp.text().await?;
101        match content_type {
102            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
103            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigurationsResponse`"))),
104            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::ConfigurationsResponse`")))),
105        }
106    } else {
107        let content = resp.text().await?;
108        let entity: Option<GetConfigurationsError> = serde_json::from_str(&content).ok();
109        Err(Error::ResponseError(ResponseContent { status, content, entity }))
110    }
111}
112
113/// This endpoint is for retrieving system configurations that only provides for internal api call. 
114pub async fn get_internalconfig(configuration: &configuration::Configuration, params: GetInternalconfigParams) -> Result<std::collections::HashMap<String, models::InternalConfigurationValue>, Error<GetInternalconfigError>> {
115
116    let uri_str = format!("{}/internalconfig", configuration.base_path);
117    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
118
119    if let Some(ref user_agent) = configuration.user_agent {
120        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
121    }
122    if let Some(param_value) = params.x_request_id {
123        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
124    }
125    if let Some(ref auth_conf) = configuration.basic_auth {
126        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
127    };
128
129    let req = req_builder.build()?;
130    let resp = configuration.client.execute(req).await?;
131
132    let status = resp.status();
133    let content_type = resp
134        .headers()
135        .get("content-type")
136        .and_then(|v| v.to_str().ok())
137        .unwrap_or("application/octet-stream");
138    let content_type = super::ContentType::from(content_type);
139
140    if !status.is_client_error() && !status.is_server_error() {
141        let content = resp.text().await?;
142        match content_type {
143            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
144            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap&lt;String, models::InternalConfigurationValue&gt;`"))),
145            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap&lt;String, models::InternalConfigurationValue&gt;`")))),
146        }
147    } else {
148        let content = resp.text().await?;
149        let entity: Option<GetInternalconfigError> = serde_json::from_str(&content).ok();
150        Err(Error::ResponseError(ResponseContent { status, content, entity }))
151    }
152}
153
154/// This endpoint is for modifying system configurations that only provides for admin user. 
155pub async fn update_configurations(configuration: &configuration::Configuration, params: UpdateConfigurationsParams) -> Result<(), Error<UpdateConfigurationsError>> {
156
157    let uri_str = format!("{}/configurations", configuration.base_path);
158    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
159
160    if let Some(ref user_agent) = configuration.user_agent {
161        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
162    }
163    if let Some(param_value) = params.x_request_id {
164        req_builder = req_builder.header("X-Request-Id", param_value.to_string());
165    }
166    if let Some(ref auth_conf) = configuration.basic_auth {
167        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
168    };
169    req_builder = req_builder.json(&params.configurations);
170
171    let req = req_builder.build()?;
172    let resp = configuration.client.execute(req).await?;
173
174    let status = resp.status();
175
176    if !status.is_client_error() && !status.is_server_error() {
177        Ok(())
178    } else {
179        let content = resp.text().await?;
180        let entity: Option<UpdateConfigurationsError> = serde_json::from_str(&content).ok();
181        Err(Error::ResponseError(ResponseContent { status, content, entity }))
182    }
183}
184