Skip to main content

incus_client/apis/
images_api.rs

1/*
2 * Incus external REST API
3 *
4 * This is the REST API used by all Incus clients. Internal endpoints aren't included in this documentation.  The Incus API is available over both a local unix+http and remote https API. Authentication for local users relies on group membership and access to the unix socket. For remote users, the default authentication method is TLS client certificates.
5 *
6 * The version of the OpenAPI document: 1.0
7 * Contact: lxc-devel@lists.linuxcontainers.org
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
18/// struct for typed errors of method [`image_delete`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ImageDeleteError {
22    Status400(models::InstancesPut400Response),
23    Status403(models::InstancesGet403Response),
24    Status500(models::InstancesGet500Response),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`image_get`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum ImageGetError {
32    Status403(models::InstancesGet403Response),
33    Status500(models::InstancesGet500Response),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`image_patch`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum ImagePatchError {
41    Status400(models::InstancesPut400Response),
42    Status403(models::InstancesGet403Response),
43    Status412(models::InstanceMetadataPut412Response),
44    Status500(models::InstancesGet500Response),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`image_put`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum ImagePutError {
52    Status400(models::InstancesPut400Response),
53    Status403(models::InstancesGet403Response),
54    Status412(models::InstanceMetadataPut412Response),
55    Status500(models::InstancesGet500Response),
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`images_get`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum ImagesGetError {
63    Status403(models::InstancesGet403Response),
64    Status500(models::InstancesGet500Response),
65    UnknownValue(serde_json::Value),
66}
67
68
69/// Removes the image from the image store.
70pub async fn image_delete(configuration: &configuration::Configuration, fingerprint: &str, project: Option<&str>) -> Result<models::InstancesPut202Response, Error<ImageDeleteError>> {
71    // add a prefix to parameters to efficiently prevent name collisions
72    let p_path_fingerprint = fingerprint;
73    let p_query_project = project;
74
75    let uri_str = format!("{}/1.0/images/{fingerprint}", configuration.base_path, fingerprint=crate::apis::urlencode(p_path_fingerprint));
76    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
77
78    if let Some(ref param_value) = p_query_project {
79        req_builder = req_builder.query(&[("project", &param_value.to_string())]);
80    }
81    if let Some(ref user_agent) = configuration.user_agent {
82        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
83    }
84
85    let req = req_builder.build()?;
86    let resp = configuration.client.execute(req).await?;
87
88    let status = resp.status();
89    let content_type = resp
90        .headers()
91        .get("content-type")
92        .and_then(|v| v.to_str().ok())
93        .unwrap_or("application/octet-stream");
94    let content_type = super::ContentType::from(content_type);
95
96    if !status.is_client_error() && !status.is_server_error() {
97        let content = resp.text().await?;
98        match content_type {
99            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
100            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstancesPut202Response`"))),
101            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::InstancesPut202Response`")))),
102        }
103    } else {
104        let content = resp.text().await?;
105        let entity: Option<ImageDeleteError> = serde_json::from_str(&content).ok();
106        Err(Error::ResponseError(ResponseContent { status, content, entity }))
107    }
108}
109
110/// Gets a specific image.
111pub async fn image_get(configuration: &configuration::Configuration, fingerprint: &str, project: Option<&str>) -> Result<models::ImageGet200Response, Error<ImageGetError>> {
112    // add a prefix to parameters to efficiently prevent name collisions
113    let p_path_fingerprint = fingerprint;
114    let p_query_project = project;
115
116    let uri_str = format!("{}/1.0/images/{fingerprint}", configuration.base_path, fingerprint=crate::apis::urlencode(p_path_fingerprint));
117    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
118
119    if let Some(ref param_value) = p_query_project {
120        req_builder = req_builder.query(&[("project", &param_value.to_string())]);
121    }
122    if let Some(ref user_agent) = configuration.user_agent {
123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124    }
125
126    let req = req_builder.build()?;
127    let resp = configuration.client.execute(req).await?;
128
129    let status = resp.status();
130    let content_type = resp
131        .headers()
132        .get("content-type")
133        .and_then(|v| v.to_str().ok())
134        .unwrap_or("application/octet-stream");
135    let content_type = super::ContentType::from(content_type);
136
137    if !status.is_client_error() && !status.is_server_error() {
138        let content = resp.text().await?;
139        match content_type {
140            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
141            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImageGet200Response`"))),
142            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::ImageGet200Response`")))),
143        }
144    } else {
145        let content = resp.text().await?;
146        let entity: Option<ImageGetError> = serde_json::from_str(&content).ok();
147        Err(Error::ResponseError(ResponseContent { status, content, entity }))
148    }
149}
150
151/// Updates a subset of the image definition.
152pub async fn image_patch(configuration: &configuration::Configuration, fingerprint: &str, image: models::ImagePut, project: Option<&str>) -> Result<models::InstancePatch200Response, Error<ImagePatchError>> {
153    // add a prefix to parameters to efficiently prevent name collisions
154    let p_path_fingerprint = fingerprint;
155    let p_body_image = image;
156    let p_query_project = project;
157
158    let uri_str = format!("{}/1.0/images/{fingerprint}", configuration.base_path, fingerprint=crate::apis::urlencode(p_path_fingerprint));
159    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
160
161    if let Some(ref param_value) = p_query_project {
162        req_builder = req_builder.query(&[("project", &param_value.to_string())]);
163    }
164    if let Some(ref user_agent) = configuration.user_agent {
165        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
166    }
167    req_builder = req_builder.json(&p_body_image);
168
169    let req = req_builder.build()?;
170    let resp = configuration.client.execute(req).await?;
171
172    let status = resp.status();
173    let content_type = resp
174        .headers()
175        .get("content-type")
176        .and_then(|v| v.to_str().ok())
177        .unwrap_or("application/octet-stream");
178    let content_type = super::ContentType::from(content_type);
179
180    if !status.is_client_error() && !status.is_server_error() {
181        let content = resp.text().await?;
182        match content_type {
183            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
184            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstancePatch200Response`"))),
185            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::InstancePatch200Response`")))),
186        }
187    } else {
188        let content = resp.text().await?;
189        let entity: Option<ImagePatchError> = serde_json::from_str(&content).ok();
190        Err(Error::ResponseError(ResponseContent { status, content, entity }))
191    }
192}
193
194/// Updates the entire image definition.
195pub async fn image_put(configuration: &configuration::Configuration, fingerprint: &str, image: models::ImagePut, project: Option<&str>) -> Result<models::InstancePatch200Response, Error<ImagePutError>> {
196    // add a prefix to parameters to efficiently prevent name collisions
197    let p_path_fingerprint = fingerprint;
198    let p_body_image = image;
199    let p_query_project = project;
200
201    let uri_str = format!("{}/1.0/images/{fingerprint}", configuration.base_path, fingerprint=crate::apis::urlencode(p_path_fingerprint));
202    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
203
204    if let Some(ref param_value) = p_query_project {
205        req_builder = req_builder.query(&[("project", &param_value.to_string())]);
206    }
207    if let Some(ref user_agent) = configuration.user_agent {
208        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
209    }
210    req_builder = req_builder.json(&p_body_image);
211
212    let req = req_builder.build()?;
213    let resp = configuration.client.execute(req).await?;
214
215    let status = resp.status();
216    let content_type = resp
217        .headers()
218        .get("content-type")
219        .and_then(|v| v.to_str().ok())
220        .unwrap_or("application/octet-stream");
221    let content_type = super::ContentType::from(content_type);
222
223    if !status.is_client_error() && !status.is_server_error() {
224        let content = resp.text().await?;
225        match content_type {
226            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
227            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InstancePatch200Response`"))),
228            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::InstancePatch200Response`")))),
229        }
230    } else {
231        let content = resp.text().await?;
232        let entity: Option<ImagePutError> = serde_json::from_str(&content).ok();
233        Err(Error::ResponseError(ResponseContent { status, content, entity }))
234    }
235}
236
237/// Returns a list of images (URLs).
238pub async fn images_get(configuration: &configuration::Configuration, project: Option<&str>, filter: Option<&str>, all_projects: Option<bool>) -> Result<models::ImagesGet200Response, Error<ImagesGetError>> {
239    // add a prefix to parameters to efficiently prevent name collisions
240    let p_query_project = project;
241    let p_query_filter = filter;
242    let p_query_all_projects = all_projects;
243
244    let uri_str = format!("{}/1.0/images", configuration.base_path);
245    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
246
247    if let Some(ref param_value) = p_query_project {
248        req_builder = req_builder.query(&[("project", &param_value.to_string())]);
249    }
250    if let Some(ref param_value) = p_query_filter {
251        req_builder = req_builder.query(&[("filter", &param_value.to_string())]);
252    }
253    if let Some(ref param_value) = p_query_all_projects {
254        req_builder = req_builder.query(&[("all-projects", &param_value.to_string())]);
255    }
256    if let Some(ref user_agent) = configuration.user_agent {
257        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
258    }
259
260    let req = req_builder.build()?;
261    let resp = configuration.client.execute(req).await?;
262
263    let status = resp.status();
264    let content_type = resp
265        .headers()
266        .get("content-type")
267        .and_then(|v| v.to_str().ok())
268        .unwrap_or("application/octet-stream");
269    let content_type = super::ContentType::from(content_type);
270
271    if !status.is_client_error() && !status.is_server_error() {
272        let content = resp.text().await?;
273        match content_type {
274            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
275            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImagesGet200Response`"))),
276            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::ImagesGet200Response`")))),
277        }
278    } else {
279        let content = resp.text().await?;
280        let entity: Option<ImagesGetError> = serde_json::from_str(&content).ok();
281        Err(Error::ResponseError(ResponseContent { status, content, entity }))
282    }
283}
284