dashtool_common/
lib.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Serialize, Deserialize, Clone)]
4#[serde(
5    from = "Option<ObjectStoreConfigSerde>",
6    into = "Option<ObjectStoreConfigSerde>"
7)]
8pub enum ObjectStoreConfig {
9    S3(S3Config),
10    Memory,
11}
12
13/// Config for the s3 object-store. The secret_access_key is read from the environment variable
14/// AWS_SECRET_ACCESS_KEY
15#[derive(Debug, Serialize, Deserialize, Clone)]
16#[serde(rename_all = "camelCase")]
17pub struct S3Config {
18    pub aws_access_key_id: String,
19    pub aws_region: String,
20    pub aws_secret_access_key: Option<String>,
21    pub aws_endpoint: Option<String>,
22    pub aws_allow_http: Option<String>,
23}
24
25impl From<Option<ObjectStoreConfigSerde>> for ObjectStoreConfig {
26    fn from(value: Option<ObjectStoreConfigSerde>) -> Self {
27        match value {
28            None => ObjectStoreConfig::Memory,
29            Some(value) => match value {
30                ObjectStoreConfigSerde::S3(value) => ObjectStoreConfig::S3(value),
31            },
32        }
33    }
34}
35
36impl From<ObjectStoreConfig> for Option<ObjectStoreConfigSerde> {
37    fn from(value: ObjectStoreConfig) -> Self {
38        match value {
39            ObjectStoreConfig::Memory => None,
40            ObjectStoreConfig::S3(value) => Some(ObjectStoreConfigSerde::S3(value)),
41        }
42    }
43}
44
45#[derive(Debug, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum ObjectStoreConfigSerde {
48    S3(S3Config),
49}