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