Skip to main content

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