Skip to main content

fastly_api/apis/
client_side_protection_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 [`csp_create_page`]
15#[derive(Clone, Debug, Default)]
16pub struct CspCreatePageParams {
17    pub page_create: Option<crate::models::PageCreate>
18}
19
20/// struct for passing parameters to the method [`csp_create_policy`]
21#[derive(Clone, Debug, Default)]
22pub struct CspCreatePolicyParams {
23    /// Page identifier
24    pub page_id: String,
25    pub policy_create: Option<crate::models::PolicyCreate>
26}
27
28/// struct for passing parameters to the method [`csp_create_website`]
29#[derive(Clone, Debug, Default)]
30pub struct CspCreateWebsiteParams {
31    pub website_create: Option<crate::models::WebsiteCreate>
32}
33
34/// struct for passing parameters to the method [`csp_delete_page`]
35#[derive(Clone, Debug, Default)]
36pub struct CspDeletePageParams {
37    /// Page identifier
38    pub page_id: String
39}
40
41/// struct for passing parameters to the method [`csp_delete_website`]
42#[derive(Clone, Debug, Default)]
43pub struct CspDeleteWebsiteParams {
44    /// Website identifier
45    pub website_id: String
46}
47
48/// struct for passing parameters to the method [`csp_get_page`]
49#[derive(Clone, Debug, Default)]
50pub struct CspGetPageParams {
51    /// Page identifier
52    pub page_id: String
53}
54
55/// struct for passing parameters to the method [`csp_get_policy`]
56#[derive(Clone, Debug, Default)]
57pub struct CspGetPolicyParams {
58    /// Page identifier
59    pub page_id: String,
60    /// Policy identifier
61    pub policy_id: String
62}
63
64/// struct for passing parameters to the method [`csp_get_script`]
65#[derive(Clone, Debug, Default)]
66pub struct CspGetScriptParams {
67    /// Page identifier
68    pub page_id: String,
69    /// Script identifier
70    pub script_id: String
71}
72
73/// struct for passing parameters to the method [`csp_get_website`]
74#[derive(Clone, Debug, Default)]
75pub struct CspGetWebsiteParams {
76    /// Website identifier
77    pub website_id: String
78}
79
80/// struct for passing parameters to the method [`csp_list_header_events`]
81#[derive(Clone, Debug, Default)]
82pub struct CspListHeaderEventsParams {
83    /// Page identifier
84    pub page_id: String,
85    /// Limit how many results are returned.
86    pub limit: Option<i32>,
87    /// Page number of the collection to request.
88    pub page: Option<i32>
89}
90
91/// struct for passing parameters to the method [`csp_list_headers`]
92#[derive(Clone, Debug, Default)]
93pub struct CspListHeadersParams {
94    /// Page identifier
95    pub page_id: String,
96    /// Limit how many results are returned.
97    pub limit: Option<i32>,
98    /// Page number of the collection to request.
99    pub page: Option<i32>
100}
101
102/// struct for passing parameters to the method [`csp_list_pages`]
103#[derive(Clone, Debug, Default)]
104pub struct CspListPagesParams {
105    /// Filter pages by website ID
106    pub website_id: Option<String>,
107    /// Limit how many results are returned.
108    pub limit: Option<i32>,
109    /// Page number of the collection to request.
110    pub page: Option<i32>
111}
112
113/// struct for passing parameters to the method [`csp_list_policies`]
114#[derive(Clone, Debug, Default)]
115pub struct CspListPoliciesParams {
116    /// Page identifier
117    pub page_id: String,
118    /// Limit how many results are returned.
119    pub limit: Option<i32>,
120    /// Page number of the collection to request.
121    pub page: Option<i32>
122}
123
124/// struct for passing parameters to the method [`csp_list_policy_reports`]
125#[derive(Clone, Debug, Default)]
126pub struct CspListPolicyReportsParams {
127    /// Page identifier
128    pub page_id: String,
129    /// Policy identifier
130    pub policy_id: String,
131    /// Limit how many results are returned.
132    pub limit: Option<i32>,
133    /// Page number of the collection to request.
134    pub page: Option<i32>
135}
136
137/// struct for passing parameters to the method [`csp_list_scripts`]
138#[derive(Clone, Debug, Default)]
139pub struct CspListScriptsParams {
140    /// Page identifier
141    pub page_id: String,
142    /// Limit how many results are returned.
143    pub limit: Option<i32>,
144    /// Page number of the collection to request.
145    pub page: Option<i32>
146}
147
148/// struct for passing parameters to the method [`csp_list_websites`]
149#[derive(Clone, Debug, Default)]
150pub struct CspListWebsitesParams {
151    /// Limit how many results are returned.
152    pub limit: Option<i32>,
153    /// Page number of the collection to request.
154    pub page: Option<i32>
155}
156
157/// struct for passing parameters to the method [`csp_update_page`]
158#[derive(Clone, Debug, Default)]
159pub struct CspUpdatePageParams {
160    /// Page identifier
161    pub page_id: String,
162    pub page_update: Option<crate::models::PageUpdate>
163}
164
165/// struct for passing parameters to the method [`csp_update_policy`]
166#[derive(Clone, Debug, Default)]
167pub struct CspUpdatePolicyParams {
168    /// Page identifier
169    pub page_id: String,
170    /// Policy identifier
171    pub policy_id: String,
172    pub policy_update: Option<crate::models::PolicyUpdate>
173}
174
175/// struct for passing parameters to the method [`csp_update_script`]
176#[derive(Clone, Debug, Default)]
177pub struct CspUpdateScriptParams {
178    /// Page identifier
179    pub page_id: String,
180    /// Script identifier
181    pub script_id: String,
182    pub script_update: Option<crate::models::ScriptUpdate>
183}
184
185/// struct for passing parameters to the method [`csp_update_website`]
186#[derive(Clone, Debug, Default)]
187pub struct CspUpdateWebsiteParams {
188    /// Website identifier
189    pub website_id: String,
190    pub website_update: Option<crate::models::WebsiteUpdate>
191}
192
193
194/// struct for typed errors of method [`csp_create_page`]
195#[derive(Debug, Clone, Serialize, Deserialize)]
196#[serde(untagged)]
197pub enum CspCreatePageError {
198    Status400(serde_json::Value),
199    Status401(serde_json::Value),
200    Status403(serde_json::Value),
201    Status429(serde_json::Value),
202    UnknownValue(serde_json::Value),
203}
204
205/// struct for typed errors of method [`csp_create_policy`]
206#[derive(Debug, Clone, Serialize, Deserialize)]
207#[serde(untagged)]
208pub enum CspCreatePolicyError {
209    Status400(serde_json::Value),
210    Status401(serde_json::Value),
211    Status403(serde_json::Value),
212    Status404(serde_json::Value),
213    Status429(serde_json::Value),
214    UnknownValue(serde_json::Value),
215}
216
217/// struct for typed errors of method [`csp_create_website`]
218#[derive(Debug, Clone, Serialize, Deserialize)]
219#[serde(untagged)]
220pub enum CspCreateWebsiteError {
221    Status400(serde_json::Value),
222    Status401(serde_json::Value),
223    Status403(serde_json::Value),
224    Status429(serde_json::Value),
225    UnknownValue(serde_json::Value),
226}
227
228/// struct for typed errors of method [`csp_delete_page`]
229#[derive(Debug, Clone, Serialize, Deserialize)]
230#[serde(untagged)]
231pub enum CspDeletePageError {
232    Status401(serde_json::Value),
233    Status403(serde_json::Value),
234    Status404(serde_json::Value),
235    UnknownValue(serde_json::Value),
236}
237
238/// struct for typed errors of method [`csp_delete_website`]
239#[derive(Debug, Clone, Serialize, Deserialize)]
240#[serde(untagged)]
241pub enum CspDeleteWebsiteError {
242    Status401(serde_json::Value),
243    Status403(serde_json::Value),
244    Status404(serde_json::Value),
245    UnknownValue(serde_json::Value),
246}
247
248/// struct for typed errors of method [`csp_get_page`]
249#[derive(Debug, Clone, Serialize, Deserialize)]
250#[serde(untagged)]
251pub enum CspGetPageError {
252    Status401(serde_json::Value),
253    Status403(serde_json::Value),
254    Status404(serde_json::Value),
255    Status429(serde_json::Value),
256    UnknownValue(serde_json::Value),
257}
258
259/// struct for typed errors of method [`csp_get_policy`]
260#[derive(Debug, Clone, Serialize, Deserialize)]
261#[serde(untagged)]
262pub enum CspGetPolicyError {
263    Status401(serde_json::Value),
264    Status403(serde_json::Value),
265    Status404(serde_json::Value),
266    Status429(serde_json::Value),
267    UnknownValue(serde_json::Value),
268}
269
270/// struct for typed errors of method [`csp_get_script`]
271#[derive(Debug, Clone, Serialize, Deserialize)]
272#[serde(untagged)]
273pub enum CspGetScriptError {
274    Status401(serde_json::Value),
275    Status403(serde_json::Value),
276    Status404(serde_json::Value),
277    Status429(serde_json::Value),
278    UnknownValue(serde_json::Value),
279}
280
281/// struct for typed errors of method [`csp_get_website`]
282#[derive(Debug, Clone, Serialize, Deserialize)]
283#[serde(untagged)]
284pub enum CspGetWebsiteError {
285    Status401(serde_json::Value),
286    Status403(serde_json::Value),
287    Status404(serde_json::Value),
288    Status429(serde_json::Value),
289    UnknownValue(serde_json::Value),
290}
291
292/// struct for typed errors of method [`csp_list_header_events`]
293#[derive(Debug, Clone, Serialize, Deserialize)]
294#[serde(untagged)]
295pub enum CspListHeaderEventsError {
296    Status400(serde_json::Value),
297    Status401(serde_json::Value),
298    Status403(serde_json::Value),
299    Status404(serde_json::Value),
300    Status429(serde_json::Value),
301    UnknownValue(serde_json::Value),
302}
303
304/// struct for typed errors of method [`csp_list_headers`]
305#[derive(Debug, Clone, Serialize, Deserialize)]
306#[serde(untagged)]
307pub enum CspListHeadersError {
308    Status400(serde_json::Value),
309    Status401(serde_json::Value),
310    Status403(serde_json::Value),
311    Status404(serde_json::Value),
312    Status429(serde_json::Value),
313    UnknownValue(serde_json::Value),
314}
315
316/// struct for typed errors of method [`csp_list_pages`]
317#[derive(Debug, Clone, Serialize, Deserialize)]
318#[serde(untagged)]
319pub enum CspListPagesError {
320    Status400(serde_json::Value),
321    Status401(serde_json::Value),
322    Status403(serde_json::Value),
323    Status429(serde_json::Value),
324    UnknownValue(serde_json::Value),
325}
326
327/// struct for typed errors of method [`csp_list_policies`]
328#[derive(Debug, Clone, Serialize, Deserialize)]
329#[serde(untagged)]
330pub enum CspListPoliciesError {
331    Status400(serde_json::Value),
332    Status401(serde_json::Value),
333    Status403(serde_json::Value),
334    Status404(serde_json::Value),
335    Status429(serde_json::Value),
336    UnknownValue(serde_json::Value),
337}
338
339/// struct for typed errors of method [`csp_list_policy_reports`]
340#[derive(Debug, Clone, Serialize, Deserialize)]
341#[serde(untagged)]
342pub enum CspListPolicyReportsError {
343    Status400(serde_json::Value),
344    Status401(serde_json::Value),
345    Status403(serde_json::Value),
346    Status404(serde_json::Value),
347    UnknownValue(serde_json::Value),
348}
349
350/// struct for typed errors of method [`csp_list_scripts`]
351#[derive(Debug, Clone, Serialize, Deserialize)]
352#[serde(untagged)]
353pub enum CspListScriptsError {
354    Status400(serde_json::Value),
355    Status401(serde_json::Value),
356    Status403(serde_json::Value),
357    Status404(serde_json::Value),
358    Status429(serde_json::Value),
359    UnknownValue(serde_json::Value),
360}
361
362/// struct for typed errors of method [`csp_list_websites`]
363#[derive(Debug, Clone, Serialize, Deserialize)]
364#[serde(untagged)]
365pub enum CspListWebsitesError {
366    Status400(serde_json::Value),
367    Status401(serde_json::Value),
368    Status403(serde_json::Value),
369    Status429(serde_json::Value),
370    UnknownValue(serde_json::Value),
371}
372
373/// struct for typed errors of method [`csp_update_page`]
374#[derive(Debug, Clone, Serialize, Deserialize)]
375#[serde(untagged)]
376pub enum CspUpdatePageError {
377    Status400(serde_json::Value),
378    Status401(serde_json::Value),
379    Status403(serde_json::Value),
380    Status404(serde_json::Value),
381    Status429(serde_json::Value),
382    UnknownValue(serde_json::Value),
383}
384
385/// struct for typed errors of method [`csp_update_policy`]
386#[derive(Debug, Clone, Serialize, Deserialize)]
387#[serde(untagged)]
388pub enum CspUpdatePolicyError {
389    Status400(serde_json::Value),
390    Status401(serde_json::Value),
391    Status403(serde_json::Value),
392    Status404(serde_json::Value),
393    Status429(serde_json::Value),
394    UnknownValue(serde_json::Value),
395}
396
397/// struct for typed errors of method [`csp_update_script`]
398#[derive(Debug, Clone, Serialize, Deserialize)]
399#[serde(untagged)]
400pub enum CspUpdateScriptError {
401    Status400(serde_json::Value),
402    Status401(serde_json::Value),
403    Status403(serde_json::Value),
404    Status404(serde_json::Value),
405    UnknownValue(serde_json::Value),
406}
407
408/// struct for typed errors of method [`csp_update_website`]
409#[derive(Debug, Clone, Serialize, Deserialize)]
410#[serde(untagged)]
411pub enum CspUpdateWebsiteError {
412    Status400(serde_json::Value),
413    Status401(serde_json::Value),
414    Status403(serde_json::Value),
415    Status404(serde_json::Value),
416    Status429(serde_json::Value),
417    UnknownValue(serde_json::Value),
418}
419
420
421/// Create a new page for monitoring.
422pub async fn csp_create_page(configuration: &mut configuration::Configuration, params: CspCreatePageParams) -> Result<crate::models::Page, Error<CspCreatePageError>> {
423    let local_var_configuration = configuration;
424
425    // unbox the parameters
426    let page_create = params.page_create;
427
428
429    let local_var_client = &local_var_configuration.client;
430
431    let local_var_uri_str = format!("{}/client-side-protection/v1/pages", local_var_configuration.base_path);
432    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
433
434    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
435        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
436    }
437    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
438        let local_var_key = local_var_apikey.key.clone();
439        let local_var_value = match local_var_apikey.prefix {
440            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
441            None => local_var_key,
442        };
443        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
444    };
445    local_var_req_builder = local_var_req_builder.json(&page_create);
446
447    let local_var_req = local_var_req_builder.build()?;
448    let local_var_resp = local_var_client.execute(local_var_req).await?;
449
450    if "POST" != "GET" && "POST" != "HEAD" {
451      let headers = local_var_resp.headers();
452      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
453          Some(v) => v.to_str().unwrap().parse().unwrap(),
454          None => configuration::DEFAULT_RATELIMIT,
455      };
456      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
457          Some(v) => v.to_str().unwrap().parse().unwrap(),
458          None => 0,
459      };
460    }
461
462    let local_var_status = local_var_resp.status();
463    let local_var_content = local_var_resp.text().await?;
464
465    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
466        serde_json::from_str(&local_var_content).map_err(Error::from)
467    } else {
468        let local_var_entity: Option<CspCreatePageError> = serde_json::from_str(&local_var_content).ok();
469        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
470        Err(Error::ResponseError(local_var_error))
471    }
472}
473
474/// Create a new Content Security Policy for a page.
475pub async fn csp_create_policy(configuration: &mut configuration::Configuration, params: CspCreatePolicyParams) -> Result<crate::models::Policy, Error<CspCreatePolicyError>> {
476    let local_var_configuration = configuration;
477
478    // unbox the parameters
479    let page_id = params.page_id;
480    let policy_create = params.policy_create;
481
482
483    let local_var_client = &local_var_configuration.client;
484
485    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/policies", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id));
486    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
487
488    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
489        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
490    }
491    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
492        let local_var_key = local_var_apikey.key.clone();
493        let local_var_value = match local_var_apikey.prefix {
494            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
495            None => local_var_key,
496        };
497        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
498    };
499    local_var_req_builder = local_var_req_builder.json(&policy_create);
500
501    let local_var_req = local_var_req_builder.build()?;
502    let local_var_resp = local_var_client.execute(local_var_req).await?;
503
504    if "POST" != "GET" && "POST" != "HEAD" {
505      let headers = local_var_resp.headers();
506      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
507          Some(v) => v.to_str().unwrap().parse().unwrap(),
508          None => configuration::DEFAULT_RATELIMIT,
509      };
510      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
511          Some(v) => v.to_str().unwrap().parse().unwrap(),
512          None => 0,
513      };
514    }
515
516    let local_var_status = local_var_resp.status();
517    let local_var_content = local_var_resp.text().await?;
518
519    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
520        serde_json::from_str(&local_var_content).map_err(Error::from)
521    } else {
522        let local_var_entity: Option<CspCreatePolicyError> = serde_json::from_str(&local_var_content).ok();
523        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
524        Err(Error::ResponseError(local_var_error))
525    }
526}
527
528/// Create a new website for Client-Side Protection monitoring.
529pub async fn csp_create_website(configuration: &mut configuration::Configuration, params: CspCreateWebsiteParams) -> Result<crate::models::Website, Error<CspCreateWebsiteError>> {
530    let local_var_configuration = configuration;
531
532    // unbox the parameters
533    let website_create = params.website_create;
534
535
536    let local_var_client = &local_var_configuration.client;
537
538    let local_var_uri_str = format!("{}/client-side-protection/v1/websites", local_var_configuration.base_path);
539    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
540
541    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
542        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
543    }
544    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
545        let local_var_key = local_var_apikey.key.clone();
546        let local_var_value = match local_var_apikey.prefix {
547            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
548            None => local_var_key,
549        };
550        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
551    };
552    local_var_req_builder = local_var_req_builder.json(&website_create);
553
554    let local_var_req = local_var_req_builder.build()?;
555    let local_var_resp = local_var_client.execute(local_var_req).await?;
556
557    if "POST" != "GET" && "POST" != "HEAD" {
558      let headers = local_var_resp.headers();
559      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
560          Some(v) => v.to_str().unwrap().parse().unwrap(),
561          None => configuration::DEFAULT_RATELIMIT,
562      };
563      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
564          Some(v) => v.to_str().unwrap().parse().unwrap(),
565          None => 0,
566      };
567    }
568
569    let local_var_status = local_var_resp.status();
570    let local_var_content = local_var_resp.text().await?;
571
572    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
573        serde_json::from_str(&local_var_content).map_err(Error::from)
574    } else {
575        let local_var_entity: Option<CspCreateWebsiteError> = serde_json::from_str(&local_var_content).ok();
576        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
577        Err(Error::ResponseError(local_var_error))
578    }
579}
580
581/// Delete a page and all associated scripts and policies.
582pub async fn csp_delete_page(configuration: &mut configuration::Configuration, params: CspDeletePageParams) -> Result<(), Error<CspDeletePageError>> {
583    let local_var_configuration = configuration;
584
585    // unbox the parameters
586    let page_id = params.page_id;
587
588
589    let local_var_client = &local_var_configuration.client;
590
591    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id));
592    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
593
594    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
595        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
596    }
597    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
598        let local_var_key = local_var_apikey.key.clone();
599        let local_var_value = match local_var_apikey.prefix {
600            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
601            None => local_var_key,
602        };
603        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
604    };
605
606    let local_var_req = local_var_req_builder.build()?;
607    let local_var_resp = local_var_client.execute(local_var_req).await?;
608
609    if "DELETE" != "GET" && "DELETE" != "HEAD" {
610      let headers = local_var_resp.headers();
611      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
612          Some(v) => v.to_str().unwrap().parse().unwrap(),
613          None => configuration::DEFAULT_RATELIMIT,
614      };
615      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
616          Some(v) => v.to_str().unwrap().parse().unwrap(),
617          None => 0,
618      };
619    }
620
621    let local_var_status = local_var_resp.status();
622    let local_var_content = local_var_resp.text().await?;
623
624    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
625        Ok(())
626    } else {
627        let local_var_entity: Option<CspDeletePageError> = serde_json::from_str(&local_var_content).ok();
628        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
629        Err(Error::ResponseError(local_var_error))
630    }
631}
632
633/// Delete a website and all associated pages, scripts, and policies.
634pub async fn csp_delete_website(configuration: &mut configuration::Configuration, params: CspDeleteWebsiteParams) -> Result<(), Error<CspDeleteWebsiteError>> {
635    let local_var_configuration = configuration;
636
637    // unbox the parameters
638    let website_id = params.website_id;
639
640
641    let local_var_client = &local_var_configuration.client;
642
643    let local_var_uri_str = format!("{}/client-side-protection/v1/websites/{website_id}", local_var_configuration.base_path, website_id=crate::apis::urlencode(website_id));
644    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
645
646    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
647        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
648    }
649    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
650        let local_var_key = local_var_apikey.key.clone();
651        let local_var_value = match local_var_apikey.prefix {
652            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
653            None => local_var_key,
654        };
655        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
656    };
657
658    let local_var_req = local_var_req_builder.build()?;
659    let local_var_resp = local_var_client.execute(local_var_req).await?;
660
661    if "DELETE" != "GET" && "DELETE" != "HEAD" {
662      let headers = local_var_resp.headers();
663      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
664          Some(v) => v.to_str().unwrap().parse().unwrap(),
665          None => configuration::DEFAULT_RATELIMIT,
666      };
667      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
668          Some(v) => v.to_str().unwrap().parse().unwrap(),
669          None => 0,
670      };
671    }
672
673    let local_var_status = local_var_resp.status();
674    let local_var_content = local_var_resp.text().await?;
675
676    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
677        Ok(())
678    } else {
679        let local_var_entity: Option<CspDeleteWebsiteError> = serde_json::from_str(&local_var_content).ok();
680        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
681        Err(Error::ResponseError(local_var_error))
682    }
683}
684
685/// Get details for a specific page.
686pub async fn csp_get_page(configuration: &mut configuration::Configuration, params: CspGetPageParams) -> Result<crate::models::Page, Error<CspGetPageError>> {
687    let local_var_configuration = configuration;
688
689    // unbox the parameters
690    let page_id = params.page_id;
691
692
693    let local_var_client = &local_var_configuration.client;
694
695    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id));
696    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
697
698    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
699        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
700    }
701    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
702        let local_var_key = local_var_apikey.key.clone();
703        let local_var_value = match local_var_apikey.prefix {
704            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
705            None => local_var_key,
706        };
707        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
708    };
709
710    let local_var_req = local_var_req_builder.build()?;
711    let local_var_resp = local_var_client.execute(local_var_req).await?;
712
713    if "GET" != "GET" && "GET" != "HEAD" {
714      let headers = local_var_resp.headers();
715      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
716          Some(v) => v.to_str().unwrap().parse().unwrap(),
717          None => configuration::DEFAULT_RATELIMIT,
718      };
719      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
720          Some(v) => v.to_str().unwrap().parse().unwrap(),
721          None => 0,
722      };
723    }
724
725    let local_var_status = local_var_resp.status();
726    let local_var_content = local_var_resp.text().await?;
727
728    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
729        serde_json::from_str(&local_var_content).map_err(Error::from)
730    } else {
731        let local_var_entity: Option<CspGetPageError> = serde_json::from_str(&local_var_content).ok();
732        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
733        Err(Error::ResponseError(local_var_error))
734    }
735}
736
737/// Get details for a specific policy.
738pub async fn csp_get_policy(configuration: &mut configuration::Configuration, params: CspGetPolicyParams) -> Result<crate::models::Policy, Error<CspGetPolicyError>> {
739    let local_var_configuration = configuration;
740
741    // unbox the parameters
742    let page_id = params.page_id;
743    let policy_id = params.policy_id;
744
745
746    let local_var_client = &local_var_configuration.client;
747
748    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/policies/{policy_id}", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id), policy_id=crate::apis::urlencode(policy_id));
749    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
750
751    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
752        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
753    }
754    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
755        let local_var_key = local_var_apikey.key.clone();
756        let local_var_value = match local_var_apikey.prefix {
757            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
758            None => local_var_key,
759        };
760        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
761    };
762
763    let local_var_req = local_var_req_builder.build()?;
764    let local_var_resp = local_var_client.execute(local_var_req).await?;
765
766    if "GET" != "GET" && "GET" != "HEAD" {
767      let headers = local_var_resp.headers();
768      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
769          Some(v) => v.to_str().unwrap().parse().unwrap(),
770          None => configuration::DEFAULT_RATELIMIT,
771      };
772      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
773          Some(v) => v.to_str().unwrap().parse().unwrap(),
774          None => 0,
775      };
776    }
777
778    let local_var_status = local_var_resp.status();
779    let local_var_content = local_var_resp.text().await?;
780
781    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
782        serde_json::from_str(&local_var_content).map_err(Error::from)
783    } else {
784        let local_var_entity: Option<CspGetPolicyError> = serde_json::from_str(&local_var_content).ok();
785        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
786        Err(Error::ResponseError(local_var_error))
787    }
788}
789
790/// Get details for a specific script.
791pub async fn csp_get_script(configuration: &mut configuration::Configuration, params: CspGetScriptParams) -> Result<crate::models::Script, Error<CspGetScriptError>> {
792    let local_var_configuration = configuration;
793
794    // unbox the parameters
795    let page_id = params.page_id;
796    let script_id = params.script_id;
797
798
799    let local_var_client = &local_var_configuration.client;
800
801    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/scripts/{script_id}", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id), script_id=crate::apis::urlencode(script_id));
802    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
803
804    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
805        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
806    }
807    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
808        let local_var_key = local_var_apikey.key.clone();
809        let local_var_value = match local_var_apikey.prefix {
810            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
811            None => local_var_key,
812        };
813        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
814    };
815
816    let local_var_req = local_var_req_builder.build()?;
817    let local_var_resp = local_var_client.execute(local_var_req).await?;
818
819    if "GET" != "GET" && "GET" != "HEAD" {
820      let headers = local_var_resp.headers();
821      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
822          Some(v) => v.to_str().unwrap().parse().unwrap(),
823          None => configuration::DEFAULT_RATELIMIT,
824      };
825      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
826          Some(v) => v.to_str().unwrap().parse().unwrap(),
827          None => 0,
828      };
829    }
830
831    let local_var_status = local_var_resp.status();
832    let local_var_content = local_var_resp.text().await?;
833
834    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
835        serde_json::from_str(&local_var_content).map_err(Error::from)
836    } else {
837        let local_var_entity: Option<CspGetScriptError> = serde_json::from_str(&local_var_content).ok();
838        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
839        Err(Error::ResponseError(local_var_error))
840    }
841}
842
843/// Get details for a specific website.
844pub async fn csp_get_website(configuration: &mut configuration::Configuration, params: CspGetWebsiteParams) -> Result<crate::models::Website, Error<CspGetWebsiteError>> {
845    let local_var_configuration = configuration;
846
847    // unbox the parameters
848    let website_id = params.website_id;
849
850
851    let local_var_client = &local_var_configuration.client;
852
853    let local_var_uri_str = format!("{}/client-side-protection/v1/websites/{website_id}", local_var_configuration.base_path, website_id=crate::apis::urlencode(website_id));
854    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
855
856    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
857        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
858    }
859    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
860        let local_var_key = local_var_apikey.key.clone();
861        let local_var_value = match local_var_apikey.prefix {
862            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
863            None => local_var_key,
864        };
865        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
866    };
867
868    let local_var_req = local_var_req_builder.build()?;
869    let local_var_resp = local_var_client.execute(local_var_req).await?;
870
871    if "GET" != "GET" && "GET" != "HEAD" {
872      let headers = local_var_resp.headers();
873      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
874          Some(v) => v.to_str().unwrap().parse().unwrap(),
875          None => configuration::DEFAULT_RATELIMIT,
876      };
877      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
878          Some(v) => v.to_str().unwrap().parse().unwrap(),
879          None => 0,
880      };
881    }
882
883    let local_var_status = local_var_resp.status();
884    let local_var_content = local_var_resp.text().await?;
885
886    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
887        serde_json::from_str(&local_var_content).map_err(Error::from)
888    } else {
889        let local_var_entity: Option<CspGetWebsiteError> = serde_json::from_str(&local_var_content).ok();
890        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
891        Err(Error::ResponseError(local_var_error))
892    }
893}
894
895/// List security header change events for a page.
896pub async fn csp_list_header_events(configuration: &mut configuration::Configuration, params: CspListHeaderEventsParams) -> Result<crate::models::InlineResponse20011, Error<CspListHeaderEventsError>> {
897    let local_var_configuration = configuration;
898
899    // unbox the parameters
900    let page_id = params.page_id;
901    let limit = params.limit;
902    let page = params.page;
903
904
905    let local_var_client = &local_var_configuration.client;
906
907    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/events", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id));
908    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
909
910    if let Some(ref local_var_str) = limit {
911        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
912    }
913    if let Some(ref local_var_str) = page {
914        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
915    }
916    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
917        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
918    }
919    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
920        let local_var_key = local_var_apikey.key.clone();
921        let local_var_value = match local_var_apikey.prefix {
922            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
923            None => local_var_key,
924        };
925        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
926    };
927
928    let local_var_req = local_var_req_builder.build()?;
929    let local_var_resp = local_var_client.execute(local_var_req).await?;
930
931    if "GET" != "GET" && "GET" != "HEAD" {
932      let headers = local_var_resp.headers();
933      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
934          Some(v) => v.to_str().unwrap().parse().unwrap(),
935          None => configuration::DEFAULT_RATELIMIT,
936      };
937      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
938          Some(v) => v.to_str().unwrap().parse().unwrap(),
939          None => 0,
940      };
941    }
942
943    let local_var_status = local_var_resp.status();
944    let local_var_content = local_var_resp.text().await?;
945
946    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
947        serde_json::from_str(&local_var_content).map_err(Error::from)
948    } else {
949        let local_var_entity: Option<CspListHeaderEventsError> = serde_json::from_str(&local_var_content).ok();
950        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
951        Err(Error::ResponseError(local_var_error))
952    }
953}
954
955/// List security headers detected on a page.
956pub async fn csp_list_headers(configuration: &mut configuration::Configuration, params: CspListHeadersParams) -> Result<crate::models::InlineResponse20010, Error<CspListHeadersError>> {
957    let local_var_configuration = configuration;
958
959    // unbox the parameters
960    let page_id = params.page_id;
961    let limit = params.limit;
962    let page = params.page;
963
964
965    let local_var_client = &local_var_configuration.client;
966
967    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/headers", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id));
968    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
969
970    if let Some(ref local_var_str) = limit {
971        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
972    }
973    if let Some(ref local_var_str) = page {
974        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
975    }
976    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
977        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
978    }
979    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
980        let local_var_key = local_var_apikey.key.clone();
981        let local_var_value = match local_var_apikey.prefix {
982            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
983            None => local_var_key,
984        };
985        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
986    };
987
988    let local_var_req = local_var_req_builder.build()?;
989    let local_var_resp = local_var_client.execute(local_var_req).await?;
990
991    if "GET" != "GET" && "GET" != "HEAD" {
992      let headers = local_var_resp.headers();
993      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
994          Some(v) => v.to_str().unwrap().parse().unwrap(),
995          None => configuration::DEFAULT_RATELIMIT,
996      };
997      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
998          Some(v) => v.to_str().unwrap().parse().unwrap(),
999          None => 0,
1000      };
1001    }
1002
1003    let local_var_status = local_var_resp.status();
1004    let local_var_content = local_var_resp.text().await?;
1005
1006    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1007        serde_json::from_str(&local_var_content).map_err(Error::from)
1008    } else {
1009        let local_var_entity: Option<CspListHeadersError> = serde_json::from_str(&local_var_content).ok();
1010        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1011        Err(Error::ResponseError(local_var_error))
1012    }
1013}
1014
1015/// List all pages. Optionally filter by website.
1016pub async fn csp_list_pages(configuration: &mut configuration::Configuration, params: CspListPagesParams) -> Result<crate::models::InlineResponse2006, Error<CspListPagesError>> {
1017    let local_var_configuration = configuration;
1018
1019    // unbox the parameters
1020    let website_id = params.website_id;
1021    let limit = params.limit;
1022    let page = params.page;
1023
1024
1025    let local_var_client = &local_var_configuration.client;
1026
1027    let local_var_uri_str = format!("{}/client-side-protection/v1/pages", local_var_configuration.base_path);
1028    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1029
1030    if let Some(ref local_var_str) = website_id {
1031        local_var_req_builder = local_var_req_builder.query(&[("website_id", &local_var_str.to_string())]);
1032    }
1033    if let Some(ref local_var_str) = limit {
1034        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
1035    }
1036    if let Some(ref local_var_str) = page {
1037        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
1038    }
1039    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1040        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1041    }
1042    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1043        let local_var_key = local_var_apikey.key.clone();
1044        let local_var_value = match local_var_apikey.prefix {
1045            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1046            None => local_var_key,
1047        };
1048        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1049    };
1050
1051    let local_var_req = local_var_req_builder.build()?;
1052    let local_var_resp = local_var_client.execute(local_var_req).await?;
1053
1054    if "GET" != "GET" && "GET" != "HEAD" {
1055      let headers = local_var_resp.headers();
1056      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1057          Some(v) => v.to_str().unwrap().parse().unwrap(),
1058          None => configuration::DEFAULT_RATELIMIT,
1059      };
1060      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1061          Some(v) => v.to_str().unwrap().parse().unwrap(),
1062          None => 0,
1063      };
1064    }
1065
1066    let local_var_status = local_var_resp.status();
1067    let local_var_content = local_var_resp.text().await?;
1068
1069    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1070        serde_json::from_str(&local_var_content).map_err(Error::from)
1071    } else {
1072        let local_var_entity: Option<CspListPagesError> = serde_json::from_str(&local_var_content).ok();
1073        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1074        Err(Error::ResponseError(local_var_error))
1075    }
1076}
1077
1078/// List all Content Security Policies for a page.
1079pub async fn csp_list_policies(configuration: &mut configuration::Configuration, params: CspListPoliciesParams) -> Result<crate::models::InlineResponse2008, Error<CspListPoliciesError>> {
1080    let local_var_configuration = configuration;
1081
1082    // unbox the parameters
1083    let page_id = params.page_id;
1084    let limit = params.limit;
1085    let page = params.page;
1086
1087
1088    let local_var_client = &local_var_configuration.client;
1089
1090    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/policies", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id));
1091    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1092
1093    if let Some(ref local_var_str) = limit {
1094        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
1095    }
1096    if let Some(ref local_var_str) = page {
1097        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
1098    }
1099    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1100        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1101    }
1102    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1103        let local_var_key = local_var_apikey.key.clone();
1104        let local_var_value = match local_var_apikey.prefix {
1105            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1106            None => local_var_key,
1107        };
1108        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1109    };
1110
1111    let local_var_req = local_var_req_builder.build()?;
1112    let local_var_resp = local_var_client.execute(local_var_req).await?;
1113
1114    if "GET" != "GET" && "GET" != "HEAD" {
1115      let headers = local_var_resp.headers();
1116      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1117          Some(v) => v.to_str().unwrap().parse().unwrap(),
1118          None => configuration::DEFAULT_RATELIMIT,
1119      };
1120      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1121          Some(v) => v.to_str().unwrap().parse().unwrap(),
1122          None => 0,
1123      };
1124    }
1125
1126    let local_var_status = local_var_resp.status();
1127    let local_var_content = local_var_resp.text().await?;
1128
1129    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1130        serde_json::from_str(&local_var_content).map_err(Error::from)
1131    } else {
1132        let local_var_entity: Option<CspListPoliciesError> = serde_json::from_str(&local_var_content).ok();
1133        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1134        Err(Error::ResponseError(local_var_error))
1135    }
1136}
1137
1138/// List CSP violation reports for a policy.
1139pub async fn csp_list_policy_reports(configuration: &mut configuration::Configuration, params: CspListPolicyReportsParams) -> Result<crate::models::InlineResponse2009, Error<CspListPolicyReportsError>> {
1140    let local_var_configuration = configuration;
1141
1142    // unbox the parameters
1143    let page_id = params.page_id;
1144    let policy_id = params.policy_id;
1145    let limit = params.limit;
1146    let page = params.page;
1147
1148
1149    let local_var_client = &local_var_configuration.client;
1150
1151    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/policies/{policy_id}/reports", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id), policy_id=crate::apis::urlencode(policy_id));
1152    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1153
1154    if let Some(ref local_var_str) = limit {
1155        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
1156    }
1157    if let Some(ref local_var_str) = page {
1158        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
1159    }
1160    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1161        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1162    }
1163    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1164        let local_var_key = local_var_apikey.key.clone();
1165        let local_var_value = match local_var_apikey.prefix {
1166            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1167            None => local_var_key,
1168        };
1169        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1170    };
1171
1172    let local_var_req = local_var_req_builder.build()?;
1173    let local_var_resp = local_var_client.execute(local_var_req).await?;
1174
1175    if "GET" != "GET" && "GET" != "HEAD" {
1176      let headers = local_var_resp.headers();
1177      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1178          Some(v) => v.to_str().unwrap().parse().unwrap(),
1179          None => configuration::DEFAULT_RATELIMIT,
1180      };
1181      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1182          Some(v) => v.to_str().unwrap().parse().unwrap(),
1183          None => 0,
1184      };
1185    }
1186
1187    let local_var_status = local_var_resp.status();
1188    let local_var_content = local_var_resp.text().await?;
1189
1190    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1191        serde_json::from_str(&local_var_content).map_err(Error::from)
1192    } else {
1193        let local_var_entity: Option<CspListPolicyReportsError> = serde_json::from_str(&local_var_content).ok();
1194        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1195        Err(Error::ResponseError(local_var_error))
1196    }
1197}
1198
1199/// List all scripts detected on a page.
1200pub async fn csp_list_scripts(configuration: &mut configuration::Configuration, params: CspListScriptsParams) -> Result<crate::models::InlineResponse2007, Error<CspListScriptsError>> {
1201    let local_var_configuration = configuration;
1202
1203    // unbox the parameters
1204    let page_id = params.page_id;
1205    let limit = params.limit;
1206    let page = params.page;
1207
1208
1209    let local_var_client = &local_var_configuration.client;
1210
1211    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/scripts", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id));
1212    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1213
1214    if let Some(ref local_var_str) = limit {
1215        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
1216    }
1217    if let Some(ref local_var_str) = page {
1218        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
1219    }
1220    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1221        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1222    }
1223    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1224        let local_var_key = local_var_apikey.key.clone();
1225        let local_var_value = match local_var_apikey.prefix {
1226            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1227            None => local_var_key,
1228        };
1229        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1230    };
1231
1232    let local_var_req = local_var_req_builder.build()?;
1233    let local_var_resp = local_var_client.execute(local_var_req).await?;
1234
1235    if "GET" != "GET" && "GET" != "HEAD" {
1236      let headers = local_var_resp.headers();
1237      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1238          Some(v) => v.to_str().unwrap().parse().unwrap(),
1239          None => configuration::DEFAULT_RATELIMIT,
1240      };
1241      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1242          Some(v) => v.to_str().unwrap().parse().unwrap(),
1243          None => 0,
1244      };
1245    }
1246
1247    let local_var_status = local_var_resp.status();
1248    let local_var_content = local_var_resp.text().await?;
1249
1250    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1251        serde_json::from_str(&local_var_content).map_err(Error::from)
1252    } else {
1253        let local_var_entity: Option<CspListScriptsError> = serde_json::from_str(&local_var_content).ok();
1254        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1255        Err(Error::ResponseError(local_var_error))
1256    }
1257}
1258
1259/// List all websites configured for Client-Side Protection.
1260pub async fn csp_list_websites(configuration: &mut configuration::Configuration, params: CspListWebsitesParams) -> Result<crate::models::InlineResponse2005, Error<CspListWebsitesError>> {
1261    let local_var_configuration = configuration;
1262
1263    // unbox the parameters
1264    let limit = params.limit;
1265    let page = params.page;
1266
1267
1268    let local_var_client = &local_var_configuration.client;
1269
1270    let local_var_uri_str = format!("{}/client-side-protection/v1/websites", local_var_configuration.base_path);
1271    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
1272
1273    if let Some(ref local_var_str) = limit {
1274        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
1275    }
1276    if let Some(ref local_var_str) = page {
1277        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
1278    }
1279    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1280        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1281    }
1282    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1283        let local_var_key = local_var_apikey.key.clone();
1284        let local_var_value = match local_var_apikey.prefix {
1285            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1286            None => local_var_key,
1287        };
1288        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1289    };
1290
1291    let local_var_req = local_var_req_builder.build()?;
1292    let local_var_resp = local_var_client.execute(local_var_req).await?;
1293
1294    if "GET" != "GET" && "GET" != "HEAD" {
1295      let headers = local_var_resp.headers();
1296      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1297          Some(v) => v.to_str().unwrap().parse().unwrap(),
1298          None => configuration::DEFAULT_RATELIMIT,
1299      };
1300      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1301          Some(v) => v.to_str().unwrap().parse().unwrap(),
1302          None => 0,
1303      };
1304    }
1305
1306    let local_var_status = local_var_resp.status();
1307    let local_var_content = local_var_resp.text().await?;
1308
1309    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1310        serde_json::from_str(&local_var_content).map_err(Error::from)
1311    } else {
1312        let local_var_entity: Option<CspListWebsitesError> = serde_json::from_str(&local_var_content).ok();
1313        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1314        Err(Error::ResponseError(local_var_error))
1315    }
1316}
1317
1318/// Update a page's configuration.
1319pub async fn csp_update_page(configuration: &mut configuration::Configuration, params: CspUpdatePageParams) -> Result<crate::models::Page, Error<CspUpdatePageError>> {
1320    let local_var_configuration = configuration;
1321
1322    // unbox the parameters
1323    let page_id = params.page_id;
1324    let page_update = params.page_update;
1325
1326
1327    let local_var_client = &local_var_configuration.client;
1328
1329    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id));
1330    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
1331
1332    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1333        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1334    }
1335    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1336        let local_var_key = local_var_apikey.key.clone();
1337        let local_var_value = match local_var_apikey.prefix {
1338            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1339            None => local_var_key,
1340        };
1341        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1342    };
1343    local_var_req_builder = local_var_req_builder.json(&page_update);
1344
1345    let local_var_req = local_var_req_builder.build()?;
1346    let local_var_resp = local_var_client.execute(local_var_req).await?;
1347
1348    if "PATCH" != "GET" && "PATCH" != "HEAD" {
1349      let headers = local_var_resp.headers();
1350      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1351          Some(v) => v.to_str().unwrap().parse().unwrap(),
1352          None => configuration::DEFAULT_RATELIMIT,
1353      };
1354      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1355          Some(v) => v.to_str().unwrap().parse().unwrap(),
1356          None => 0,
1357      };
1358    }
1359
1360    let local_var_status = local_var_resp.status();
1361    let local_var_content = local_var_resp.text().await?;
1362
1363    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1364        serde_json::from_str(&local_var_content).map_err(Error::from)
1365    } else {
1366        let local_var_entity: Option<CspUpdatePageError> = serde_json::from_str(&local_var_content).ok();
1367        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1368        Err(Error::ResponseError(local_var_error))
1369    }
1370}
1371
1372/// Update a policy's configuration.
1373pub async fn csp_update_policy(configuration: &mut configuration::Configuration, params: CspUpdatePolicyParams) -> Result<crate::models::Policy, Error<CspUpdatePolicyError>> {
1374    let local_var_configuration = configuration;
1375
1376    // unbox the parameters
1377    let page_id = params.page_id;
1378    let policy_id = params.policy_id;
1379    let policy_update = params.policy_update;
1380
1381
1382    let local_var_client = &local_var_configuration.client;
1383
1384    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/policies/{policy_id}", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id), policy_id=crate::apis::urlencode(policy_id));
1385    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
1386
1387    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1388        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1389    }
1390    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1391        let local_var_key = local_var_apikey.key.clone();
1392        let local_var_value = match local_var_apikey.prefix {
1393            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1394            None => local_var_key,
1395        };
1396        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1397    };
1398    local_var_req_builder = local_var_req_builder.json(&policy_update);
1399
1400    let local_var_req = local_var_req_builder.build()?;
1401    let local_var_resp = local_var_client.execute(local_var_req).await?;
1402
1403    if "PATCH" != "GET" && "PATCH" != "HEAD" {
1404      let headers = local_var_resp.headers();
1405      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1406          Some(v) => v.to_str().unwrap().parse().unwrap(),
1407          None => configuration::DEFAULT_RATELIMIT,
1408      };
1409      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1410          Some(v) => v.to_str().unwrap().parse().unwrap(),
1411          None => 0,
1412      };
1413    }
1414
1415    let local_var_status = local_var_resp.status();
1416    let local_var_content = local_var_resp.text().await?;
1417
1418    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1419        serde_json::from_str(&local_var_content).map_err(Error::from)
1420    } else {
1421        let local_var_entity: Option<CspUpdatePolicyError> = serde_json::from_str(&local_var_content).ok();
1422        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1423        Err(Error::ResponseError(local_var_error))
1424    }
1425}
1426
1427/// Update a script's authorization status or justification.
1428pub async fn csp_update_script(configuration: &mut configuration::Configuration, params: CspUpdateScriptParams) -> Result<crate::models::Script, Error<CspUpdateScriptError>> {
1429    let local_var_configuration = configuration;
1430
1431    // unbox the parameters
1432    let page_id = params.page_id;
1433    let script_id = params.script_id;
1434    let script_update = params.script_update;
1435
1436
1437    let local_var_client = &local_var_configuration.client;
1438
1439    let local_var_uri_str = format!("{}/client-side-protection/v1/pages/{page_id}/scripts/{script_id}", local_var_configuration.base_path, page_id=crate::apis::urlencode(page_id), script_id=crate::apis::urlencode(script_id));
1440    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
1441
1442    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1443        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1444    }
1445    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1446        let local_var_key = local_var_apikey.key.clone();
1447        let local_var_value = match local_var_apikey.prefix {
1448            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1449            None => local_var_key,
1450        };
1451        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1452    };
1453    local_var_req_builder = local_var_req_builder.json(&script_update);
1454
1455    let local_var_req = local_var_req_builder.build()?;
1456    let local_var_resp = local_var_client.execute(local_var_req).await?;
1457
1458    if "PATCH" != "GET" && "PATCH" != "HEAD" {
1459      let headers = local_var_resp.headers();
1460      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1461          Some(v) => v.to_str().unwrap().parse().unwrap(),
1462          None => configuration::DEFAULT_RATELIMIT,
1463      };
1464      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1465          Some(v) => v.to_str().unwrap().parse().unwrap(),
1466          None => 0,
1467      };
1468    }
1469
1470    let local_var_status = local_var_resp.status();
1471    let local_var_content = local_var_resp.text().await?;
1472
1473    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1474        serde_json::from_str(&local_var_content).map_err(Error::from)
1475    } else {
1476        let local_var_entity: Option<CspUpdateScriptError> = serde_json::from_str(&local_var_content).ok();
1477        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1478        Err(Error::ResponseError(local_var_error))
1479    }
1480}
1481
1482/// Update a website's configuration.
1483pub async fn csp_update_website(configuration: &mut configuration::Configuration, params: CspUpdateWebsiteParams) -> Result<crate::models::Website, Error<CspUpdateWebsiteError>> {
1484    let local_var_configuration = configuration;
1485
1486    // unbox the parameters
1487    let website_id = params.website_id;
1488    let website_update = params.website_update;
1489
1490
1491    let local_var_client = &local_var_configuration.client;
1492
1493    let local_var_uri_str = format!("{}/client-side-protection/v1/websites/{website_id}", local_var_configuration.base_path, website_id=crate::apis::urlencode(website_id));
1494    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
1495
1496    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1497        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1498    }
1499    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
1500        let local_var_key = local_var_apikey.key.clone();
1501        let local_var_value = match local_var_apikey.prefix {
1502            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
1503            None => local_var_key,
1504        };
1505        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
1506    };
1507    local_var_req_builder = local_var_req_builder.json(&website_update);
1508
1509    let local_var_req = local_var_req_builder.build()?;
1510    let local_var_resp = local_var_client.execute(local_var_req).await?;
1511
1512    if "PATCH" != "GET" && "PATCH" != "HEAD" {
1513      let headers = local_var_resp.headers();
1514      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
1515          Some(v) => v.to_str().unwrap().parse().unwrap(),
1516          None => configuration::DEFAULT_RATELIMIT,
1517      };
1518      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
1519          Some(v) => v.to_str().unwrap().parse().unwrap(),
1520          None => 0,
1521      };
1522    }
1523
1524    let local_var_status = local_var_resp.status();
1525    let local_var_content = local_var_resp.text().await?;
1526
1527    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1528        serde_json::from_str(&local_var_content).map_err(Error::from)
1529    } else {
1530        let local_var_entity: Option<CspUpdateWebsiteError> = serde_json::from_str(&local_var_content).ok();
1531        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
1532        Err(Error::ResponseError(local_var_error))
1533    }
1534}
1535