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