Skip to main content

outscale_api/apis/
nat_service_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 this API is also available for download: <button>[GitHub repository](https://github.com/outscale/osc-api)</button><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 OUTSCALE 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.40.1
7 * Contact: support@outscale.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::apis::ResponseContent;
13
14/// struct for typed errors of method [`create_nat_service`]
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(untagged)]
17pub enum CreateNatServiceError {
18    Status400(crate::models::ErrorResponse),
19    Status401(crate::models::ErrorResponse),
20    Status500(crate::models::ErrorResponse),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`delete_nat_service`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum DeleteNatServiceError {
28    Status400(crate::models::ErrorResponse),
29    Status401(crate::models::ErrorResponse),
30    Status500(crate::models::ErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`read_nat_services`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ReadNatServicesError {
38    Status400(crate::models::ErrorResponse),
39    Status401(crate::models::ErrorResponse),
40    Status500(crate::models::ErrorResponse),
41    UnknownValue(serde_json::Value),
42}
43
44/// Creates a network address translation (NAT) service in the specified public Subnet of a Net.<br /> A NAT service enables virtual machines (VMs) placed in the private Subnet of this Net to connect to the Internet, without being accessible from the Internet.<br /> When creating a NAT service, you specify the allocation ID of the public IP you want to use as public IP for the NAT service. Once the NAT service is created, you need to create a route in the route table of the private Subnet, with 0.0.0.0/0 as destination and the ID of the NAT service as target. For more information, see [LinkPublicIP](#linkpublicip) and [CreateRoute](#createroute).<br /> This action also enables you to create multiple NAT services in the same Net (one per public Subnet).<br /><br />  **[IMPORTANT]**<br /> You cannot modify the public IP associated with a NAT service after its creation. To do so, you need to delete the NAT service and create a new one with another public IP.<br /><br /> For more information, see [About NAT Services](https://docs.outscale.com/en/userguide/About-NAT-Services.html).
45pub fn create_nat_service(
46    configuration: &configuration::Configuration,
47    create_nat_service_request: Option<crate::models::CreateNatServiceRequest>,
48) -> Result<crate::models::CreateNatServiceResponse, Error<CreateNatServiceError>> {
49    let local_var_configuration = configuration;
50
51    let local_var_client = &local_var_configuration.client;
52
53    let local_var_uri_str = format!("{}/CreateNatService", local_var_configuration.base_path);
54    let mut local_var_req_builder =
55        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
56
57    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
58        let local_var_new_headers = match local_var_aws_v4_key.sign(
59            &local_var_uri_str,
60            "POST",
61            &serde_json::to_string(&create_nat_service_request)
62                .expect("param should serialize to string"),
63        ) {
64            Ok(new_headers) => new_headers,
65            Err(err) => return Err(Error::AWSV4SignatureError(err)),
66        };
67        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
68            local_var_req_builder =
69                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
70        }
71    }
72    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
73        local_var_req_builder =
74            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
75    }
76    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
77        let local_var_key = local_var_apikey.key.clone();
78        let local_var_value = match local_var_apikey.prefix {
79            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
80            None => local_var_key,
81        };
82        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
83    };
84    local_var_req_builder = local_var_req_builder.json(&create_nat_service_request);
85
86    let local_var_req = local_var_req_builder.build()?;
87    let local_var_resp = local_var_client.execute(local_var_req)?;
88
89    let local_var_status = local_var_resp.status();
90    let local_var_content = local_var_resp.text()?;
91
92    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
93        serde_json::from_str(&local_var_content).map_err(Error::from)
94    } else {
95        let local_var_entity: Option<CreateNatServiceError> =
96            serde_json::from_str(&local_var_content).ok();
97        let local_var_error = ResponseContent {
98            status: local_var_status,
99            content: local_var_content,
100            entity: local_var_entity,
101        };
102        Err(Error::ResponseError(local_var_error))
103    }
104}
105
106/// Deletes a specified network address translation (NAT) service.<br /> This action disassociates the public IP from the NAT service, but does not release this public IP from your OUTSCALE account. However, it does not delete any NAT service routes in your route tables.
107pub fn delete_nat_service(
108    configuration: &configuration::Configuration,
109    delete_nat_service_request: Option<crate::models::DeleteNatServiceRequest>,
110) -> Result<crate::models::DeleteNatServiceResponse, Error<DeleteNatServiceError>> {
111    let local_var_configuration = configuration;
112
113    let local_var_client = &local_var_configuration.client;
114
115    let local_var_uri_str = format!("{}/DeleteNatService", local_var_configuration.base_path);
116    let mut local_var_req_builder =
117        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
118
119    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
120        let local_var_new_headers = match local_var_aws_v4_key.sign(
121            &local_var_uri_str,
122            "POST",
123            &serde_json::to_string(&delete_nat_service_request)
124                .expect("param should serialize to string"),
125        ) {
126            Ok(new_headers) => new_headers,
127            Err(err) => return Err(Error::AWSV4SignatureError(err)),
128        };
129        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
130            local_var_req_builder =
131                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
132        }
133    }
134    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
135        local_var_req_builder =
136            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
137    }
138    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
139        let local_var_key = local_var_apikey.key.clone();
140        let local_var_value = match local_var_apikey.prefix {
141            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
142            None => local_var_key,
143        };
144        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
145    };
146    local_var_req_builder = local_var_req_builder.json(&delete_nat_service_request);
147
148    let local_var_req = local_var_req_builder.build()?;
149    let local_var_resp = local_var_client.execute(local_var_req)?;
150
151    let local_var_status = local_var_resp.status();
152    let local_var_content = local_var_resp.text()?;
153
154    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
155        serde_json::from_str(&local_var_content).map_err(Error::from)
156    } else {
157        let local_var_entity: Option<DeleteNatServiceError> =
158            serde_json::from_str(&local_var_content).ok();
159        let local_var_error = ResponseContent {
160            status: local_var_status,
161            content: local_var_content,
162            entity: local_var_entity,
163        };
164        Err(Error::ResponseError(local_var_error))
165    }
166}
167
168/// Lists one or more network address translation (NAT) services.
169pub fn read_nat_services(
170    configuration: &configuration::Configuration,
171    read_nat_services_request: Option<crate::models::ReadNatServicesRequest>,
172) -> Result<crate::models::ReadNatServicesResponse, Error<ReadNatServicesError>> {
173    let local_var_configuration = configuration;
174
175    let local_var_client = &local_var_configuration.client;
176
177    let local_var_uri_str = format!("{}/ReadNatServices", local_var_configuration.base_path);
178    let mut local_var_req_builder =
179        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
180
181    if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key {
182        let local_var_new_headers = match local_var_aws_v4_key.sign(
183            &local_var_uri_str,
184            "POST",
185            &serde_json::to_string(&read_nat_services_request)
186                .expect("param should serialize to string"),
187        ) {
188            Ok(new_headers) => new_headers,
189            Err(err) => return Err(Error::AWSV4SignatureError(err)),
190        };
191        for (local_var_name, local_var_value) in local_var_new_headers.iter() {
192            local_var_req_builder =
193                local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str());
194        }
195    }
196    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
197        local_var_req_builder =
198            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199    }
200    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
201        let local_var_key = local_var_apikey.key.clone();
202        let local_var_value = match local_var_apikey.prefix {
203            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
204            None => local_var_key,
205        };
206        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
207    };
208    local_var_req_builder = local_var_req_builder.json(&read_nat_services_request);
209
210    let local_var_req = local_var_req_builder.build()?;
211    let local_var_resp = local_var_client.execute(local_var_req)?;
212
213    let local_var_status = local_var_resp.status();
214    let local_var_content = local_var_resp.text()?;
215
216    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
217        serde_json::from_str(&local_var_content).map_err(Error::from)
218    } else {
219        let local_var_entity: Option<ReadNatServicesError> =
220            serde_json::from_str(&local_var_content).ok();
221        let local_var_error = ResponseContent {
222            status: local_var_status,
223            content: local_var_content,
224            entity: local_var_entity,
225        };
226        Err(Error::ResponseError(local_var_error))
227    }
228}