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