google_cloud_storage/http/notifications/
insert.rs

1use std::collections::HashMap;
2
3use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
4
5use crate::http::notifications::{EventType, PayloadFormat};
6use crate::http::Escape;
7
8#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
9pub struct NotificationCreationConfig {
10    /// The Cloud PubSub topic to which this subscription publishes. Formatted as:
11    /// '//pubsub.googleapis.com/projects/{project-identifier}/topics/{my-topic}'
12    pub topic: String,
13    /// If present, only send notifications about listed event types. If empty,
14    /// sent notifications for all event types.
15    pub event_types: Option<Vec<EventType>>,
16    /// An optional list of additional attributes to attach to each Cloud PubSub
17    /// message published for this notification subscription.
18    pub custom_attributes: HashMap<String, String>,
19    /// If present, only apply this notification configuration to object names that
20    /// begin with this prefix.
21    pub object_name_prefix: Option<String>,
22    /// The desired content of the Payload.
23    pub payload_format: PayloadFormat,
24}
25
26/// Request message for InsertNotification.
27#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
28#[serde(rename_all = "camelCase")]
29pub struct InsertNotificationRequest {
30    /// Required. The parent bucket of the notification.
31    pub bucket: String,
32    /// Properties of the notification to be inserted.
33    pub notification: NotificationCreationConfig,
34}
35
36pub(crate) fn build(base_url: &str, client: &Client, req: &InsertNotificationRequest) -> RequestBuilder {
37    let url = format!("{}/b/{}/notificationConfigs", base_url, req.bucket.escape());
38    client.post(url).json(&req.notification)
39}