use crate::db::OrbitRow;
use crate::state::HubState;
use anyhow::{Context, Result};
use tessera_core::manifest::SnapshotManifest;
use tessera_providers::{FilesystemConfig, MysqlSource, PostgresProvider, PostgresSource};
use uuid::Uuid;
#[derive(serde::Deserialize)]
#[serde(tag = "engine", rename_all = "snake_case")]
pub(super) enum DatabaseSource {
Postgres(PostgresSource),
Mysql(MysqlSource),
}
impl DatabaseSource {
pub(super) fn valid_endpoint(&self) -> bool {
let (host, port, database, user, password_file) = match self {
Self::Postgres(source) if source.bastion.is_none() => (
&source.host,
source.port,
&source.database,
&source.user,
&source.password_file,
),
Self::Mysql(MysqlSource::Direct {
host,
port,
database,
user,
password_file,
..
}) => (host, *port, database, user, password_file),
_ => return false,
};
port != 0
&& password_file.is_absolute()
&& [host, database, user]
.iter()
.all(|value| !value.trim().is_empty() && !value.chars().any(char::is_control))
}
}
pub async fn run_orbit_internal(state: HubState, orbit: OrbitRow) -> Result