fastly_api/apis/
vcl_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 [`create_custom_vcl`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateCustomVclParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    /// The VCL code to be included.
22    pub content: Option<String>,
23    /// Set to `true` when this is the main VCL, otherwise `false`.
24    pub main: Option<bool>,
25    /// The name of this VCL.
26    pub name: Option<String>
27}
28
29/// struct for passing parameters to the method [`delete_custom_vcl`]
30#[derive(Clone, Debug, Default)]
31pub struct DeleteCustomVclParams {
32    /// Alphanumeric string identifying the service.
33    pub service_id: String,
34    /// Integer identifying a service version.
35    pub version_id: i32,
36    /// The name of this VCL.
37    pub vcl_name: String
38}
39
40/// struct for passing parameters to the method [`get_custom_vcl`]
41#[derive(Clone, Debug, Default)]
42pub struct GetCustomVclParams {
43    /// Alphanumeric string identifying the service.
44    pub service_id: String,
45    /// Integer identifying a service version.
46    pub version_id: i32,
47    /// The name of this VCL.
48    pub vcl_name: String,
49    /// Omit VCL content.
50    pub no_content: Option<String>
51}
52
53/// struct for passing parameters to the method [`get_custom_vcl_boilerplate`]
54#[derive(Clone, Debug, Default)]
55pub struct GetCustomVclBoilerplateParams {
56    /// Alphanumeric string identifying the service.
57    pub service_id: String,
58    /// Integer identifying a service version.
59    pub version_id: i32
60}
61
62/// struct for passing parameters to the method [`get_custom_vcl_generated`]
63#[derive(Clone, Debug, Default)]
64pub struct GetCustomVclGeneratedParams {
65    /// Alphanumeric string identifying the service.
66    pub service_id: String,
67    /// Integer identifying a service version.
68    pub version_id: i32
69}
70
71/// struct for passing parameters to the method [`get_custom_vcl_generated_highlighted`]
72#[derive(Clone, Debug, Default)]
73pub struct GetCustomVclGeneratedHighlightedParams {
74    /// Alphanumeric string identifying the service.
75    pub service_id: String,
76    /// Integer identifying a service version.
77    pub version_id: i32
78}
79
80/// struct for passing parameters to the method [`get_custom_vcl_highlighted`]
81#[derive(Clone, Debug, Default)]
82pub struct GetCustomVclHighlightedParams {
83    /// Alphanumeric string identifying the service.
84    pub service_id: String,
85    /// Integer identifying a service version.
86    pub version_id: i32,
87    /// The name of this VCL.
88    pub vcl_name: String
89}
90
91/// struct for passing parameters to the method [`get_custom_vcl_raw`]
92#[derive(Clone, Debug, Default)]
93pub struct GetCustomVclRawParams {
94    /// Alphanumeric string identifying the service.
95    pub service_id: String,
96    /// Integer identifying a service version.
97    pub version_id: i32,
98    /// The name of this VCL.
99    pub vcl_name: String
100}
101
102/// struct for passing parameters to the method [`lint_vcl_default`]
103#[derive(Clone, Debug, Default)]
104pub struct LintVclDefaultParams {
105    pub inline_object1: crate::models::InlineObject1
106}
107
108/// struct for passing parameters to the method [`lint_vcl_for_service`]
109#[derive(Clone, Debug, Default)]
110pub struct LintVclForServiceParams {
111    /// Alphanumeric string identifying the service.
112    pub service_id: String,
113    pub inline_object: crate::models::InlineObject
114}
115
116/// struct for passing parameters to the method [`list_custom_vcl`]
117#[derive(Clone, Debug, Default)]
118pub struct ListCustomVclParams {
119    /// Alphanumeric string identifying the service.
120    pub service_id: String,
121    /// Integer identifying a service version.
122    pub version_id: i32
123}
124
125/// struct for passing parameters to the method [`set_custom_vcl_main`]
126#[derive(Clone, Debug, Default)]
127pub struct SetCustomVclMainParams {
128    /// Alphanumeric string identifying the service.
129    pub service_id: String,
130    /// Integer identifying a service version.
131    pub version_id: i32,
132    /// The name of this VCL.
133    pub vcl_name: String
134}
135
136/// struct for passing parameters to the method [`update_custom_vcl`]
137#[derive(Clone, Debug, Default)]
138pub struct UpdateCustomVclParams {
139    /// Alphanumeric string identifying the service.
140    pub service_id: String,
141    /// Integer identifying a service version.
142    pub version_id: i32,
143    /// The name of this VCL.
144    pub vcl_name: String,
145    /// The VCL code to be included.
146    pub content: Option<String>,
147    /// Set to `true` when this is the main VCL, otherwise `false`.
148    pub main: Option<bool>,
149    /// The name of this VCL.
150    pub name: Option<String>
151}
152
153
154/// struct for typed errors of method [`create_custom_vcl`]
155#[derive(Debug, Clone, Serialize, Deserialize)]
156#[serde(untagged)]
157pub enum CreateCustomVclError {
158    UnknownValue(serde_json::Value),
159}
160
161/// struct for typed errors of method [`delete_custom_vcl`]
162#[derive(Debug, Clone, Serialize, Deserialize)]
163#[serde(untagged)]
164pub enum DeleteCustomVclError {
165    UnknownValue(serde_json::Value),
166}
167
168/// struct for typed errors of method [`get_custom_vcl`]
169#[derive(Debug, Clone, Serialize, Deserialize)]
170#[serde(untagged)]
171pub enum GetCustomVclError {
172    UnknownValue(serde_json::Value),
173}
174
175/// struct for typed errors of method [`get_custom_vcl_boilerplate`]
176#[derive(Debug, Clone, Serialize, Deserialize)]
177#[serde(untagged)]
178pub enum GetCustomVclBoilerplateError {
179    UnknownValue(serde_json::Value),
180}
181
182/// struct for typed errors of method [`get_custom_vcl_generated`]
183#[derive(Debug, Clone, Serialize, Deserialize)]
184#[serde(untagged)]
185pub enum GetCustomVclGeneratedError {
186    UnknownValue(serde_json::Value),
187}
188
189/// struct for typed errors of method [`get_custom_vcl_generated_highlighted`]
190#[derive(Debug, Clone, Serialize, Deserialize)]
191#[serde(untagged)]
192pub enum GetCustomVclGeneratedHighlightedError {
193    UnknownValue(serde_json::Value),
194}
195
196/// struct for typed errors of method [`get_custom_vcl_highlighted`]
197#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(untagged)]
199pub enum GetCustomVclHighlightedError {
200    UnknownValue(serde_json::Value),
201}
202
203/// struct for typed errors of method [`get_custom_vcl_raw`]
204#[derive(Debug, Clone, Serialize, Deserialize)]
205#[serde(untagged)]
206pub enum GetCustomVclRawError {
207    UnknownValue(serde_json::Value),
208}
209
210/// struct for typed errors of method [`lint_vcl_default`]
211#[derive(Debug, Clone, Serialize, Deserialize)]
212#[serde(untagged)]
213pub enum LintVclDefaultError {
214    UnknownValue(serde_json::Value),
215}
216
217/// struct for typed errors of method [`lint_vcl_for_service`]
218#[derive(Debug, Clone, Serialize, Deserialize)]
219#[serde(untagged)]
220pub enum LintVclForServiceError {
221    UnknownValue(serde_json::Value),
222}
223
224/// struct for typed errors of method [`list_custom_vcl`]
225#[derive(Debug, Clone, Serialize, Deserialize)]
226#[serde(untagged)]
227pub enum ListCustomVclError {
228    UnknownValue(serde_json::Value),
229}
230
231/// struct for typed errors of method [`set_custom_vcl_main`]
232#[derive(Debug, Clone, Serialize, Deserialize)]
233#[serde(untagged)]
234pub enum SetCustomVclMainError {
235    UnknownValue(serde_json::Value),
236}
237
238/// struct for typed errors of method [`update_custom_vcl`]
239#[derive(Debug, Clone, Serialize, Deserialize)]
240#[serde(untagged)]
241pub enum UpdateCustomVclError {
242    UnknownValue(serde_json::Value),
243}
244
245
246/// Upload a VCL for a particular service and version.
247pub async fn create_custom_vcl(configuration: &mut configuration::Configuration, params: CreateCustomVclParams) -> Result<crate::models::VclResponse, Error<CreateCustomVclError>> {
248    let local_var_configuration = configuration;
249
250    // unbox the parameters
251    let service_id = params.service_id;
252    let version_id = params.version_id;
253    let content = params.content;
254    let main = params.main;
255    let name = params.name;
256
257
258    let local_var_client = &local_var_configuration.client;
259
260    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
261    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
262
263    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
264        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
265    }
266    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
267        let local_var_key = local_var_apikey.key.clone();
268        let local_var_value = match local_var_apikey.prefix {
269            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
270            None => local_var_key,
271        };
272        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
273    };
274    let mut local_var_form_params = std::collections::HashMap::new();
275    if let Some(local_var_param_value) = content {
276        local_var_form_params.insert("content", local_var_param_value.to_string());
277    }
278    if let Some(local_var_param_value) = main {
279        local_var_form_params.insert("main", local_var_param_value.to_string());
280    }
281    if let Some(local_var_param_value) = name {
282        local_var_form_params.insert("name", local_var_param_value.to_string());
283    }
284    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
285
286    let local_var_req = local_var_req_builder.build()?;
287    let local_var_resp = local_var_client.execute(local_var_req).await?;
288
289    if "POST" != "GET" && "POST" != "HEAD" {
290      let headers = local_var_resp.headers();
291      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
292          Some(v) => v.to_str().unwrap().parse().unwrap(),
293          None => configuration::DEFAULT_RATELIMIT,
294      };
295      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
296          Some(v) => v.to_str().unwrap().parse().unwrap(),
297          None => 0,
298      };
299    }
300
301    let local_var_status = local_var_resp.status();
302    let local_var_content = local_var_resp.text().await?;
303
304    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
305        serde_json::from_str(&local_var_content).map_err(Error::from)
306    } else {
307        let local_var_entity: Option<CreateCustomVclError> = serde_json::from_str(&local_var_content).ok();
308        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
309        Err(Error::ResponseError(local_var_error))
310    }
311}
312
313/// Delete the uploaded VCL for a particular service and version.
314pub async fn delete_custom_vcl(configuration: &mut configuration::Configuration, params: DeleteCustomVclParams) -> Result<crate::models::InlineResponse200, Error<DeleteCustomVclError>> {
315    let local_var_configuration = configuration;
316
317    // unbox the parameters
318    let service_id = params.service_id;
319    let version_id = params.version_id;
320    let vcl_name = params.vcl_name;
321
322
323    let local_var_client = &local_var_configuration.client;
324
325    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
326    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
327
328    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
329        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
330    }
331    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
332        let local_var_key = local_var_apikey.key.clone();
333        let local_var_value = match local_var_apikey.prefix {
334            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
335            None => local_var_key,
336        };
337        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
338    };
339
340    let local_var_req = local_var_req_builder.build()?;
341    let local_var_resp = local_var_client.execute(local_var_req).await?;
342
343    if "DELETE" != "GET" && "DELETE" != "HEAD" {
344      let headers = local_var_resp.headers();
345      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
346          Some(v) => v.to_str().unwrap().parse().unwrap(),
347          None => configuration::DEFAULT_RATELIMIT,
348      };
349      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
350          Some(v) => v.to_str().unwrap().parse().unwrap(),
351          None => 0,
352      };
353    }
354
355    let local_var_status = local_var_resp.status();
356    let local_var_content = local_var_resp.text().await?;
357
358    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
359        serde_json::from_str(&local_var_content).map_err(Error::from)
360    } else {
361        let local_var_entity: Option<DeleteCustomVclError> = serde_json::from_str(&local_var_content).ok();
362        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
363        Err(Error::ResponseError(local_var_error))
364    }
365}
366
367/// Get the uploaded VCL for a particular service and version.
368pub async fn get_custom_vcl(configuration: &mut configuration::Configuration, params: GetCustomVclParams) -> Result<crate::models::VclResponse, Error<GetCustomVclError>> {
369    let local_var_configuration = configuration;
370
371    // unbox the parameters
372    let service_id = params.service_id;
373    let version_id = params.version_id;
374    let vcl_name = params.vcl_name;
375    let no_content = params.no_content;
376
377
378    let local_var_client = &local_var_configuration.client;
379
380    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
381    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
382
383    if let Some(ref local_var_str) = no_content {
384        local_var_req_builder = local_var_req_builder.query(&[("no_content", &local_var_str.to_string())]);
385    }
386    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
387        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
388    }
389    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
390        let local_var_key = local_var_apikey.key.clone();
391        let local_var_value = match local_var_apikey.prefix {
392            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
393            None => local_var_key,
394        };
395        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
396    };
397
398    let local_var_req = local_var_req_builder.build()?;
399    let local_var_resp = local_var_client.execute(local_var_req).await?;
400
401    if "GET" != "GET" && "GET" != "HEAD" {
402      let headers = local_var_resp.headers();
403      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
404          Some(v) => v.to_str().unwrap().parse().unwrap(),
405          None => configuration::DEFAULT_RATELIMIT,
406      };
407      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
408          Some(v) => v.to_str().unwrap().parse().unwrap(),
409          None => 0,
410      };
411    }
412
413    let local_var_status = local_var_resp.status();
414    let local_var_content = local_var_resp.text().await?;
415
416    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
417        serde_json::from_str(&local_var_content).map_err(Error::from)
418    } else {
419        let local_var_entity: Option<GetCustomVclError> = serde_json::from_str(&local_var_content).ok();
420        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
421        Err(Error::ResponseError(local_var_error))
422    }
423}
424
425/// Return boilerplate VCL with the service's TTL from the [settings](https://www.fastly.com/documentation/reference/api/vcl-services/settings/).
426pub async fn get_custom_vcl_boilerplate(configuration: &mut configuration::Configuration, params: GetCustomVclBoilerplateParams) -> Result<String, Error<GetCustomVclBoilerplateError>> {
427    let local_var_configuration = configuration;
428
429    // unbox the parameters
430    let service_id = params.service_id;
431    let version_id = params.version_id;
432
433
434    let local_var_client = &local_var_configuration.client;
435
436    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/boilerplate", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
437    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
438
439    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
440        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
441    }
442    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
443        let local_var_key = local_var_apikey.key.clone();
444        let local_var_value = match local_var_apikey.prefix {
445            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
446            None => local_var_key,
447        };
448        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
449    };
450
451    let local_var_req = local_var_req_builder.build()?;
452    let local_var_resp = local_var_client.execute(local_var_req).await?;
453
454    if "GET" != "GET" && "GET" != "HEAD" {
455      let headers = local_var_resp.headers();
456      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
457          Some(v) => v.to_str().unwrap().parse().unwrap(),
458          None => configuration::DEFAULT_RATELIMIT,
459      };
460      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
461          Some(v) => v.to_str().unwrap().parse().unwrap(),
462          None => 0,
463      };
464    }
465
466    let local_var_status = local_var_resp.status();
467    let local_var_content = local_var_resp.text().await?;
468
469    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
470        serde_json::from_str(&local_var_content).map_err(Error::from)
471    } else {
472        let local_var_entity: Option<GetCustomVclBoilerplateError> = serde_json::from_str(&local_var_content).ok();
473        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
474        Err(Error::ResponseError(local_var_error))
475    }
476}
477
478/// Display the generated VCL for a particular service and version.
479pub async fn get_custom_vcl_generated(configuration: &mut configuration::Configuration, params: GetCustomVclGeneratedParams) -> Result<crate::models::VclResponse, Error<GetCustomVclGeneratedError>> {
480    let local_var_configuration = configuration;
481
482    // unbox the parameters
483    let service_id = params.service_id;
484    let version_id = params.version_id;
485
486
487    let local_var_client = &local_var_configuration.client;
488
489    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/generated_vcl", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
490    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
491
492    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
493        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
494    }
495    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
496        let local_var_key = local_var_apikey.key.clone();
497        let local_var_value = match local_var_apikey.prefix {
498            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
499            None => local_var_key,
500        };
501        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
502    };
503
504    let local_var_req = local_var_req_builder.build()?;
505    let local_var_resp = local_var_client.execute(local_var_req).await?;
506
507    if "GET" != "GET" && "GET" != "HEAD" {
508      let headers = local_var_resp.headers();
509      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
510          Some(v) => v.to_str().unwrap().parse().unwrap(),
511          None => configuration::DEFAULT_RATELIMIT,
512      };
513      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
514          Some(v) => v.to_str().unwrap().parse().unwrap(),
515          None => 0,
516      };
517    }
518
519    let local_var_status = local_var_resp.status();
520    let local_var_content = local_var_resp.text().await?;
521
522    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
523        serde_json::from_str(&local_var_content).map_err(Error::from)
524    } else {
525        let local_var_entity: Option<GetCustomVclGeneratedError> = serde_json::from_str(&local_var_content).ok();
526        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
527        Err(Error::ResponseError(local_var_error))
528    }
529}
530
531/// Display the content of generated VCL with HTML syntax highlighting. Include line numbers by sending `lineno=true` as a request parameter.
532pub async fn get_custom_vcl_generated_highlighted(configuration: &mut configuration::Configuration, params: GetCustomVclGeneratedHighlightedParams) -> Result<crate::models::VclSyntaxHighlightingResponse, Error<GetCustomVclGeneratedHighlightedError>> {
533    let local_var_configuration = configuration;
534
535    // unbox the parameters
536    let service_id = params.service_id;
537    let version_id = params.version_id;
538
539
540    let local_var_client = &local_var_configuration.client;
541
542    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/generated_vcl/content", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
543    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
544
545    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
546        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
547    }
548    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
549        let local_var_key = local_var_apikey.key.clone();
550        let local_var_value = match local_var_apikey.prefix {
551            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
552            None => local_var_key,
553        };
554        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
555    };
556
557    let local_var_req = local_var_req_builder.build()?;
558    let local_var_resp = local_var_client.execute(local_var_req).await?;
559
560    if "GET" != "GET" && "GET" != "HEAD" {
561      let headers = local_var_resp.headers();
562      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
563          Some(v) => v.to_str().unwrap().parse().unwrap(),
564          None => configuration::DEFAULT_RATELIMIT,
565      };
566      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
567          Some(v) => v.to_str().unwrap().parse().unwrap(),
568          None => 0,
569      };
570    }
571
572    let local_var_status = local_var_resp.status();
573    let local_var_content = local_var_resp.text().await?;
574
575    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
576        serde_json::from_str(&local_var_content).map_err(Error::from)
577    } else {
578        let local_var_entity: Option<GetCustomVclGeneratedHighlightedError> = serde_json::from_str(&local_var_content).ok();
579        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
580        Err(Error::ResponseError(local_var_error))
581    }
582}
583
584/// Get the uploaded VCL for a particular service and version with HTML syntax highlighting. Include line numbers by sending `lineno=true` as a request parameter.
585pub async fn get_custom_vcl_highlighted(configuration: &mut configuration::Configuration, params: GetCustomVclHighlightedParams) -> Result<crate::models::VclSyntaxHighlightingResponse, Error<GetCustomVclHighlightedError>> {
586    let local_var_configuration = configuration;
587
588    // unbox the parameters
589    let service_id = params.service_id;
590    let version_id = params.version_id;
591    let vcl_name = params.vcl_name;
592
593
594    let local_var_client = &local_var_configuration.client;
595
596    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}/content", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
597    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
598
599    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
600        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
601    }
602    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
603        let local_var_key = local_var_apikey.key.clone();
604        let local_var_value = match local_var_apikey.prefix {
605            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
606            None => local_var_key,
607        };
608        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
609    };
610
611    let local_var_req = local_var_req_builder.build()?;
612    let local_var_resp = local_var_client.execute(local_var_req).await?;
613
614    if "GET" != "GET" && "GET" != "HEAD" {
615      let headers = local_var_resp.headers();
616      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
617          Some(v) => v.to_str().unwrap().parse().unwrap(),
618          None => configuration::DEFAULT_RATELIMIT,
619      };
620      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
621          Some(v) => v.to_str().unwrap().parse().unwrap(),
622          None => 0,
623      };
624    }
625
626    let local_var_status = local_var_resp.status();
627    let local_var_content = local_var_resp.text().await?;
628
629    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
630        serde_json::from_str(&local_var_content).map_err(Error::from)
631    } else {
632        let local_var_entity: Option<GetCustomVclHighlightedError> = serde_json::from_str(&local_var_content).ok();
633        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
634        Err(Error::ResponseError(local_var_error))
635    }
636}
637
638/// Download the specified VCL.
639pub async fn get_custom_vcl_raw(configuration: &mut configuration::Configuration, params: GetCustomVclRawParams) -> Result<String, Error<GetCustomVclRawError>> {
640    let local_var_configuration = configuration;
641
642    // unbox the parameters
643    let service_id = params.service_id;
644    let version_id = params.version_id;
645    let vcl_name = params.vcl_name;
646
647
648    let local_var_client = &local_var_configuration.client;
649
650    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}/download", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
651    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
652
653    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
654        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
655    }
656    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
657        let local_var_key = local_var_apikey.key.clone();
658        let local_var_value = match local_var_apikey.prefix {
659            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
660            None => local_var_key,
661        };
662        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
663    };
664
665    let local_var_req = local_var_req_builder.build()?;
666    let local_var_resp = local_var_client.execute(local_var_req).await?;
667
668    if "GET" != "GET" && "GET" != "HEAD" {
669      let headers = local_var_resp.headers();
670      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
671          Some(v) => v.to_str().unwrap().parse().unwrap(),
672          None => configuration::DEFAULT_RATELIMIT,
673      };
674      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
675          Some(v) => v.to_str().unwrap().parse().unwrap(),
676          None => 0,
677      };
678    }
679
680    let local_var_status = local_var_resp.status();
681    let local_var_content = local_var_resp.text().await?;
682
683    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
684        serde_json::from_str(&local_var_content).map_err(Error::from)
685    } else {
686        let local_var_entity: Option<GetCustomVclRawError> = serde_json::from_str(&local_var_content).ok();
687        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
688        Err(Error::ResponseError(local_var_error))
689    }
690}
691
692/// This endpoint validates the submitted VCL against a default set of enabled flags. Consider using the `/service/{service_id}/lint` operation to validate VCL in the context of a specific service.
693pub async fn lint_vcl_default(configuration: &mut configuration::Configuration, params: LintVclDefaultParams) -> Result<crate::models::ValidatorResult, Error<LintVclDefaultError>> {
694    let local_var_configuration = configuration;
695
696    // unbox the parameters
697    let inline_object1 = params.inline_object1;
698
699
700    let local_var_client = &local_var_configuration.client;
701
702    let local_var_uri_str = format!("{}/vcl_lint", local_var_configuration.base_path);
703    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
704
705    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
706        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
707    }
708    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
709        let local_var_key = local_var_apikey.key.clone();
710        let local_var_value = match local_var_apikey.prefix {
711            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
712            None => local_var_key,
713        };
714        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
715    };
716    local_var_req_builder = local_var_req_builder.json(&inline_object1);
717
718    let local_var_req = local_var_req_builder.build()?;
719    let local_var_resp = local_var_client.execute(local_var_req).await?;
720
721    if "POST" != "GET" && "POST" != "HEAD" {
722      let headers = local_var_resp.headers();
723      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
724          Some(v) => v.to_str().unwrap().parse().unwrap(),
725          None => configuration::DEFAULT_RATELIMIT,
726      };
727      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
728          Some(v) => v.to_str().unwrap().parse().unwrap(),
729          None => 0,
730      };
731    }
732
733    let local_var_status = local_var_resp.status();
734    let local_var_content = local_var_resp.text().await?;
735
736    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
737        serde_json::from_str(&local_var_content).map_err(Error::from)
738    } else {
739        let local_var_entity: Option<LintVclDefaultError> = serde_json::from_str(&local_var_content).ok();
740        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
741        Err(Error::ResponseError(local_var_error))
742    }
743}
744
745/// Services may have flags set by a Fastly employee or by the purchase of products as addons to the service, which modify the way VCL is interpreted by that service.  This endpoint validates the submitted VCL in the context of the specified service.
746pub async fn lint_vcl_for_service(configuration: &mut configuration::Configuration, params: LintVclForServiceParams) -> Result<crate::models::ValidatorResult, Error<LintVclForServiceError>> {
747    let local_var_configuration = configuration;
748
749    // unbox the parameters
750    let service_id = params.service_id;
751    let inline_object = params.inline_object;
752
753
754    let local_var_client = &local_var_configuration.client;
755
756    let local_var_uri_str = format!("{}/service/{service_id}/lint", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
757    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
758
759    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
760        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
761    }
762    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
763        let local_var_key = local_var_apikey.key.clone();
764        let local_var_value = match local_var_apikey.prefix {
765            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
766            None => local_var_key,
767        };
768        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
769    };
770    local_var_req_builder = local_var_req_builder.json(&inline_object);
771
772    let local_var_req = local_var_req_builder.build()?;
773    let local_var_resp = local_var_client.execute(local_var_req).await?;
774
775    if "POST" != "GET" && "POST" != "HEAD" {
776      let headers = local_var_resp.headers();
777      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
778          Some(v) => v.to_str().unwrap().parse().unwrap(),
779          None => configuration::DEFAULT_RATELIMIT,
780      };
781      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
782          Some(v) => v.to_str().unwrap().parse().unwrap(),
783          None => 0,
784      };
785    }
786
787    let local_var_status = local_var_resp.status();
788    let local_var_content = local_var_resp.text().await?;
789
790    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
791        serde_json::from_str(&local_var_content).map_err(Error::from)
792    } else {
793        let local_var_entity: Option<LintVclForServiceError> = serde_json::from_str(&local_var_content).ok();
794        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
795        Err(Error::ResponseError(local_var_error))
796    }
797}
798
799/// List the uploaded VCLs for a particular service and version.
800pub async fn list_custom_vcl(configuration: &mut configuration::Configuration, params: ListCustomVclParams) -> Result<Vec<crate::models::VclResponse>, Error<ListCustomVclError>> {
801    let local_var_configuration = configuration;
802
803    // unbox the parameters
804    let service_id = params.service_id;
805    let version_id = params.version_id;
806
807
808    let local_var_client = &local_var_configuration.client;
809
810    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
811    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
812
813    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
814        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
815    }
816    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
817        let local_var_key = local_var_apikey.key.clone();
818        let local_var_value = match local_var_apikey.prefix {
819            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
820            None => local_var_key,
821        };
822        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
823    };
824
825    let local_var_req = local_var_req_builder.build()?;
826    let local_var_resp = local_var_client.execute(local_var_req).await?;
827
828    if "GET" != "GET" && "GET" != "HEAD" {
829      let headers = local_var_resp.headers();
830      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
831          Some(v) => v.to_str().unwrap().parse().unwrap(),
832          None => configuration::DEFAULT_RATELIMIT,
833      };
834      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
835          Some(v) => v.to_str().unwrap().parse().unwrap(),
836          None => 0,
837      };
838    }
839
840    let local_var_status = local_var_resp.status();
841    let local_var_content = local_var_resp.text().await?;
842
843    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
844        serde_json::from_str(&local_var_content).map_err(Error::from)
845    } else {
846        let local_var_entity: Option<ListCustomVclError> = serde_json::from_str(&local_var_content).ok();
847        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
848        Err(Error::ResponseError(local_var_error))
849    }
850}
851
852/// Set the specified VCL as the main.
853pub async fn set_custom_vcl_main(configuration: &mut configuration::Configuration, params: SetCustomVclMainParams) -> Result<crate::models::VclResponse, Error<SetCustomVclMainError>> {
854    let local_var_configuration = configuration;
855
856    // unbox the parameters
857    let service_id = params.service_id;
858    let version_id = params.version_id;
859    let vcl_name = params.vcl_name;
860
861
862    let local_var_client = &local_var_configuration.client;
863
864    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}/main", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
865    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
866
867    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
868        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
869    }
870    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
871        let local_var_key = local_var_apikey.key.clone();
872        let local_var_value = match local_var_apikey.prefix {
873            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
874            None => local_var_key,
875        };
876        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
877    };
878
879    let local_var_req = local_var_req_builder.build()?;
880    let local_var_resp = local_var_client.execute(local_var_req).await?;
881
882    if "PUT" != "GET" && "PUT" != "HEAD" {
883      let headers = local_var_resp.headers();
884      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
885          Some(v) => v.to_str().unwrap().parse().unwrap(),
886          None => configuration::DEFAULT_RATELIMIT,
887      };
888      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
889          Some(v) => v.to_str().unwrap().parse().unwrap(),
890          None => 0,
891      };
892    }
893
894    let local_var_status = local_var_resp.status();
895    let local_var_content = local_var_resp.text().await?;
896
897    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
898        serde_json::from_str(&local_var_content).map_err(Error::from)
899    } else {
900        let local_var_entity: Option<SetCustomVclMainError> = serde_json::from_str(&local_var_content).ok();
901        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
902        Err(Error::ResponseError(local_var_error))
903    }
904}
905
906/// Update the uploaded VCL for a particular service and version.
907pub async fn update_custom_vcl(configuration: &mut configuration::Configuration, params: UpdateCustomVclParams) -> Result<crate::models::VclResponse, Error<UpdateCustomVclError>> {
908    let local_var_configuration = configuration;
909
910    // unbox the parameters
911    let service_id = params.service_id;
912    let version_id = params.version_id;
913    let vcl_name = params.vcl_name;
914    let content = params.content;
915    let main = params.main;
916    let name = params.name;
917
918
919    let local_var_client = &local_var_configuration.client;
920
921    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/vcl/{vcl_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, vcl_name=crate::apis::urlencode(vcl_name));
922    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
923
924    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
925        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
926    }
927    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
928        let local_var_key = local_var_apikey.key.clone();
929        let local_var_value = match local_var_apikey.prefix {
930            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
931            None => local_var_key,
932        };
933        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
934    };
935    let mut local_var_form_params = std::collections::HashMap::new();
936    if let Some(local_var_param_value) = content {
937        local_var_form_params.insert("content", local_var_param_value.to_string());
938    }
939    if let Some(local_var_param_value) = main {
940        local_var_form_params.insert("main", local_var_param_value.to_string());
941    }
942    if let Some(local_var_param_value) = name {
943        local_var_form_params.insert("name", local_var_param_value.to_string());
944    }
945    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
946
947    let local_var_req = local_var_req_builder.build()?;
948    let local_var_resp = local_var_client.execute(local_var_req).await?;
949
950    if "PUT" != "GET" && "PUT" != "HEAD" {
951      let headers = local_var_resp.headers();
952      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
953          Some(v) => v.to_str().unwrap().parse().unwrap(),
954          None => configuration::DEFAULT_RATELIMIT,
955      };
956      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
957          Some(v) => v.to_str().unwrap().parse().unwrap(),
958          None => 0,
959      };
960    }
961
962    let local_var_status = local_var_resp.status();
963    let local_var_content = local_var_resp.text().await?;
964
965    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
966        serde_json::from_str(&local_var_content).map_err(Error::from)
967    } else {
968        let local_var_entity: Option<UpdateCustomVclError> = serde_json::from_str(&local_var_content).ok();
969        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
970        Err(Error::ResponseError(local_var_error))
971    }
972}
973