fastly_api/apis/
logging_kinesis_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_kinesis`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateLogKinesisParams {
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    pub placement: Option<crate::models::LoggingPlacement>,
24    /// A Fastly [log format string](https://docs.fastly.com/en/guides/custom-log-formats).
25    pub format: Option<String>,
26    /// The Amazon Kinesis stream to send logs to. Required.
27    pub topic: Option<String>,
28    pub region: Option<crate::models::AwsRegion>,
29    /// The secret key associated with the target Amazon Kinesis stream. Not required if `iam_role` is specified.
30    pub secret_key: Option<String>,
31    /// The access key associated with the target Amazon Kinesis stream. Not required if `iam_role` is specified.
32    pub access_key: Option<String>,
33    /// The ARN for an IAM role granting Fastly access to the target Amazon Kinesis stream. Not required if `access_key` and `secret_key` are provided.
34    pub iam_role: Option<String>,
35    /// 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`. 
36    pub format_version: Option<i32>
37}
38
39/// struct for passing parameters to the method [`delete_log_kinesis`]
40#[derive(Clone, Debug, Default)]
41pub struct DeleteLogKinesisParams {
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_kinesis_name: String
48}
49
50/// struct for passing parameters to the method [`get_log_kinesis`]
51#[derive(Clone, Debug, Default)]
52pub struct GetLogKinesisParams {
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_kinesis_name: String
59}
60
61/// struct for passing parameters to the method [`list_log_kinesis`]
62#[derive(Clone, Debug, Default)]
63pub struct ListLogKinesisParams {
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_kinesis`]
71#[derive(Clone, Debug, Default)]
72pub struct UpdateLogKinesisParams {
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_kinesis_name: String
79}
80
81
82/// struct for typed errors of method [`create_log_kinesis`]
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum CreateLogKinesisError {
86    UnknownValue(serde_json::Value),
87}
88
89/// struct for typed errors of method [`delete_log_kinesis`]
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum DeleteLogKinesisError {
93    UnknownValue(serde_json::Value),
94}
95
96/// struct for typed errors of method [`get_log_kinesis`]
97#[derive(Debug, Clone, Serialize, Deserialize)]
98#[serde(untagged)]
99pub enum GetLogKinesisError {
100    UnknownValue(serde_json::Value),
101}
102
103/// struct for typed errors of method [`list_log_kinesis`]
104#[derive(Debug, Clone, Serialize, Deserialize)]
105#[serde(untagged)]
106pub enum ListLogKinesisError {
107    UnknownValue(serde_json::Value),
108}
109
110/// struct for typed errors of method [`update_log_kinesis`]
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum UpdateLogKinesisError {
114    UnknownValue(serde_json::Value),
115}
116
117
118/// Create an Amazon Kinesis Data Streams logging object for a particular service and version.
119pub async fn create_log_kinesis(configuration: &mut configuration::Configuration, params: CreateLogKinesisParams) -> Result<crate::models::LoggingKinesisResponse, Error<CreateLogKinesisError>> {
120    let local_var_configuration = configuration;
121
122    // unbox the parameters
123    let service_id = params.service_id;
124    let version_id = params.version_id;
125    let name = params.name;
126    let placement = params.placement;
127    let format = params.format;
128    let topic = params.topic;
129    let region = params.region;
130    let secret_key = params.secret_key;
131    let access_key = params.access_key;
132    let iam_role = params.iam_role;
133    let format_version = params.format_version;
134
135
136    let local_var_client = &local_var_configuration.client;
137
138    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/kinesis", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
139    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
140
141    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
142        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
143    }
144    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
145        let local_var_key = local_var_apikey.key.clone();
146        let local_var_value = match local_var_apikey.prefix {
147            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
148            None => local_var_key,
149        };
150        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
151    };
152    let mut local_var_form_params = std::collections::HashMap::new();
153    if let Some(local_var_param_value) = name {
154        local_var_form_params.insert("name", local_var_param_value.to_string());
155    }
156    if let Some(local_var_param_value) = placement {
157        local_var_form_params.insert("placement", local_var_param_value.to_string());
158    }
159    if let Some(local_var_param_value) = format {
160        local_var_form_params.insert("format", local_var_param_value.to_string());
161    }
162    if let Some(local_var_param_value) = topic {
163        local_var_form_params.insert("topic", local_var_param_value.to_string());
164    }
165    if let Some(local_var_param_value) = region {
166        local_var_form_params.insert("region", local_var_param_value.to_string());
167    }
168    if let Some(local_var_param_value) = secret_key {
169        local_var_form_params.insert("secret_key", local_var_param_value.to_string());
170    }
171    if let Some(local_var_param_value) = access_key {
172        local_var_form_params.insert("access_key", local_var_param_value.to_string());
173    }
174    if let Some(local_var_param_value) = iam_role {
175        local_var_form_params.insert("iam_role", local_var_param_value.to_string());
176    }
177    if let Some(local_var_param_value) = format_version {
178        local_var_form_params.insert("format_version", local_var_param_value.to_string());
179    }
180    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
181
182    let local_var_req = local_var_req_builder.build()?;
183    let local_var_resp = local_var_client.execute(local_var_req).await?;
184
185    if "POST" != "GET" && "POST" != "HEAD" {
186      let headers = local_var_resp.headers();
187      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
188          Some(v) => v.to_str().unwrap().parse().unwrap(),
189          None => configuration::DEFAULT_RATELIMIT,
190      };
191      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
192          Some(v) => v.to_str().unwrap().parse().unwrap(),
193          None => 0,
194      };
195    }
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        serde_json::from_str(&local_var_content).map_err(Error::from)
202    } else {
203        let local_var_entity: Option<CreateLogKinesisError> = serde_json::from_str(&local_var_content).ok();
204        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205        Err(Error::ResponseError(local_var_error))
206    }
207}
208
209/// Delete an Amazon Kinesis Data Streams logging object for a particular service and version.
210pub async fn delete_log_kinesis(configuration: &mut configuration::Configuration, params: DeleteLogKinesisParams) -> Result<crate::models::InlineResponse200, Error<DeleteLogKinesisError>> {
211    let local_var_configuration = configuration;
212
213    // unbox the parameters
214    let service_id = params.service_id;
215    let version_id = params.version_id;
216    let logging_kinesis_name = params.logging_kinesis_name;
217
218
219    let local_var_client = &local_var_configuration.client;
220
221    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/kinesis/{logging_kinesis_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, logging_kinesis_name=crate::apis::urlencode(logging_kinesis_name));
222    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
223
224    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
225        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
226    }
227    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
228        let local_var_key = local_var_apikey.key.clone();
229        let local_var_value = match local_var_apikey.prefix {
230            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
231            None => local_var_key,
232        };
233        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
234    };
235
236    let local_var_req = local_var_req_builder.build()?;
237    let local_var_resp = local_var_client.execute(local_var_req).await?;
238
239    if "DELETE" != "GET" && "DELETE" != "HEAD" {
240      let headers = local_var_resp.headers();
241      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
242          Some(v) => v.to_str().unwrap().parse().unwrap(),
243          None => configuration::DEFAULT_RATELIMIT,
244      };
245      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
246          Some(v) => v.to_str().unwrap().parse().unwrap(),
247          None => 0,
248      };
249    }
250
251    let local_var_status = local_var_resp.status();
252    let local_var_content = local_var_resp.text().await?;
253
254    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
255        serde_json::from_str(&local_var_content).map_err(Error::from)
256    } else {
257        let local_var_entity: Option<DeleteLogKinesisError> = serde_json::from_str(&local_var_content).ok();
258        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
259        Err(Error::ResponseError(local_var_error))
260    }
261}
262
263/// Get the details for an Amazon Kinesis Data Streams logging object for a particular service and version.
264pub async fn get_log_kinesis(configuration: &mut configuration::Configuration, params: GetLogKinesisParams) -> Result<crate::models::LoggingKinesisResponse, Error<GetLogKinesisError>> {
265    let local_var_configuration = configuration;
266
267    // unbox the parameters
268    let service_id = params.service_id;
269    let version_id = params.version_id;
270    let logging_kinesis_name = params.logging_kinesis_name;
271
272
273    let local_var_client = &local_var_configuration.client;
274
275    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/kinesis/{logging_kinesis_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, logging_kinesis_name=crate::apis::urlencode(logging_kinesis_name));
276    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
277
278    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
279        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
280    }
281    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
282        let local_var_key = local_var_apikey.key.clone();
283        let local_var_value = match local_var_apikey.prefix {
284            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
285            None => local_var_key,
286        };
287        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
288    };
289
290    let local_var_req = local_var_req_builder.build()?;
291    let local_var_resp = local_var_client.execute(local_var_req).await?;
292
293    if "GET" != "GET" && "GET" != "HEAD" {
294      let headers = local_var_resp.headers();
295      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
296          Some(v) => v.to_str().unwrap().parse().unwrap(),
297          None => configuration::DEFAULT_RATELIMIT,
298      };
299      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
300          Some(v) => v.to_str().unwrap().parse().unwrap(),
301          None => 0,
302      };
303    }
304
305    let local_var_status = local_var_resp.status();
306    let local_var_content = local_var_resp.text().await?;
307
308    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
309        serde_json::from_str(&local_var_content).map_err(Error::from)
310    } else {
311        let local_var_entity: Option<GetLogKinesisError> = serde_json::from_str(&local_var_content).ok();
312        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
313        Err(Error::ResponseError(local_var_error))
314    }
315}
316
317/// List all of the Amazon Kinesis Data Streams logging objects for a particular service and version.
318pub async fn list_log_kinesis(configuration: &mut configuration::Configuration, params: ListLogKinesisParams) -> Result<Vec<crate::models::LoggingKinesisResponse>, Error<ListLogKinesisError>> {
319    let local_var_configuration = configuration;
320
321    // unbox the parameters
322    let service_id = params.service_id;
323    let version_id = params.version_id;
324
325
326    let local_var_client = &local_var_configuration.client;
327
328    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/kinesis", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
329    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
330
331    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
332        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
333    }
334    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
335        let local_var_key = local_var_apikey.key.clone();
336        let local_var_value = match local_var_apikey.prefix {
337            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
338            None => local_var_key,
339        };
340        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
341    };
342
343    let local_var_req = local_var_req_builder.build()?;
344    let local_var_resp = local_var_client.execute(local_var_req).await?;
345
346    if "GET" != "GET" && "GET" != "HEAD" {
347      let headers = local_var_resp.headers();
348      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
349          Some(v) => v.to_str().unwrap().parse().unwrap(),
350          None => configuration::DEFAULT_RATELIMIT,
351      };
352      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
353          Some(v) => v.to_str().unwrap().parse().unwrap(),
354          None => 0,
355      };
356    }
357
358    let local_var_status = local_var_resp.status();
359    let local_var_content = local_var_resp.text().await?;
360
361    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
362        serde_json::from_str(&local_var_content).map_err(Error::from)
363    } else {
364        let local_var_entity: Option<ListLogKinesisError> = serde_json::from_str(&local_var_content).ok();
365        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
366        Err(Error::ResponseError(local_var_error))
367    }
368}
369
370/// Update an Amazon Kinesis Data Streams logging object for a particular service and version.
371pub async fn update_log_kinesis(configuration: &mut configuration::Configuration, params: UpdateLogKinesisParams) -> Result<crate::models::LoggingKinesisResponse, Error<UpdateLogKinesisError>> {
372    let local_var_configuration = configuration;
373
374    // unbox the parameters
375    let service_id = params.service_id;
376    let version_id = params.version_id;
377    let logging_kinesis_name = params.logging_kinesis_name;
378
379
380    let local_var_client = &local_var_configuration.client;
381
382    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/logging/kinesis/{logging_kinesis_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, logging_kinesis_name=crate::apis::urlencode(logging_kinesis_name));
383    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
384
385    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
386        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
387    }
388    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
389        let local_var_key = local_var_apikey.key.clone();
390        let local_var_value = match local_var_apikey.prefix {
391            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
392            None => local_var_key,
393        };
394        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
395    };
396
397    let local_var_req = local_var_req_builder.build()?;
398    let local_var_resp = local_var_client.execute(local_var_req).await?;
399
400    if "PUT" != "GET" && "PUT" != "HEAD" {
401      let headers = local_var_resp.headers();
402      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
403          Some(v) => v.to_str().unwrap().parse().unwrap(),
404          None => configuration::DEFAULT_RATELIMIT,
405      };
406      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
407          Some(v) => v.to_str().unwrap().parse().unwrap(),
408          None => 0,
409      };
410    }
411
412    let local_var_status = local_var_resp.status();
413    let local_var_content = local_var_resp.text().await?;
414
415    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
416        serde_json::from_str(&local_var_content).map_err(Error::from)
417    } else {
418        let local_var_entity: Option<UpdateLogKinesisError> = serde_json::from_str(&local_var_content).ok();
419        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
420        Err(Error::ResponseError(local_var_error))
421    }
422}
423