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