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