outscale_api/apis/
ca_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.34.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_ca`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateCaError {
20    UnknownValue(serde_json::Value),
21}
22
23/// struct for typed errors of method [`delete_ca`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum DeleteCaError {
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`read_cas`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ReadCasError {
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`update_ca`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum UpdateCaError {
41    UnknownValue(serde_json::Value),
42}
43
44pub fn create_ca(
45    configuration: &configuration::Configuration,
46    create_ca_request: Option<crate::models::CreateCaRequest>,
47) -> Result<crate::models::CreateCaResponse, Error<CreateCaError>> {
48    let local_var_configuration = configuration;
49
50    let local_var_client = &local_var_configuration.client;
51
52    let local_var_uri_str = format!("{}/CreateCa", local_var_configuration.base_path);
53    let mut local_var_req_builder =
54        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
55
56    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
57        let local_var_new_headers = match local_var_aws_v4_key.sign(
58            &local_var_uri_str,
59            "POST",
60            &serde_json::to_string(&create_ca_request).expect("param should serialize to string"),
61        ) {
62            Ok(new_headers) => new_headers,
63            Err(err) => return Err(Error::AWSV4SignatureError(err)),
64        };
65        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
66            local_var_req_builder =
67                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
68        }
69    }
70    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
71        local_var_req_builder =
72            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
73    }
74    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
75        let local_var_key = local_var_apikey.key.clone();
76        let local_var_value = match local_var_apikey.prefix {
77            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
78            None => local_var_key,
79        };
80        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
81    };
82    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
83        local_var_req_builder = local_var_req_builder.basic_auth(
84            local_var_auth_conf.0.to_owned(),
85            local_var_auth_conf.1.to_owned(),
86        );
87    };
88    local_var_req_builder = local_var_req_builder.json(&create_ca_request);
89
90    let local_var_req = local_var_req_builder.build()?;
91    let mut local_var_resp = local_var_client.execute(local_var_req)?;
92
93    let local_var_status = local_var_resp.status();
94    let local_var_content = local_var_resp.text()?;
95
96    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
97        serde_json::from_str(&local_var_content).map_err(Error::from)
98    } else {
99        let local_var_entity: Option<CreateCaError> = serde_json::from_str(&local_var_content).ok();
100        let local_var_error = ResponseContent {
101            status: local_var_status,
102            content: local_var_content,
103            entity: local_var_entity,
104        };
105        Err(Error::ResponseError(local_var_error))
106    }
107}
108
109pub fn delete_ca(
110    configuration: &configuration::Configuration,
111    delete_ca_request: Option<crate::models::DeleteCaRequest>,
112) -> Result<crate::models::DeleteCaResponse, Error<DeleteCaError>> {
113    let local_var_configuration = configuration;
114
115    let local_var_client = &local_var_configuration.client;
116
117    let local_var_uri_str = format!("{}/DeleteCa", local_var_configuration.base_path);
118    let mut local_var_req_builder =
119        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
120
121    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
122        let local_var_new_headers = match local_var_aws_v4_key.sign(
123            &local_var_uri_str,
124            "POST",
125            &serde_json::to_string(&delete_ca_request).expect("param should serialize to string"),
126        ) {
127            Ok(new_headers) => new_headers,
128            Err(err) => return Err(Error::AWSV4SignatureError(err)),
129        };
130        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
131            local_var_req_builder =
132                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
133        }
134    }
135    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
136        local_var_req_builder =
137            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138    }
139    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
140        let local_var_key = local_var_apikey.key.clone();
141        let local_var_value = match local_var_apikey.prefix {
142            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
143            None => local_var_key,
144        };
145        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
146    };
147    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
148        local_var_req_builder = local_var_req_builder.basic_auth(
149            local_var_auth_conf.0.to_owned(),
150            local_var_auth_conf.1.to_owned(),
151        );
152    };
153    local_var_req_builder = local_var_req_builder.json(&delete_ca_request);
154
155    let local_var_req = local_var_req_builder.build()?;
156    let mut local_var_resp = local_var_client.execute(local_var_req)?;
157
158    let local_var_status = local_var_resp.status();
159    let local_var_content = local_var_resp.text()?;
160
161    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162        serde_json::from_str(&local_var_content).map_err(Error::from)
163    } else {
164        let local_var_entity: Option<DeleteCaError> = serde_json::from_str(&local_var_content).ok();
165        let local_var_error = ResponseContent {
166            status: local_var_status,
167            content: local_var_content,
168            entity: local_var_entity,
169        };
170        Err(Error::ResponseError(local_var_error))
171    }
172}
173
174pub fn read_cas(
175    configuration: &configuration::Configuration,
176    read_cas_request: Option<crate::models::ReadCasRequest>,
177) -> Result<crate::models::ReadCasResponse, Error<ReadCasError>> {
178    let local_var_configuration = configuration;
179
180    let local_var_client = &local_var_configuration.client;
181
182    let local_var_uri_str = format!("{}/ReadCas", local_var_configuration.base_path);
183    let mut local_var_req_builder =
184        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
185
186    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
187        let local_var_new_headers = match local_var_aws_v4_key.sign(
188            &local_var_uri_str,
189            "POST",
190            &serde_json::to_string(&read_cas_request).expect("param should serialize to string"),
191        ) {
192            Ok(new_headers) => new_headers,
193            Err(err) => return Err(Error::AWSV4SignatureError(err)),
194        };
195        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
196            local_var_req_builder =
197                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
198        }
199    }
200    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
201        local_var_req_builder =
202            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
203    }
204    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
205        let local_var_key = local_var_apikey.key.clone();
206        let local_var_value = match local_var_apikey.prefix {
207            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
208            None => local_var_key,
209        };
210        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
211    };
212    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
213        local_var_req_builder = local_var_req_builder.basic_auth(
214            local_var_auth_conf.0.to_owned(),
215            local_var_auth_conf.1.to_owned(),
216        );
217    };
218    local_var_req_builder = local_var_req_builder.json(&read_cas_request);
219
220    let local_var_req = local_var_req_builder.build()?;
221    let mut local_var_resp = local_var_client.execute(local_var_req)?;
222
223    let local_var_status = local_var_resp.status();
224    let local_var_content = local_var_resp.text()?;
225
226    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
227        serde_json::from_str(&local_var_content).map_err(Error::from)
228    } else {
229        let local_var_entity: Option<ReadCasError> = serde_json::from_str(&local_var_content).ok();
230        let local_var_error = ResponseContent {
231            status: local_var_status,
232            content: local_var_content,
233            entity: local_var_entity,
234        };
235        Err(Error::ResponseError(local_var_error))
236    }
237}
238
239pub fn update_ca(
240    configuration: &configuration::Configuration,
241    update_ca_request: Option<crate::models::UpdateCaRequest>,
242) -> Result<crate::models::UpdateCaResponse, Error<UpdateCaError>> {
243    let local_var_configuration = configuration;
244
245    let local_var_client = &local_var_configuration.client;
246
247    let local_var_uri_str = format!("{}/UpdateCa", local_var_configuration.base_path);
248    let mut local_var_req_builder =
249        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
250
251    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
252        let local_var_new_headers = match local_var_aws_v4_key.sign(
253            &local_var_uri_str,
254            "POST",
255            &serde_json::to_string(&update_ca_request).expect("param should serialize to string"),
256        ) {
257            Ok(new_headers) => new_headers,
258            Err(err) => return Err(Error::AWSV4SignatureError(err)),
259        };
260        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
261            local_var_req_builder =
262                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
263        }
264    }
265    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
266        local_var_req_builder =
267            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
268    }
269    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
270        let local_var_key = local_var_apikey.key.clone();
271        let local_var_value = match local_var_apikey.prefix {
272            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
273            None => local_var_key,
274        };
275        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
276    };
277    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
278        local_var_req_builder = local_var_req_builder.basic_auth(
279            local_var_auth_conf.0.to_owned(),
280            local_var_auth_conf.1.to_owned(),
281        );
282    };
283    local_var_req_builder = local_var_req_builder.json(&update_ca_request);
284
285    let local_var_req = local_var_req_builder.build()?;
286    let mut local_var_resp = local_var_client.execute(local_var_req)?;
287
288    let local_var_status = local_var_resp.status();
289    let local_var_content = local_var_resp.text()?;
290
291    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
292        serde_json::from_str(&local_var_content).map_err(Error::from)
293    } else {
294        let local_var_entity: Option<UpdateCaError> = serde_json::from_str(&local_var_content).ok();
295        let local_var_error = ResponseContent {
296            status: local_var_status,
297            content: local_var_content,
298            entity: local_var_entity,
299        };
300        Err(Error::ResponseError(local_var_error))
301    }
302}