use std::num::NonZeroU16;
use isoloom_spec::model::Protocol;
use isoloom_spec::syntax::{AbsPath, AptWord, Argv, HttpsUrl, ProjectPath, RepositoryKey, RepositoryName, UnitName, UserName};
pub type PinnedPackage = isoloom_spec::syntax::Package;
pub type CopyPlan = isoloom_spec::syntax::Copy;
pub type FilePlan = isoloom_spec::syntax::FileStep;
pub type TemplatePlan = isoloom_spec::syntax::Template;
pub type UserPlan = isoloom_spec::syntax::UserStep;
pub type GroupPlan = isoloom_spec::syntax::GroupStep;
pub type CommandPlan = isoloom_spec::syntax::CommandStep;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Resource {
Repository(RepositoryPlan),
Packages(Vec<PinnedPackage>),
Copy(CopyPlan),
File(FilePlan),
Template(TemplatePlan),
User(UserPlan),
Group(GroupPlan),
Service(ServicePlan),
Command(CommandPlan),
Firewall(Vec<PortSpec>),
Run(RunPlan),
Reboot,
Playbook(ProjectPath),
}
impl Resource {
#[must_use]
pub fn kind(&self) -> &'static str {
match self {
Resource::Repository(_) => "repository",
Resource::Packages(_) => "packages",
Resource::Copy(_) => "copy",
Resource::File(_) => "file",
Resource::Template(_) => "template",
Resource::User(_) => "user",
Resource::Group(_) => "group",
Resource::Service(_) => "service",
Resource::Command(_) => "command",
Resource::Firewall(_) => "firewall",
Resource::Run(_) => "run",
Resource::Reboot => "reboot",
Resource::Playbook(_) => "playbook",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum RepositoryKind {
Apt,
Rpm,
Apk,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RepositoryPlan {
pub name: RepositoryName,
pub kind: RepositoryKind,
pub url: HttpsUrl,
pub key: RepositoryKey,
pub suite: Option<AptWord>,
pub components: Vec<AptWord>,
pub priority: Option<i32>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ServicePlan {
pub unit: UnitName,
pub source: ServiceSource,
pub enabled: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ServiceSource {
Package,
Defined {
run: Argv,
user: Option<UserName>,
cwd: Option<AbsPath>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PortSpec {
pub port: NonZeroU16,
pub protocol: Protocol,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RunPlan {
pub script: ProjectPath,
pub creates: Option<AbsPath>,
pub shell: Shell,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Shell {
Posix,
PowerShell,
}