harbor_api/apis/
icon_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct GetIconParams {
20 pub digest: String,
22 pub x_request_id: Option<String>
24}
25
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetIconError {
31 Status400(models::Errors),
32 Status404(models::Errors),
33 Status500(models::Errors),
34 UnknownValue(serde_json::Value),
35}
36
37
38pub async fn get_icon(configuration: &configuration::Configuration, params: GetIconParams) -> Result<models::Icon, Error<GetIconError>> {
40
41 let uri_str = format!("{}/icons/{digest}", configuration.base_path, digest=crate::apis::urlencode(params.digest));
42 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
43
44 if let Some(ref user_agent) = configuration.user_agent {
45 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
46 }
47 if let Some(param_value) = params.x_request_id {
48 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
49 }
50 if let Some(ref auth_conf) = configuration.basic_auth {
51 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
52 };
53
54 let req = req_builder.build()?;
55 let resp = configuration.client.execute(req).await?;
56
57 let status = resp.status();
58 let content_type = resp
59 .headers()
60 .get("content-type")
61 .and_then(|v| v.to_str().ok())
62 .unwrap_or("application/octet-stream");
63 let content_type = super::ContentType::from(content_type);
64
65 if !status.is_client_error() && !status.is_server_error() {
66 let content = resp.text().await?;
67 match content_type {
68 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Icon`"))),
70 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::Icon`")))),
71 }
72 } else {
73 let content = resp.text().await?;
74 let entity: Option<GetIconError> = serde_json::from_str(&content).ok();
75 Err(Error::ResponseError(ResponseContent { status, content, entity }))
76 }
77}
78