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