objectstore_server/
state.rs

1use std::sync::Arc;
2
3use objectstore_service::{StorageConfig, StorageService};
4
5use crate::config::{Config, Storage};
6
7pub type ServiceState = Arc<State>;
8
9pub struct State {
10    pub config: Config,
11    pub service: StorageService,
12}
13
14impl State {
15    pub async fn new(config: Config) -> anyhow::Result<ServiceState> {
16        let high_volume = map_storage_config(&config.high_volume_storage);
17        let long_term = map_storage_config(&config.long_term_storage);
18        let service = StorageService::new(high_volume, long_term).await?;
19
20        Ok(Arc::new(Self { config, service }))
21    }
22}
23
24fn map_storage_config(config: &'_ Storage) -> StorageConfig<'_> {
25    match config {
26        Storage::FileSystem { path } => StorageConfig::FileSystem { path },
27        Storage::S3Compatible { endpoint, bucket } => {
28            StorageConfig::S3Compatible { endpoint, bucket }
29        }
30        Storage::Gcs { endpoint, bucket } => StorageConfig::Gcs {
31            endpoint: endpoint.as_deref(),
32            bucket,
33        },
34        Storage::BigTable {
35            endpoint,
36            project_id,
37            instance_name,
38            table_name,
39            connections,
40        } => StorageConfig::BigTable {
41            endpoint: endpoint.as_deref(),
42            project_id,
43            instance_name,
44            table_name,
45            connections: *connections,
46        },
47    }
48}