fastly_api/apis/
ngwaf_reports_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_attacks_report`]
15#[derive(Clone, Debug, Default)]
16pub struct GetAttacksReportParams {
17    /// The start of a time range in RFC 3339 format.
18    pub from: String,
19    /// The end of a time range in RFC 3339 format. Defaults to the current time.
20    pub to: Option<String>
21}
22
23/// struct for passing parameters to the method [`get_signals_report`]
24#[derive(Clone, Debug, Default)]
25pub struct GetSignalsReportParams {
26    /// The start of a time range in RFC 3339 format.
27    pub from: String,
28    /// The end of a time range in RFC 3339 format. Defaults to the current time.
29    pub to: Option<String>,
30    /// The type of signal
31    pub signal_type: Option<String>
32}
33
34
35/// struct for typed errors of method [`get_attacks_report`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetAttacksReportError {
39    Status400(serde_json::Value),
40    Status401(serde_json::Value),
41    Status403(serde_json::Value),
42    Status429(serde_json::Value),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_signals_report`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetSignalsReportError {
50    Status400(serde_json::Value),
51    Status401(serde_json::Value),
52    Status403(serde_json::Value),
53    Status429(serde_json::Value),
54    UnknownValue(serde_json::Value),
55}
56
57
58/// Get attacks report
59pub async fn get_attacks_report(configuration: &mut configuration::Configuration, params: GetAttacksReportParams) -> Result<crate::models::ListAttackReport, Error<GetAttacksReportError>> {
60    let local_var_configuration = configuration;
61
62    // unbox the parameters
63    let from = params.from;
64    let to = params.to;
65
66
67    let local_var_client = &local_var_configuration.client;
68
69    let local_var_uri_str = format!("{}/ngwaf/v1/reports/attacks", local_var_configuration.base_path);
70    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
71
72    local_var_req_builder = local_var_req_builder.query(&[("from", &from.to_string())]);
73    if let Some(ref local_var_str) = to {
74        local_var_req_builder = local_var_req_builder.query(&[("to", &local_var_str.to_string())]);
75    }
76    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
77        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
78    }
79    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
80        let local_var_key = local_var_apikey.key.clone();
81        let local_var_value = match local_var_apikey.prefix {
82            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
83            None => local_var_key,
84        };
85        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
86    };
87
88    let local_var_req = local_var_req_builder.build()?;
89    let local_var_resp = local_var_client.execute(local_var_req).await?;
90
91    if "GET" != "GET" && "GET" != "HEAD" {
92      let headers = local_var_resp.headers();
93      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
94          Some(v) => v.to_str().unwrap().parse().unwrap(),
95          None => configuration::DEFAULT_RATELIMIT,
96      };
97      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
98          Some(v) => v.to_str().unwrap().parse().unwrap(),
99          None => 0,
100      };
101    }
102
103    let local_var_status = local_var_resp.status();
104    let local_var_content = local_var_resp.text().await?;
105
106    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
107        serde_json::from_str(&local_var_content).map_err(Error::from)
108    } else {
109        let local_var_entity: Option<GetAttacksReportError> = serde_json::from_str(&local_var_content).ok();
110        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
111        Err(Error::ResponseError(local_var_error))
112    }
113}
114
115/// Get signals report
116pub async fn get_signals_report(configuration: &mut configuration::Configuration, params: GetSignalsReportParams) -> Result<crate::models::ListSignalReport, Error<GetSignalsReportError>> {
117    let local_var_configuration = configuration;
118
119    // unbox the parameters
120    let from = params.from;
121    let to = params.to;
122    let signal_type = params.signal_type;
123
124
125    let local_var_client = &local_var_configuration.client;
126
127    let local_var_uri_str = format!("{}/ngwaf/v1/reports/signals", local_var_configuration.base_path);
128    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
129
130    local_var_req_builder = local_var_req_builder.query(&[("from", &from.to_string())]);
131    if let Some(ref local_var_str) = to {
132        local_var_req_builder = local_var_req_builder.query(&[("to", &local_var_str.to_string())]);
133    }
134    if let Some(ref local_var_str) = signal_type {
135        local_var_req_builder = local_var_req_builder.query(&[("signal_type", &local_var_str.to_string())]);
136    }
137    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
138        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
139    }
140    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
141        let local_var_key = local_var_apikey.key.clone();
142        let local_var_value = match local_var_apikey.prefix {
143            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
144            None => local_var_key,
145        };
146        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
147    };
148
149    let local_var_req = local_var_req_builder.build()?;
150    let local_var_resp = local_var_client.execute(local_var_req).await?;
151
152    if "GET" != "GET" && "GET" != "HEAD" {
153      let headers = local_var_resp.headers();
154      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
155          Some(v) => v.to_str().unwrap().parse().unwrap(),
156          None => configuration::DEFAULT_RATELIMIT,
157      };
158      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
159          Some(v) => v.to_str().unwrap().parse().unwrap(),
160          None => 0,
161      };
162    }
163
164    let local_var_status = local_var_resp.status();
165    let local_var_content = local_var_resp.text().await?;
166
167    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
168        serde_json::from_str(&local_var_content).map_err(Error::from)
169    } else {
170        let local_var_entity: Option<GetSignalsReportError> = serde_json::from_str(&local_var_content).ok();
171        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
172        Err(Error::ResponseError(local_var_error))
173    }
174}
175