Skip to main content

coil_storage/policy/
topology.rs

1use coil_config::{
2    ObjectStoreKind, PlatformConfig, SingleNodeStorageMode, StorageClass, StorageDeployment,
3};
4
5use super::StorageBackendKind;
6use crate::policy::paths::trim_trailing_separator;
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct ObjectStoreTarget {
10    pub kind: ObjectStoreKind,
11}
12
13impl ObjectStoreTarget {
14    pub const fn backend_kind(&self) -> StorageBackendKind {
15        match self.kind {
16            ObjectStoreKind::S3 => StorageBackendKind::S3Compatible,
17        }
18    }
19}
20
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct StorageTopology {
23    pub local_root: String,
24    pub default_class: StorageClass,
25    pub deployment: StorageDeployment,
26    pub single_node_escape_hatch: SingleNodeStorageMode,
27    pub object_store: Option<ObjectStoreTarget>,
28}
29
30impl StorageTopology {
31    pub fn from_config(config: &PlatformConfig) -> Self {
32        Self {
33            local_root: trim_trailing_separator(&config.storage.local_root),
34            default_class: config.storage.default_class,
35            deployment: config.storage.deployment,
36            single_node_escape_hatch: config.storage.single_node_escape_hatch,
37            object_store: config
38                .storage
39                .object_store
40                .map(|kind| ObjectStoreTarget { kind }),
41        }
42    }
43
44    pub fn supports_object_store(&self) -> bool {
45        self.object_store.is_some()
46    }
47
48    pub const fn allows_explicit_local_only(&self) -> bool {
49        matches!(self.deployment, StorageDeployment::SingleNode)
50            && matches!(
51                self.single_node_escape_hatch,
52                SingleNodeStorageMode::ExplicitSingleNode
53            )
54    }
55}