pub mod artifact;
pub mod registry;
use std::path::PathBuf;
use artifact::Artifact;
use anyhow::Result;
use crate::resolve::ResolvedPlan;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct AdapterId(&'static str);
impl AdapterId {
pub const fn new(value: &'static str) -> Self {
Self(value)
}
pub const fn as_str(self) -> &'static str {
self.0
}
}
impl std::fmt::Display for AdapterId {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Capability {
AuthoritativeDns,
RecursiveDns,
HostEnvironment,
HostNetworking,
NetworkMounts,
NasPermissions,
ProxmoxGuests,
ProxmoxSdn,
ProxmoxStorage,
ReverseProxy,
OverlayRouting,
Firewall,
CertificateIntent,
DockerNetworking,
SshClientConfig,
ExternalIngress,
CloudflareDns,
CloudflareTunnel,
}
#[derive(Debug, Clone, Copy)]
pub struct AdapterMetadata {
pub id: AdapterId,
pub name: &'static str,
pub description: &'static str,
pub capabilities: &'static [Capability],
}
#[derive(Debug, Clone, Copy)]
pub struct AdapterContext<'a, 'plan> {
pub plan: &'a ResolvedPlan<'plan>,
pub target_host: Option<&'a str>,
}
impl<'a, 'plan> AdapterContext<'a, 'plan> {
pub const fn new(plan: &'a ResolvedPlan<'plan>) -> Self {
Self {
plan,
target_host: None,
}
}
pub const fn for_host(mut self, host: &'a str) -> Self {
self.target_host = Some(host);
self
}
}
#[derive(Debug, Clone)]
pub struct AdapterOutput {
pub adapter: AdapterId,
pub root: PathBuf,
pub target_host: Option<String>,
pub artifacts: Vec<Artifact>,
}
pub trait Adapter: Send + Sync {
fn metadata(&self) -> AdapterMetadata;
fn validate(&self, context: &AdapterContext<'_, '_>) -> Result<()>;
fn render(&self, context: &AdapterContext<'_, '_>) -> Result<AdapterOutput>;
}