outscale_api/apis/
image_api.rs

1/*
2 * 3DS OUTSCALE API
3 *
4 * Welcome to the OUTSCALE API documentation.<br /> The OUTSCALE API enables you to manage your resources in the OUTSCALE Cloud. This documentation describes the different actions available along with code examples.<br /><br /> Throttling: To protect against overloads, the number of identical requests allowed in a given time period is limited.<br /> Brute force: To protect against brute force attacks, the number of failed authentication attempts in a given time period is limited.<br /><br /> Note that the OUTSCALE Cloud is compatible with Amazon Web Services (AWS) APIs, but there are [differences in resource names](https://docs.outscale.com/en/userguide/About-the-APIs.html) between AWS and the OUTSCALE API.<br /> You can also manage your resources using the [Cockpit](https://docs.outscale.com/en/userguide/About-Cockpit.html) web interface.<br /><br /> An OpenAPI description of the OUTSCALE API is also available in this [GitHub repository](https://github.com/outscale/osc-api).<br /> # Authentication Schemes ### Access Key/Secret Key The main way to authenticate your requests to the OUTSCALE API is to use an access key and a secret key.<br /> The mechanism behind this is based on AWS Signature Version 4, whose technical implementation details are described in [Signature of API Requests](https://docs.outscale.com/en/userguide/Signature-of-API-Requests.html).<br /><br /> In practice, the way to specify your access key and secret key depends on the tool or SDK you want to use to interact with the API.<br />  > For example, if you use OSC CLI: > 1. You need to create an **~/.osc/config.json** file to specify your access key, secret key, and the Region of your account. > 2. You then specify the `--profile` option when executing OSC CLI commands. > > For more information, see [Installing and Configuring OSC CLI](https://docs.outscale.com/en/userguide/Installing-and-Configuring-OSC-CLI.html).  See the code samples in each section of this documentation for specific examples in different programming languages.<br /> For more information about access keys, see [About Access Keys](https://docs.outscale.com/en/userguide/About-Access-Keys.html).  > If you try to sign requests with an invalid access key four times in a row, further authentication attempts will be prevented for 1 minute. This lockout time increases 1 minute every four failed attempts, for up to 10 minutes.  ### Login/Password For certain API actions, you can also use basic authentication with the login (email address) and password of your TINA account.<br /> This is useful only in special circumstances, for example if you do not know your access key/secret key and want to retrieve them programmatically.<br /> In most cases, however, you can use the Cockpit web interface to retrieve them.<br />  > For example, if you use OSC CLI: > 1. You need to create an **~/.osc/config.json** file to specify the Region of your account, but you leave the access key value and secret key value empty (`&quot;&quot;`). > 2. You then specify the `--profile`, `--authentication-method`, `--login`, and `--password` options when executing OSC CLI commands.  See the code samples in each section of this documentation for specific examples in different programming languages.  > If you try to sign requests with an invalid password four times in a row, further authentication attempts will be prevented for 1 minute. This lockout time increases 1 minute every four failed attempts, for up to 10 minutes.  ### No Authentication A few API actions do not require any authentication. They are indicated as such in this documentation.<br /> ### Other Security Mechanisms In parallel with the authentication schemes, you can add other security mechanisms to your OUTSCALE account, for example to restrict API requests by IP or other criteria.<br /> For more information, see [Managing Your API Accesses](https://docs.outscale.com/en/userguide/Managing-Your-API-Accesses.html). # Pagination Tutorial You can learn more about the pagination methods for read calls in the dedicated [pagination tutorial](https://docs.outscale.com/en/userguide/Tutorial-Paginating-an-API-Request.html). # Error Codes Reference You can learn more about errors returned by the API in the dedicated [errors page](api-errors.html).
5 *
6 * The version of the OpenAPI document: 1.35.3
7 * Contact: support@outscale.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{configuration, Error};
14use crate::apis::ResponseContent;
15
16/// struct for typed errors of method [`create_image`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateImageError {
20    Status400(crate::models::ErrorResponse),
21    Status401(crate::models::ErrorResponse),
22    Status500(crate::models::ErrorResponse),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`create_image_export_task`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum CreateImageExportTaskError {
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`delete_image`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum DeleteImageError {
37    Status400(crate::models::ErrorResponse),
38    Status401(crate::models::ErrorResponse),
39    Status500(crate::models::ErrorResponse),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`read_image_export_tasks`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum ReadImageExportTasksError {
47    UnknownValue(serde_json::Value),
48}
49
50/// struct for typed errors of method [`read_images`]
51#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum ReadImagesError {
54    Status400(crate::models::ErrorResponse),
55    Status401(crate::models::ErrorResponse),
56    Status500(crate::models::ErrorResponse),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`update_image`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum UpdateImageError {
64    Status400(crate::models::ErrorResponse),
65    Status401(crate::models::ErrorResponse),
66    Status500(crate::models::ErrorResponse),
67    UnknownValue(serde_json::Value),
68}
69
70pub fn create_image(
71    configuration: &configuration::Configuration,
72    create_image_request: Option<crate::models::CreateImageRequest>,
73) -> Result<crate::models::CreateImageResponse, Error<CreateImageError>> {
74    let local_var_configuration = configuration;
75
76    let local_var_client = &local_var_configuration.client;
77
78    let local_var_uri_str = format!("{}/CreateImage", local_var_configuration.base_path);
79    let mut local_var_req_builder =
80        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
81
82    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
83        let local_var_new_headers = match local_var_aws_v4_key.sign(
84            &local_var_uri_str,
85            "POST",
86            &serde_json::to_string(&create_image_request)
87                .expect("param should serialize to string"),
88        ) {
89            Ok(new_headers) => new_headers,
90            Err(err) => return Err(Error::AWSV4SignatureError(err)),
91        };
92        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
93            local_var_req_builder =
94                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
95        }
96    }
97    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
98        local_var_req_builder =
99            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100    }
101    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
102        let local_var_key = local_var_apikey.key.clone();
103        let local_var_value = match local_var_apikey.prefix {
104            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
105            None => local_var_key,
106        };
107        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
108    };
109    local_var_req_builder = local_var_req_builder.json(&create_image_request);
110
111    let local_var_req = local_var_req_builder.build()?;
112    let mut local_var_resp = local_var_client.execute(local_var_req)?;
113
114    let local_var_status = local_var_resp.status();
115    let local_var_content = local_var_resp.text()?;
116
117    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118        serde_json::from_str(&local_var_content).map_err(Error::from)
119    } else {
120        let local_var_entity: Option<CreateImageError> =
121            serde_json::from_str(&local_var_content).ok();
122        let local_var_error = ResponseContent {
123            status: local_var_status,
124            content: local_var_content,
125            entity: local_var_entity,
126        };
127        Err(Error::ResponseError(local_var_error))
128    }
129}
130
131pub fn create_image_export_task(
132    configuration: &configuration::Configuration,
133    create_image_export_task_request: Option<crate::models::CreateImageExportTaskRequest>,
134) -> Result<crate::models::CreateImageExportTaskResponse, Error<CreateImageExportTaskError>> {
135    let local_var_configuration = configuration;
136
137    let local_var_client = &local_var_configuration.client;
138
139    let local_var_uri_str = format!(
140        "{}/CreateImageExportTask",
141        local_var_configuration.base_path
142    );
143    let mut local_var_req_builder =
144        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
145
146    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
147        let local_var_new_headers = match local_var_aws_v4_key.sign(
148            &local_var_uri_str,
149            "POST",
150            &serde_json::to_string(&create_image_export_task_request)
151                .expect("param should serialize to string"),
152        ) {
153            Ok(new_headers) => new_headers,
154            Err(err) => return Err(Error::AWSV4SignatureError(err)),
155        };
156        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
157            local_var_req_builder =
158                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
159        }
160    }
161    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
162        local_var_req_builder =
163            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
164    }
165    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
166        let local_var_key = local_var_apikey.key.clone();
167        let local_var_value = match local_var_apikey.prefix {
168            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
169            None => local_var_key,
170        };
171        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
172    };
173    local_var_req_builder = local_var_req_builder.json(&create_image_export_task_request);
174
175    let local_var_req = local_var_req_builder.build()?;
176    let mut local_var_resp = local_var_client.execute(local_var_req)?;
177
178    let local_var_status = local_var_resp.status();
179    let local_var_content = local_var_resp.text()?;
180
181    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
182        serde_json::from_str(&local_var_content).map_err(Error::from)
183    } else {
184        let local_var_entity: Option<CreateImageExportTaskError> =
185            serde_json::from_str(&local_var_content).ok();
186        let local_var_error = ResponseContent {
187            status: local_var_status,
188            content: local_var_content,
189            entity: local_var_entity,
190        };
191        Err(Error::ResponseError(local_var_error))
192    }
193}
194
195pub fn delete_image(
196    configuration: &configuration::Configuration,
197    delete_image_request: Option<crate::models::DeleteImageRequest>,
198) -> Result<crate::models::DeleteImageResponse, Error<DeleteImageError>> {
199    let local_var_configuration = configuration;
200
201    let local_var_client = &local_var_configuration.client;
202
203    let local_var_uri_str = format!("{}/DeleteImage", local_var_configuration.base_path);
204    let mut local_var_req_builder =
205        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
206
207    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
208        let local_var_new_headers = match local_var_aws_v4_key.sign(
209            &local_var_uri_str,
210            "POST",
211            &serde_json::to_string(&delete_image_request)
212                .expect("param should serialize to string"),
213        ) {
214            Ok(new_headers) => new_headers,
215            Err(err) => return Err(Error::AWSV4SignatureError(err)),
216        };
217        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
218            local_var_req_builder =
219                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
220        }
221    }
222    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
223        local_var_req_builder =
224            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
225    }
226    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
227        let local_var_key = local_var_apikey.key.clone();
228        let local_var_value = match local_var_apikey.prefix {
229            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
230            None => local_var_key,
231        };
232        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
233    };
234    local_var_req_builder = local_var_req_builder.json(&delete_image_request);
235
236    let local_var_req = local_var_req_builder.build()?;
237    let mut local_var_resp = local_var_client.execute(local_var_req)?;
238
239    let local_var_status = local_var_resp.status();
240    let local_var_content = local_var_resp.text()?;
241
242    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
243        serde_json::from_str(&local_var_content).map_err(Error::from)
244    } else {
245        let local_var_entity: Option<DeleteImageError> =
246            serde_json::from_str(&local_var_content).ok();
247        let local_var_error = ResponseContent {
248            status: local_var_status,
249            content: local_var_content,
250            entity: local_var_entity,
251        };
252        Err(Error::ResponseError(local_var_error))
253    }
254}
255
256pub fn read_image_export_tasks(
257    configuration: &configuration::Configuration,
258    read_image_export_tasks_request: Option<crate::models::ReadImageExportTasksRequest>,
259) -> Result<crate::models::ReadImageExportTasksResponse, Error<ReadImageExportTasksError>> {
260    let local_var_configuration = configuration;
261
262    let local_var_client = &local_var_configuration.client;
263
264    let local_var_uri_str = format!("{}/ReadImageExportTasks", local_var_configuration.base_path);
265    let mut local_var_req_builder =
266        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
267
268    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
269        let local_var_new_headers = match local_var_aws_v4_key.sign(
270            &local_var_uri_str,
271            "POST",
272            &serde_json::to_string(&read_image_export_tasks_request)
273                .expect("param should serialize to string"),
274        ) {
275            Ok(new_headers) => new_headers,
276            Err(err) => return Err(Error::AWSV4SignatureError(err)),
277        };
278        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
279            local_var_req_builder =
280                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
281        }
282    }
283    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
284        local_var_req_builder =
285            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
286    }
287    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
288        let local_var_key = local_var_apikey.key.clone();
289        let local_var_value = match local_var_apikey.prefix {
290            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
291            None => local_var_key,
292        };
293        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
294    };
295    local_var_req_builder = local_var_req_builder.json(&read_image_export_tasks_request);
296
297    let local_var_req = local_var_req_builder.build()?;
298    let mut local_var_resp = local_var_client.execute(local_var_req)?;
299
300    let local_var_status = local_var_resp.status();
301    let local_var_content = local_var_resp.text()?;
302
303    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
304        serde_json::from_str(&local_var_content).map_err(Error::from)
305    } else {
306        let local_var_entity: Option<ReadImageExportTasksError> =
307            serde_json::from_str(&local_var_content).ok();
308        let local_var_error = ResponseContent {
309            status: local_var_status,
310            content: local_var_content,
311            entity: local_var_entity,
312        };
313        Err(Error::ResponseError(local_var_error))
314    }
315}
316
317pub fn read_images(
318    configuration: &configuration::Configuration,
319    read_images_request: Option<crate::models::ReadImagesRequest>,
320) -> Result<crate::models::ReadImagesResponse, Error<ReadImagesError>> {
321    let local_var_configuration = configuration;
322
323    let local_var_client = &local_var_configuration.client;
324
325    let local_var_uri_str = format!("{}/ReadImages", local_var_configuration.base_path);
326    let mut local_var_req_builder =
327        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
328
329    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
330        let local_var_new_headers = match local_var_aws_v4_key.sign(
331            &local_var_uri_str,
332            "POST",
333            &serde_json::to_string(&read_images_request).expect("param should serialize to string"),
334        ) {
335            Ok(new_headers) => new_headers,
336            Err(err) => return Err(Error::AWSV4SignatureError(err)),
337        };
338        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
339            local_var_req_builder =
340                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
341        }
342    }
343    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
344        local_var_req_builder =
345            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
346    }
347    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
348        let local_var_key = local_var_apikey.key.clone();
349        let local_var_value = match local_var_apikey.prefix {
350            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
351            None => local_var_key,
352        };
353        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
354    };
355    local_var_req_builder = local_var_req_builder.json(&read_images_request);
356
357    let local_var_req = local_var_req_builder.build()?;
358    let mut local_var_resp = local_var_client.execute(local_var_req)?;
359
360    let local_var_status = local_var_resp.status();
361    let local_var_content = local_var_resp.text()?;
362
363    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
364        serde_json::from_str(&local_var_content).map_err(Error::from)
365    } else {
366        let local_var_entity: Option<ReadImagesError> =
367            serde_json::from_str(&local_var_content).ok();
368        let local_var_error = ResponseContent {
369            status: local_var_status,
370            content: local_var_content,
371            entity: local_var_entity,
372        };
373        Err(Error::ResponseError(local_var_error))
374    }
375}
376
377pub fn update_image(
378    configuration: &configuration::Configuration,
379    update_image_request: Option<crate::models::UpdateImageRequest>,
380) -> Result<crate::models::UpdateImageResponse, Error<UpdateImageError>> {
381    let local_var_configuration = configuration;
382
383    let local_var_client = &local_var_configuration.client;
384
385    let local_var_uri_str = format!("{}/UpdateImage", local_var_configuration.base_path);
386    let mut local_var_req_builder =
387        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
388
389    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
390        let local_var_new_headers = match local_var_aws_v4_key.sign(
391            &local_var_uri_str,
392            "POST",
393            &serde_json::to_string(&update_image_request)
394                .expect("param should serialize to string"),
395        ) {
396            Ok(new_headers) => new_headers,
397            Err(err) => return Err(Error::AWSV4SignatureError(err)),
398        };
399        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
400            local_var_req_builder =
401                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
402        }
403    }
404    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
405        local_var_req_builder =
406            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
407    }
408    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
409        let local_var_key = local_var_apikey.key.clone();
410        let local_var_value = match local_var_apikey.prefix {
411            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
412            None => local_var_key,
413        };
414        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
415    };
416    local_var_req_builder = local_var_req_builder.json(&update_image_request);
417
418    let local_var_req = local_var_req_builder.build()?;
419    let mut local_var_resp = local_var_client.execute(local_var_req)?;
420
421    let local_var_status = local_var_resp.status();
422    let local_var_content = local_var_resp.text()?;
423
424    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
425        serde_json::from_str(&local_var_content).map_err(Error::from)
426    } else {
427        let local_var_entity: Option<UpdateImageError> =
428            serde_json::from_str(&local_var_content).ok();
429        let local_var_error = ResponseContent {
430            status: local_var_status,
431            content: local_var_content,
432            entity: local_var_entity,
433        };
434        Err(Error::ResponseError(local_var_error))
435    }
436}