Skip to main content

alien_core/bindings/
storage.rs

1//! Service-type based storage binding definitions
2
3use super::BindingValue;
4use serde::{Deserialize, Serialize};
5
6/// AWS S3 storage binding configuration
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
9#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
10#[serde(rename_all = "camelCase")]
11pub struct S3StorageBinding {
12    /// The name of the S3 bucket
13    pub bucket_name: BindingValue<String>,
14}
15
16/// Azure Blob Storage binding configuration
17#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
19#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
20#[serde(rename_all = "camelCase")]
21pub struct BlobStorageBinding {
22    /// The name of the storage account
23    pub account_name: BindingValue<String>,
24    /// The name of the container
25    pub container_name: BindingValue<String>,
26}
27
28/// Google Cloud Storage binding configuration
29#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
30#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
31#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
32#[serde(rename_all = "camelCase")]
33pub struct GcsStorageBinding {
34    /// The name of the GCS bucket
35    pub bucket_name: BindingValue<String>,
36}
37
38/// Local filesystem storage binding configuration
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
41#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
42#[serde(rename_all = "camelCase")]
43pub struct LocalStorageBinding {
44    /// The storage directory path (file:// URL or absolute path)
45    pub storage_path: BindingValue<String>,
46}
47
48/// Service-type based storage binding that supports multiple storage providers
49#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
50#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
51#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
52#[serde(tag = "service", rename_all = "lowercase")]
53pub enum StorageBinding {
54    /// AWS S3
55    S3(S3StorageBinding),
56    /// Azure Blob Storage
57    Blob(BlobStorageBinding),
58    /// Google Cloud Storage
59    Gcs(GcsStorageBinding),
60    /// Local filesystem storage
61    #[serde(rename = "local-storage")]
62    Local(LocalStorageBinding),
63}
64
65impl StorageBinding {
66    /// Creates an S3 storage binding
67    pub fn s3(bucket_name: impl Into<BindingValue<String>>) -> Self {
68        Self::S3(S3StorageBinding {
69            bucket_name: bucket_name.into(),
70        })
71    }
72
73    /// Creates an Azure Blob storage binding
74    pub fn blob(
75        account_name: impl Into<BindingValue<String>>,
76        container_name: impl Into<BindingValue<String>>,
77    ) -> Self {
78        Self::Blob(BlobStorageBinding {
79            account_name: account_name.into(),
80            container_name: container_name.into(),
81        })
82    }
83
84    /// Creates a GCS storage binding
85    pub fn gcs(bucket_name: impl Into<BindingValue<String>>) -> Self {
86        Self::Gcs(GcsStorageBinding {
87            bucket_name: bucket_name.into(),
88        })
89    }
90
91    /// Creates a local storage binding
92    pub fn local(storage_path: impl Into<BindingValue<String>>) -> Self {
93        Self::Local(LocalStorageBinding {
94            storage_path: storage_path.into(),
95        })
96    }
97}