68 lines
1.7 KiB
Rust
68 lines
1.7 KiB
Rust
//! Configurations and resolved settings dispatched by resource category.
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{Address, ConfigError, Driver, ObjectStorage, ResolvedSql, SqlCluster};
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
#[serde(tag = "kind", rename_all = "snake_case")]
|
|
pub enum Resource {
|
|
Sql(SqlCluster),
|
|
ObjectStore(ObjectStorage),
|
|
}
|
|
|
|
pub type ResourceRef<'a> = &'a Resource;
|
|
|
|
impl Resource {
|
|
pub fn driver(&self) -> Driver {
|
|
match self {
|
|
Self::Sql(cluster) => Driver::Sql(cluster.driver),
|
|
Self::ObjectStore(store) => Driver::ObjectStore(store.driver),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn default_documents() -> Self {
|
|
Self::local_documents("bedrock.sqlite3".into())
|
|
}
|
|
|
|
pub(crate) fn local_documents(path: Address) -> Self {
|
|
Self::Sql(SqlCluster::local(path))
|
|
}
|
|
|
|
pub(crate) fn resolve(
|
|
&self,
|
|
deployment: &str,
|
|
name: Option<&str>,
|
|
read_only: bool,
|
|
) -> Result<ResolvedResource, ConfigError> {
|
|
match self {
|
|
Self::Sql(cluster) => cluster
|
|
.resolve(deployment, name, read_only)
|
|
.map(ResolvedResource::Sql),
|
|
Self::ObjectStore(store) => store.resolve().map(ResolvedResource::ObjectStore),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum ResolvedResource {
|
|
Sql(ResolvedSql),
|
|
ObjectStore(ObjectStorage),
|
|
}
|
|
|
|
impl ResolvedResource {
|
|
pub fn as_sql(&self) -> Option<&ResolvedSql> {
|
|
match self {
|
|
Self::Sql(sql) => Some(sql),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
pub fn as_object_store(&self) -> Option<&ObjectStorage> {
|
|
match self {
|
|
Self::ObjectStore(store) => Some(store),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|