Skip to main content

alien_core/app_events/
storage.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5#[cfg(feature = "openapi")]
6use utoipa::ToSchema;
7
8/// Represents the type of storage event that occurred.
9#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
10#[cfg_attr(feature = "openapi", derive(ToSchema))]
11#[serde(rename_all = "camelCase")]
12pub enum StorageEventType {
13    /// An object was created (e.g., uploaded, put).
14    Created,
15    /// An object was deleted.
16    Deleted,
17    /// An object was copied.
18    Copied,
19    /// An object's metadata was updated.
20    MetadataUpdated,
21    /// An object was restored from an archive tier.
22    Restored,
23    /// An object's storage tier was changed.
24    TierChanged,
25    /// An unknown or unsupported storage event type.
26    Unknown,
27}
28
29/// Represents an event triggered by an action in an object storage service.
30///
31/// This struct provides a generic representation for events from services like
32/// AWS S3, Google Cloud Storage (GCS), and Azure Blob Storage.
33#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
34#[cfg_attr(feature = "openapi", derive(ToSchema))]
35#[serde(rename_all = "camelCase")]
36pub struct StorageEvent {
37    /// The type of storage event.
38    pub event_type: StorageEventType,
39
40    /// The name of the bucket or container where the event occurred.
41    pub bucket_name: String,
42
43    /// The key or path of the object involved in the event.
44    pub object_key: String,
45
46    /// The timestamp when the event occurred.
47    pub timestamp: DateTime<Utc>,
48
49    /// Optional size of the object in bytes.
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub size: Option<u64>,
52
53    /// Optional ETag or hash of the object content.
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub etag: Option<String>,
56
57    /// Optional content type (MIME type) of the object.
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub content_type: Option<String>,
60
61    /// Optional metadata associated with the object.
62    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
63    pub metadata: HashMap<String, String>,
64
65    /// Optional information about the source object for copy events.
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub copy_source: Option<String>,
68
69    /// Optional previous storage tier for TierChanged or Restored events.
70    #[serde(skip_serializing_if = "Option::is_none")]
71    pub previous_tier: Option<String>,
72
73    /// Optional current storage tier for TierChanged or Restored events.
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub current_tier: Option<String>,
76
77    /// Optional region where the event originated.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub region: Option<String>,
80
81    /// Optional version or sequencer identifier for the event or object state.
82    #[serde(skip_serializing_if = "Option::is_none")]
83    pub version_id: Option<String>,
84}
85
86/// A wrapper type for a list of storage events.
87#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
88#[cfg_attr(feature = "openapi", derive(ToSchema))]
89#[serde(rename_all = "camelCase")]
90pub struct StorageEvents(pub Vec<StorageEvent>);