fastly_api/apis/
tls_private_keys_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`create_tls_key`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateTlsKeyParams {
17    pub tls_private_key: Option<crate::models::TlsPrivateKey>
18}
19
20/// struct for passing parameters to the method [`delete_tls_key`]
21#[derive(Clone, Debug, Default)]
22pub struct DeleteTlsKeyParams {
23    /// Alphanumeric string identifying a private Key.
24    pub tls_private_key_id: String
25}
26
27/// struct for passing parameters to the method [`get_tls_key`]
28#[derive(Clone, Debug, Default)]
29pub struct GetTlsKeyParams {
30    /// Alphanumeric string identifying a private Key.
31    pub tls_private_key_id: String
32}
33
34/// struct for passing parameters to the method [`list_tls_keys`]
35#[derive(Clone, Debug, Default)]
36pub struct ListTlsKeysParams {
37    /// Limit the returned keys to those without any matching TLS certificates. The only valid value is false.
38    pub filter_in_use: Option<String>,
39    /// Current page.
40    pub page_number: Option<i32>,
41    /// Number of records per page.
42    pub page_size: Option<i32>
43}
44
45
46/// struct for typed errors of method [`create_tls_key`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum CreateTlsKeyError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`delete_tls_key`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum DeleteTlsKeyError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_tls_key`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetTlsKeyError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`list_tls_keys`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ListTlsKeysError {
71    UnknownValue(serde_json::Value),
72}
73
74
75/// Create a TLS private key.
76pub async fn create_tls_key(configuration: &mut configuration::Configuration, params: CreateTlsKeyParams) -> Result<crate::models::TlsPrivateKeyResponse, Error<CreateTlsKeyError>> {
77    let local_var_configuration = configuration;
78
79    // unbox the parameters
80    let tls_private_key = params.tls_private_key;
81
82
83    let local_var_client = &local_var_configuration.client;
84
85    let local_var_uri_str = format!("{}/tls/private_keys", local_var_configuration.base_path);
86    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
87
88    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
89        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
90    }
91    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
92        let local_var_key = local_var_apikey.key.clone();
93        let local_var_value = match local_var_apikey.prefix {
94            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
95            None => local_var_key,
96        };
97        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
98    };
99    local_var_req_builder = local_var_req_builder.json(&tls_private_key);
100
101    let local_var_req = local_var_req_builder.build()?;
102    let local_var_resp = local_var_client.execute(local_var_req).await?;
103
104    if "POST" != "GET" && "POST" != "HEAD" {
105      let headers = local_var_resp.headers();
106      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
107          Some(v) => v.to_str().unwrap().parse().unwrap(),
108          None => configuration::DEFAULT_RATELIMIT,
109      };
110      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
111          Some(v) => v.to_str().unwrap().parse().unwrap(),
112          None => 0,
113      };
114    }
115
116    let local_var_status = local_var_resp.status();
117    let local_var_content = local_var_resp.text().await?;
118
119    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
120        serde_json::from_str(&local_var_content).map_err(Error::from)
121    } else {
122        let local_var_entity: Option<CreateTlsKeyError> = serde_json::from_str(&local_var_content).ok();
123        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
124        Err(Error::ResponseError(local_var_error))
125    }
126}
127
128/// Destroy a TLS private key. Only private keys not already matched to any certificates can be deleted.
129pub async fn delete_tls_key(configuration: &mut configuration::Configuration, params: DeleteTlsKeyParams) -> Result<(), Error<DeleteTlsKeyError>> {
130    let local_var_configuration = configuration;
131
132    // unbox the parameters
133    let tls_private_key_id = params.tls_private_key_id;
134
135
136    let local_var_client = &local_var_configuration.client;
137
138    let local_var_uri_str = format!("{}/tls/private_keys/{tls_private_key_id}", local_var_configuration.base_path, tls_private_key_id=crate::apis::urlencode(tls_private_key_id));
139    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
140
141    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
142        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
143    }
144    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
145        let local_var_key = local_var_apikey.key.clone();
146        let local_var_value = match local_var_apikey.prefix {
147            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
148            None => local_var_key,
149        };
150        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
151    };
152
153    let local_var_req = local_var_req_builder.build()?;
154    let local_var_resp = local_var_client.execute(local_var_req).await?;
155
156    if "DELETE" != "GET" && "DELETE" != "HEAD" {
157      let headers = local_var_resp.headers();
158      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
159          Some(v) => v.to_str().unwrap().parse().unwrap(),
160          None => configuration::DEFAULT_RATELIMIT,
161      };
162      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
163          Some(v) => v.to_str().unwrap().parse().unwrap(),
164          None => 0,
165      };
166    }
167
168    let local_var_status = local_var_resp.status();
169    let local_var_content = local_var_resp.text().await?;
170
171    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
172        Ok(())
173    } else {
174        let local_var_entity: Option<DeleteTlsKeyError> = serde_json::from_str(&local_var_content).ok();
175        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
176        Err(Error::ResponseError(local_var_error))
177    }
178}
179
180/// Show a TLS private key.
181pub async fn get_tls_key(configuration: &mut configuration::Configuration, params: GetTlsKeyParams) -> Result<crate::models::TlsPrivateKeyResponse, Error<GetTlsKeyError>> {
182    let local_var_configuration = configuration;
183
184    // unbox the parameters
185    let tls_private_key_id = params.tls_private_key_id;
186
187
188    let local_var_client = &local_var_configuration.client;
189
190    let local_var_uri_str = format!("{}/tls/private_keys/{tls_private_key_id}", local_var_configuration.base_path, tls_private_key_id=crate::apis::urlencode(tls_private_key_id));
191    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
192
193    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
194        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
195    }
196    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
197        let local_var_key = local_var_apikey.key.clone();
198        let local_var_value = match local_var_apikey.prefix {
199            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
200            None => local_var_key,
201        };
202        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
203    };
204
205    let local_var_req = local_var_req_builder.build()?;
206    let local_var_resp = local_var_client.execute(local_var_req).await?;
207
208    if "GET" != "GET" && "GET" != "HEAD" {
209      let headers = local_var_resp.headers();
210      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
211          Some(v) => v.to_str().unwrap().parse().unwrap(),
212          None => configuration::DEFAULT_RATELIMIT,
213      };
214      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
215          Some(v) => v.to_str().unwrap().parse().unwrap(),
216          None => 0,
217      };
218    }
219
220    let local_var_status = local_var_resp.status();
221    let local_var_content = local_var_resp.text().await?;
222
223    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
224        serde_json::from_str(&local_var_content).map_err(Error::from)
225    } else {
226        let local_var_entity: Option<GetTlsKeyError> = serde_json::from_str(&local_var_content).ok();
227        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
228        Err(Error::ResponseError(local_var_error))
229    }
230}
231
232/// List all TLS private keys.
233pub async fn list_tls_keys(configuration: &mut configuration::Configuration, params: ListTlsKeysParams) -> Result<crate::models::TlsPrivateKeysResponse, Error<ListTlsKeysError>> {
234    let local_var_configuration = configuration;
235
236    // unbox the parameters
237    let filter_in_use = params.filter_in_use;
238    let page_number = params.page_number;
239    let page_size = params.page_size;
240
241
242    let local_var_client = &local_var_configuration.client;
243
244    let local_var_uri_str = format!("{}/tls/private_keys", local_var_configuration.base_path);
245    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
246
247    if let Some(ref local_var_str) = filter_in_use {
248        local_var_req_builder = local_var_req_builder.query(&[("filter[in_use]", &local_var_str.to_string())]);
249    }
250    if let Some(ref local_var_str) = page_number {
251        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
252    }
253    if let Some(ref local_var_str) = page_size {
254        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
255    }
256    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
257        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
258    }
259    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
260        let local_var_key = local_var_apikey.key.clone();
261        let local_var_value = match local_var_apikey.prefix {
262            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
263            None => local_var_key,
264        };
265        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
266    };
267
268    let local_var_req = local_var_req_builder.build()?;
269    let local_var_resp = local_var_client.execute(local_var_req).await?;
270
271    if "GET" != "GET" && "GET" != "HEAD" {
272      let headers = local_var_resp.headers();
273      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
274          Some(v) => v.to_str().unwrap().parse().unwrap(),
275          None => configuration::DEFAULT_RATELIMIT,
276      };
277      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
278          Some(v) => v.to_str().unwrap().parse().unwrap(),
279          None => 0,
280      };
281    }
282
283    let local_var_status = local_var_resp.status();
284    let local_var_content = local_var_resp.text().await?;
285
286    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
287        serde_json::from_str(&local_var_content).map_err(Error::from)
288    } else {
289        let local_var_entity: Option<ListTlsKeysError> = serde_json::from_str(&local_var_content).ok();
290        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
291        Err(Error::ResponseError(local_var_error))
292    }
293}
294