fastly_api/apis/
tls_domains_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 [`list_tls_domains`]
15#[derive(Clone, Debug, Default)]
16pub struct ListTlsDomainsParams {
17    /// Optional. Limit the returned domains to those currently using Fastly to terminate TLS with SNI (that is, domains considered \"in use\") Permitted values: true, false.
18    pub filter_in_use: Option<String>,
19    /// Optional. Limit the returned domains to those listed in the given TLS certificate's SAN list.
20    pub filter_tls_certificates_id: Option<String>,
21    /// Optional. Limit the returned domains to those for a given TLS subscription.
22    pub filter_tls_subscriptions_id: Option<String>,
23    /// Include related objects. Optional, comma-separated values. Permitted values: `tls_activations`, `tls_certificates`, `tls_subscriptions`, `tls_subscriptions.tls_authorizations`, `tls_authorizations.globalsign_email_challenge`, and `tls_authorizations.self_managed_http_challenge`. 
24    pub include: Option<String>,
25    /// The order in which to list the results.
26    pub sort: Option<String>,
27    /// Current page.
28    pub page_number: Option<i32>,
29    /// Number of records per page.
30    pub page_size: Option<i32>
31}
32
33
34/// struct for typed errors of method [`list_tls_domains`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ListTlsDomainsError {
38    UnknownValue(serde_json::Value),
39}
40
41
42/// List all TLS domains.
43pub async fn list_tls_domains(configuration: &mut configuration::Configuration, params: ListTlsDomainsParams) -> Result<crate::models::TlsDomainsResponse, Error<ListTlsDomainsError>> {
44    let local_var_configuration = configuration;
45
46    // unbox the parameters
47    let filter_in_use = params.filter_in_use;
48    let filter_tls_certificates_id = params.filter_tls_certificates_id;
49    let filter_tls_subscriptions_id = params.filter_tls_subscriptions_id;
50    let include = params.include;
51    let sort = params.sort;
52    let page_number = params.page_number;
53    let page_size = params.page_size;
54
55
56    let local_var_client = &local_var_configuration.client;
57
58    let local_var_uri_str = format!("{}/tls/domains", local_var_configuration.base_path);
59    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
60
61    if let Some(ref local_var_str) = filter_in_use {
62        local_var_req_builder = local_var_req_builder.query(&[("filter[in_use]", &local_var_str.to_string())]);
63    }
64    if let Some(ref local_var_str) = filter_tls_certificates_id {
65        local_var_req_builder = local_var_req_builder.query(&[("filter[tls_certificates.id]", &local_var_str.to_string())]);
66    }
67    if let Some(ref local_var_str) = filter_tls_subscriptions_id {
68        local_var_req_builder = local_var_req_builder.query(&[("filter[tls_subscriptions.id]", &local_var_str.to_string())]);
69    }
70    if let Some(ref local_var_str) = include {
71        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
72    }
73    if let Some(ref local_var_str) = sort {
74        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
75    }
76    if let Some(ref local_var_str) = page_number {
77        local_var_req_builder = local_var_req_builder.query(&[("page[number]", &local_var_str.to_string())]);
78    }
79    if let Some(ref local_var_str) = page_size {
80        local_var_req_builder = local_var_req_builder.query(&[("page[size]", &local_var_str.to_string())]);
81    }
82    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
83        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
84    }
85    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
86        let local_var_key = local_var_apikey.key.clone();
87        let local_var_value = match local_var_apikey.prefix {
88            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
89            None => local_var_key,
90        };
91        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
92    };
93
94    let local_var_req = local_var_req_builder.build()?;
95    let local_var_resp = local_var_client.execute(local_var_req).await?;
96
97    if "GET" != "GET" && "GET" != "HEAD" {
98      let headers = local_var_resp.headers();
99      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
100          Some(v) => v.to_str().unwrap().parse().unwrap(),
101          None => configuration::DEFAULT_RATELIMIT,
102      };
103      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
104          Some(v) => v.to_str().unwrap().parse().unwrap(),
105          None => 0,
106      };
107    }
108
109    let local_var_status = local_var_resp.status();
110    let local_var_content = local_var_resp.text().await?;
111
112    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113        serde_json::from_str(&local_var_content).map_err(Error::from)
114    } else {
115        let local_var_entity: Option<ListTlsDomainsError> = serde_json::from_str(&local_var_content).ok();
116        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
117        Err(Error::ResponseError(local_var_error))
118    }
119}
120