fastly_api/apis/
tls_configurations_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 [`get_tls_config`]
15#[derive(Clone, Debug, Default)]
16pub struct GetTlsConfigParams {
17    /// Alphanumeric string identifying a TLS configuration.
18    pub tls_configuration_id: String,
19    /// Include related objects. Optional, comma-separated values. Permitted values: `dns_records`. 
20    pub include: Option<String>
21}
22
23/// struct for passing parameters to the method [`list_tls_configs`]
24#[derive(Clone, Debug, Default)]
25pub struct ListTlsConfigsParams {
26    /// Optionally filters by the bulk attribute.
27    pub filter_bulk: Option<String>,
28    /// Include related objects. Optional, comma-separated values. Permitted values: `dns_records`. 
29    pub include: Option<String>,
30    /// Current page.
31    pub page_number: Option<i32>,
32    /// Number of records per page.
33    pub page_size: Option<i32>
34}
35
36/// struct for passing parameters to the method [`update_tls_config`]
37#[derive(Clone, Debug, Default)]
38pub struct UpdateTlsConfigParams {
39    /// Alphanumeric string identifying a TLS configuration.
40    pub tls_configuration_id: String,
41    pub tls_configuration: Option<crate::models::TlsConfiguration>
42}
43
44
45/// struct for typed errors of method [`get_tls_config`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetTlsConfigError {
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`list_tls_configs`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ListTlsConfigsError {
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`update_tls_config`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum UpdateTlsConfigError {
63    UnknownValue(serde_json::Value),
64}
65
66
67/// Show a TLS configuration.
68pub async fn get_tls_config(configuration: &mut configuration::Configuration, params: GetTlsConfigParams) -> Result<crate::models::TlsConfigurationResponse, Error<GetTlsConfigError>> {
69    let local_var_configuration = configuration;
70
71    // unbox the parameters
72    let tls_configuration_id = params.tls_configuration_id;
73    let include = params.include;
74
75
76    let local_var_client = &local_var_configuration.client;
77
78    let local_var_uri_str = format!("{}/tls/configurations/{tls_configuration_id}", local_var_configuration.base_path, tls_configuration_id=crate::apis::urlencode(tls_configuration_id));
79    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
80
81    if let Some(ref local_var_str) = include {
82        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
83    }
84    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
85        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
86    }
87    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
88        let local_var_key = local_var_apikey.key.clone();
89        let local_var_value = match local_var_apikey.prefix {
90            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
91            None => local_var_key,
92        };
93        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
94    };
95
96    let local_var_req = local_var_req_builder.build()?;
97    let local_var_resp = local_var_client.execute(local_var_req).await?;
98
99    if "GET" != "GET" && "GET" != "HEAD" {
100      let headers = local_var_resp.headers();
101      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
102          Some(v) => v.to_str().unwrap().parse().unwrap(),
103          None => configuration::DEFAULT_RATELIMIT,
104      };
105      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
106          Some(v) => v.to_str().unwrap().parse().unwrap(),
107          None => 0,
108      };
109    }
110
111    let local_var_status = local_var_resp.status();
112    let local_var_content = local_var_resp.text().await?;
113
114    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
115        serde_json::from_str(&local_var_content).map_err(Error::from)
116    } else {
117        let local_var_entity: Option<GetTlsConfigError> = serde_json::from_str(&local_var_content).ok();
118        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
119        Err(Error::ResponseError(local_var_error))
120    }
121}
122
123/// List all TLS configurations.
124pub async fn list_tls_configs(configuration: &mut configuration::Configuration, params: ListTlsConfigsParams) -> Result<crate::models::TlsConfigurationsResponse, Error<ListTlsConfigsError>> {
125    let local_var_configuration = configuration;
126
127    // unbox the parameters
128    let filter_bulk = params.filter_bulk;
129    let include = params.include;
130    let page_number = params.page_number;
131    let page_size = params.page_size;
132
133
134    let local_var_client = &local_var_configuration.client;
135
136    let local_var_uri_str = format!("{}/tls/configurations", local_var_configuration.base_path);
137    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
138
139    if let Some(ref local_var_str) = filter_bulk {
140        local_var_req_builder = local_var_req_builder.query(&[("filter[bulk]", &local_var_str.to_string())]);
141    }
142    if let Some(ref local_var_str) = include {
143        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
144    }
145    if let Some(ref local_var_str) = page_number {
146        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
147    }
148    if let Some(ref local_var_str) = page_size {
149        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
150    }
151    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
153    }
154    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
155        let local_var_key = local_var_apikey.key.clone();
156        let local_var_value = match local_var_apikey.prefix {
157            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
158            None => local_var_key,
159        };
160        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
161    };
162
163    let local_var_req = local_var_req_builder.build()?;
164    let local_var_resp = local_var_client.execute(local_var_req).await?;
165
166    if "GET" != "GET" && "GET" != "HEAD" {
167      let headers = local_var_resp.headers();
168      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
169          Some(v) => v.to_str().unwrap().parse().unwrap(),
170          None => configuration::DEFAULT_RATELIMIT,
171      };
172      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
173          Some(v) => v.to_str().unwrap().parse().unwrap(),
174          None => 0,
175      };
176    }
177
178    let local_var_status = local_var_resp.status();
179    let local_var_content = local_var_resp.text().await?;
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<ListTlsConfigsError> = serde_json::from_str(&local_var_content).ok();
185        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
186        Err(Error::ResponseError(local_var_error))
187    }
188}
189
190/// Update a TLS configuration.
191pub async fn update_tls_config(configuration: &mut configuration::Configuration, params: UpdateTlsConfigParams) -> Result<crate::models::TlsConfigurationResponse, Error<UpdateTlsConfigError>> {
192    let local_var_configuration = configuration;
193
194    // unbox the parameters
195    let tls_configuration_id = params.tls_configuration_id;
196    let tls_configuration = params.tls_configuration;
197
198
199    let local_var_client = &local_var_configuration.client;
200
201    let local_var_uri_str = format!("{}/tls/configurations/{tls_configuration_id}", local_var_configuration.base_path, tls_configuration_id=crate::apis::urlencode(tls_configuration_id));
202    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
203
204    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
205        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
206    }
207    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
208        let local_var_key = local_var_apikey.key.clone();
209        let local_var_value = match local_var_apikey.prefix {
210            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
211            None => local_var_key,
212        };
213        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
214    };
215    local_var_req_builder = local_var_req_builder.json(&tls_configuration);
216
217    let local_var_req = local_var_req_builder.build()?;
218    let local_var_resp = local_var_client.execute(local_var_req).await?;
219
220    if "PATCH" != "GET" && "PATCH" != "HEAD" {
221      let headers = local_var_resp.headers();
222      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
223          Some(v) => v.to_str().unwrap().parse().unwrap(),
224          None => configuration::DEFAULT_RATELIMIT,
225      };
226      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
227          Some(v) => v.to_str().unwrap().parse().unwrap(),
228          None => 0,
229      };
230    }
231
232    let local_var_status = local_var_resp.status();
233    let local_var_content = local_var_resp.text().await?;
234
235    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
236        serde_json::from_str(&local_var_content).map_err(Error::from)
237    } else {
238        let local_var_entity: Option<UpdateTlsConfigError> = serde_json::from_str(&local_var_content).ok();
239        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
240        Err(Error::ResponseError(local_var_error))
241    }
242}
243