fastly_api/apis/
logging_papertrail_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_log_papertrail`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateLogPapertrailParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    /// The name for the real-time logging configuration.
22    pub name: Option<String>,
23    /// Where in the generated VCL the logging call should be placed. If not set, endpoints with `format_version` of 2 are placed in `vcl_log` and those with `format_version` of 1 are placed in `vcl_deliver`. 
24    pub placement: Option<String>,
25    /// The name of an existing condition in the configured endpoint, or leave blank to always execute.
26    pub response_condition: Option<String>,
27    /// A Fastly [log format string](https://docs.fastly.com/en/guides/custom-log-formats).
28    pub format: Option<String>,
29    /// The version of the custom logging format used for the configured endpoint. The logging call gets placed by default in `vcl_log` if `format_version` is set to `2` and in `vcl_deliver` if `format_version` is set to `1`. 
30    pub format_version: Option<i32>,
31    /// A hostname or IPv4 address.
32    pub address: Option<String>,
33    /// The port number.
34    pub port: Option<i32>
35}
36
37/// struct for passing parameters to the method [`delete_log_papertrail`]
38#[derive(Clone, Debug, Default)]
39pub struct DeleteLogPapertrailParams {
40    /// Alphanumeric string identifying the service.
41    pub service_id: String,
42    /// Integer identifying a service version.
43    pub version_id: i32,
44    /// The name for the real-time logging configuration.
45    pub logging_papertrail_name: String
46}
47
48/// struct for passing parameters to the method [`get_log_papertrail`]
49#[derive(Clone, Debug, Default)]
50pub struct GetLogPapertrailParams {
51    /// Alphanumeric string identifying the service.
52    pub service_id: String,
53    /// Integer identifying a service version.
54    pub version_id: i32,
55    /// The name for the real-time logging configuration.
56    pub logging_papertrail_name: String
57}
58
59/// struct for passing parameters to the method [`list_log_papertrail`]
60#[derive(Clone, Debug, Default)]
61pub struct ListLogPapertrailParams {
62    /// Alphanumeric string identifying the service.
63    pub service_id: String,
64    /// Integer identifying a service version.
65    pub version_id: i32
66}
67
68/// struct for passing parameters to the method [`update_log_papertrail`]
69#[derive(Clone, Debug, Default)]
70pub struct UpdateLogPapertrailParams {
71    /// Alphanumeric string identifying the service.
72    pub service_id: String,
73    /// Integer identifying a service version.
74    pub version_id: i32,
75    /// The name for the real-time logging configuration.
76    pub logging_papertrail_name: String,
77    /// The name for the real-time logging configuration.
78    pub name: Option<String>,
79    /// Where in the generated VCL the logging call should be placed. If not set, endpoints with `format_version` of 2 are placed in `vcl_log` and those with `format_version` of 1 are placed in `vcl_deliver`. 
80    pub placement: Option<String>,
81    /// The name of an existing condition in the configured endpoint, or leave blank to always execute.
82    pub response_condition: Option<String>,
83    /// A Fastly [log format string](https://docs.fastly.com/en/guides/custom-log-formats).
84    pub format: Option<String>,
85    /// The version of the custom logging format used for the configured endpoint. The logging call gets placed by default in `vcl_log` if `format_version` is set to `2` and in `vcl_deliver` if `format_version` is set to `1`. 
86    pub format_version: Option<i32>,
87    /// A hostname or IPv4 address.
88    pub address: Option<String>,
89    /// The port number.
90    pub port: Option<i32>
91}
92
93
94/// struct for typed errors of method [`create_log_papertrail`]
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(untagged)]
97pub enum CreateLogPapertrailError {
98    UnknownValue(serde_json::Value),
99}
100
101/// struct for typed errors of method [`delete_log_papertrail`]
102#[derive(Debug, Clone, Serialize, Deserialize)]
103#[serde(untagged)]
104pub enum DeleteLogPapertrailError {
105    UnknownValue(serde_json::Value),
106}
107
108/// struct for typed errors of method [`get_log_papertrail`]
109#[derive(Debug, Clone, Serialize, Deserialize)]
110#[serde(untagged)]
111pub enum GetLogPapertrailError {
112    UnknownValue(serde_json::Value),
113}
114
115/// struct for typed errors of method [`list_log_papertrail`]
116#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum ListLogPapertrailError {
119    UnknownValue(serde_json::Value),
120}
121
122/// struct for typed errors of method [`update_log_papertrail`]
123#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum UpdateLogPapertrailError {
126    UnknownValue(serde_json::Value),
127}
128
129
130/// Create a Papertrail for a particular service and version.
131pub async fn create_log_papertrail(configuration: &mut configuration::Configuration, params: CreateLogPapertrailParams) -> Result<crate::models::LoggingPapertrailResponse, Error<CreateLogPapertrailError>> {
132    let local_var_configuration = configuration;
133
134    // unbox the parameters
135    let service_id = params.service_id;
136    let version_id = params.version_id;
137    let name = params.name;
138    let placement = params.placement;
139    let response_condition = params.response_condition;
140    let format = params.format;
141    let format_version = params.format_version;
142    let address = params.address;
143    let port = params.port;
144
145
146    let local_var_client = &local_var_configuration.client;
147
148    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/papertrail", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
149    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
150
151    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
152        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
153    }
154    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
155        let local_var_key = local_var_apikey.key.clone();
156        let local_var_value = match local_var_apikey.prefix {
157            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
158            None => local_var_key,
159        };
160        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
161    };
162    let mut local_var_form_params = std::collections::HashMap::new();
163    if let Some(local_var_param_value) = name {
164        local_var_form_params.insert("name", local_var_param_value.to_string());
165    }
166    if let Some(local_var_param_value) = placement {
167        local_var_form_params.insert("placement", local_var_param_value.to_string());
168    }
169    if let Some(local_var_param_value) = response_condition {
170        local_var_form_params.insert("response_condition", local_var_param_value.to_string());
171    }
172    if let Some(local_var_param_value) = format {
173        local_var_form_params.insert("format", local_var_param_value.to_string());
174    }
175    if let Some(local_var_param_value) = format_version {
176        local_var_form_params.insert("format_version", local_var_param_value.to_string());
177    }
178    if let Some(local_var_param_value) = address {
179        local_var_form_params.insert("address", local_var_param_value.to_string());
180    }
181    if let Some(local_var_param_value) = port {
182        local_var_form_params.insert("port", local_var_param_value.to_string());
183    }
184    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
185
186    let local_var_req = local_var_req_builder.build()?;
187    let local_var_resp = local_var_client.execute(local_var_req).await?;
188
189    if "POST" != "GET" && "POST" != "HEAD" {
190      let headers = local_var_resp.headers();
191      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
192          Some(v) => v.to_str().unwrap().parse().unwrap(),
193          None => configuration::DEFAULT_RATELIMIT,
194      };
195      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
196          Some(v) => v.to_str().unwrap().parse().unwrap(),
197          None => 0,
198      };
199    }
200
201    let local_var_status = local_var_resp.status();
202    let local_var_content = local_var_resp.text().await?;
203
204    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
205        serde_json::from_str(&local_var_content).map_err(Error::from)
206    } else {
207        let local_var_entity: Option<CreateLogPapertrailError> = serde_json::from_str(&local_var_content).ok();
208        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
209        Err(Error::ResponseError(local_var_error))
210    }
211}
212
213/// Delete the Papertrail for a particular service and version.
214pub async fn delete_log_papertrail(configuration: &mut configuration::Configuration, params: DeleteLogPapertrailParams) -> Result<crate::models::InlineResponse200, Error<DeleteLogPapertrailError>> {
215    let local_var_configuration = configuration;
216
217    // unbox the parameters
218    let service_id = params.service_id;
219    let version_id = params.version_id;
220    let logging_papertrail_name = params.logging_papertrail_name;
221
222
223    let local_var_client = &local_var_configuration.client;
224
225    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/papertrail/{logging_papertrail_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, logging_papertrail_name=crate::apis::urlencode(logging_papertrail_name));
226    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
227
228    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
229        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
230    }
231    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
232        let local_var_key = local_var_apikey.key.clone();
233        let local_var_value = match local_var_apikey.prefix {
234            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
235            None => local_var_key,
236        };
237        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
238    };
239
240    let local_var_req = local_var_req_builder.build()?;
241    let local_var_resp = local_var_client.execute(local_var_req).await?;
242
243    if "DELETE" != "GET" && "DELETE" != "HEAD" {
244      let headers = local_var_resp.headers();
245      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
246          Some(v) => v.to_str().unwrap().parse().unwrap(),
247          None => configuration::DEFAULT_RATELIMIT,
248      };
249      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
250          Some(v) => v.to_str().unwrap().parse().unwrap(),
251          None => 0,
252      };
253    }
254
255    let local_var_status = local_var_resp.status();
256    let local_var_content = local_var_resp.text().await?;
257
258    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
259        serde_json::from_str(&local_var_content).map_err(Error::from)
260    } else {
261        let local_var_entity: Option<DeleteLogPapertrailError> = serde_json::from_str(&local_var_content).ok();
262        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
263        Err(Error::ResponseError(local_var_error))
264    }
265}
266
267/// Get the Papertrail for a particular service and version.
268pub async fn get_log_papertrail(configuration: &mut configuration::Configuration, params: GetLogPapertrailParams) -> Result<crate::models::LoggingPapertrailResponse, Error<GetLogPapertrailError>> {
269    let local_var_configuration = configuration;
270
271    // unbox the parameters
272    let service_id = params.service_id;
273    let version_id = params.version_id;
274    let logging_papertrail_name = params.logging_papertrail_name;
275
276
277    let local_var_client = &local_var_configuration.client;
278
279    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/papertrail/{logging_papertrail_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, logging_papertrail_name=crate::apis::urlencode(logging_papertrail_name));
280    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
281
282    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
283        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
284    }
285    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
286        let local_var_key = local_var_apikey.key.clone();
287        let local_var_value = match local_var_apikey.prefix {
288            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
289            None => local_var_key,
290        };
291        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
292    };
293
294    let local_var_req = local_var_req_builder.build()?;
295    let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297    if "GET" != "GET" && "GET" != "HEAD" {
298      let headers = local_var_resp.headers();
299      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
300          Some(v) => v.to_str().unwrap().parse().unwrap(),
301          None => configuration::DEFAULT_RATELIMIT,
302      };
303      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
304          Some(v) => v.to_str().unwrap().parse().unwrap(),
305          None => 0,
306      };
307    }
308
309    let local_var_status = local_var_resp.status();
310    let local_var_content = local_var_resp.text().await?;
311
312    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
313        serde_json::from_str(&local_var_content).map_err(Error::from)
314    } else {
315        let local_var_entity: Option<GetLogPapertrailError> = serde_json::from_str(&local_var_content).ok();
316        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
317        Err(Error::ResponseError(local_var_error))
318    }
319}
320
321/// List all of the Papertrails for a particular service and version.
322pub async fn list_log_papertrail(configuration: &mut configuration::Configuration, params: ListLogPapertrailParams) -> Result<Vec<crate::models::LoggingPapertrailResponse>, Error<ListLogPapertrailError>> {
323    let local_var_configuration = configuration;
324
325    // unbox the parameters
326    let service_id = params.service_id;
327    let version_id = params.version_id;
328
329
330    let local_var_client = &local_var_configuration.client;
331
332    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/papertrail", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
333    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
334
335    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
336        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
337    }
338    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
339        let local_var_key = local_var_apikey.key.clone();
340        let local_var_value = match local_var_apikey.prefix {
341            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
342            None => local_var_key,
343        };
344        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
345    };
346
347    let local_var_req = local_var_req_builder.build()?;
348    let local_var_resp = local_var_client.execute(local_var_req).await?;
349
350    if "GET" != "GET" && "GET" != "HEAD" {
351      let headers = local_var_resp.headers();
352      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
353          Some(v) => v.to_str().unwrap().parse().unwrap(),
354          None => configuration::DEFAULT_RATELIMIT,
355      };
356      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
357          Some(v) => v.to_str().unwrap().parse().unwrap(),
358          None => 0,
359      };
360    }
361
362    let local_var_status = local_var_resp.status();
363    let local_var_content = local_var_resp.text().await?;
364
365    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
366        serde_json::from_str(&local_var_content).map_err(Error::from)
367    } else {
368        let local_var_entity: Option<ListLogPapertrailError> = serde_json::from_str(&local_var_content).ok();
369        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
370        Err(Error::ResponseError(local_var_error))
371    }
372}
373
374/// Update the Papertrail for a particular service and version.
375pub async fn update_log_papertrail(configuration: &mut configuration::Configuration, params: UpdateLogPapertrailParams) -> Result<crate::models::LoggingPapertrailResponse, Error<UpdateLogPapertrailError>> {
376    let local_var_configuration = configuration;
377
378    // unbox the parameters
379    let service_id = params.service_id;
380    let version_id = params.version_id;
381    let logging_papertrail_name = params.logging_papertrail_name;
382    let name = params.name;
383    let placement = params.placement;
384    let response_condition = params.response_condition;
385    let format = params.format;
386    let format_version = params.format_version;
387    let address = params.address;
388    let port = params.port;
389
390
391    let local_var_client = &local_var_configuration.client;
392
393    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/papertrail/{logging_papertrail_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, logging_papertrail_name=crate::apis::urlencode(logging_papertrail_name));
394    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
395
396    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
397        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
398    }
399    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
400        let local_var_key = local_var_apikey.key.clone();
401        let local_var_value = match local_var_apikey.prefix {
402            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
403            None => local_var_key,
404        };
405        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
406    };
407    let mut local_var_form_params = std::collections::HashMap::new();
408    if let Some(local_var_param_value) = name {
409        local_var_form_params.insert("name", local_var_param_value.to_string());
410    }
411    if let Some(local_var_param_value) = placement {
412        local_var_form_params.insert("placement", local_var_param_value.to_string());
413    }
414    if let Some(local_var_param_value) = response_condition {
415        local_var_form_params.insert("response_condition", local_var_param_value.to_string());
416    }
417    if let Some(local_var_param_value) = format {
418        local_var_form_params.insert("format", local_var_param_value.to_string());
419    }
420    if let Some(local_var_param_value) = format_version {
421        local_var_form_params.insert("format_version", local_var_param_value.to_string());
422    }
423    if let Some(local_var_param_value) = address {
424        local_var_form_params.insert("address", local_var_param_value.to_string());
425    }
426    if let Some(local_var_param_value) = port {
427        local_var_form_params.insert("port", local_var_param_value.to_string());
428    }
429    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
430
431    let local_var_req = local_var_req_builder.build()?;
432    let local_var_resp = local_var_client.execute(local_var_req).await?;
433
434    if "PUT" != "GET" && "PUT" != "HEAD" {
435      let headers = local_var_resp.headers();
436      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
437          Some(v) => v.to_str().unwrap().parse().unwrap(),
438          None => configuration::DEFAULT_RATELIMIT,
439      };
440      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
441          Some(v) => v.to_str().unwrap().parse().unwrap(),
442          None => 0,
443      };
444    }
445
446    let local_var_status = local_var_resp.status();
447    let local_var_content = local_var_resp.text().await?;
448
449    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
450        serde_json::from_str(&local_var_content).map_err(Error::from)
451    } else {
452        let local_var_entity: Option<UpdateLogPapertrailError> = serde_json::from_str(&local_var_content).ok();
453        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
454        Err(Error::ResponseError(local_var_error))
455    }
456}
457