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