Unify backend resources and role bindings in clusters
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
//! 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user