pub mod credentials;
pub mod deployer;
use greentic_deploy_spec::CapabilitySlot;
use semver::VersionReq;
use super::slot::EnvPackHandler;
use crate::tool_check::ToolCheck;
pub use credentials::LocalProcessCredentials;
#[derive(Debug, Default)]
pub struct LocalProcessDeployerHandler {
creds: LocalProcessCredentials,
}
impl LocalProcessDeployerHandler {
pub const DESCRIPTOR_PATH: &'static str = "greentic.deployer.local-process";
pub const VERSION_REQ: &'static str = "^0.1.0";
pub fn new() -> Self {
Self::default()
}
pub fn with_port_range(range: std::ops::RangeInclusive<u16>) -> Self {
Self {
creds: LocalProcessCredentials::with_port_range(range),
}
}
}
impl EnvPackHandler for LocalProcessDeployerHandler {
fn slot(&self) -> CapabilitySlot {
CapabilitySlot::Deployer
}
fn descriptor_path(&self) -> &str {
Self::DESCRIPTOR_PATH
}
fn supported_versions(&self) -> VersionReq {
Self::VERSION_REQ
.parse()
.expect("local-process version-req is valid (guarded by tests)")
}
fn preflight(&self) -> Vec<ToolCheck> {
Vec::new()
}
fn deployer_credentials(&self) -> Option<&dyn crate::credentials::DeployerCredentials> {
Some(&self.creds)
}
fn wizard_qaspec_yaml(&self) -> Option<&'static str> {
Some(include_str!("wizard.qaspec.yaml"))
}
fn as_deployer(&self) -> Option<&dyn crate::env_packs::deployer::Deployer> {
Some(self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::defaults::LOCAL_DEPLOYER_PACK;
use greentic_deploy_spec::PackDescriptor;
#[test]
fn handler_serves_deployer_slot_with_local_process_path() {
let h = LocalProcessDeployerHandler::default();
assert_eq!(h.slot(), CapabilitySlot::Deployer);
assert_eq!(h.descriptor_path(), "greentic.deployer.local-process");
let _ = h.supported_versions();
}
#[test]
fn version_req_accepts_default_local_binding_descriptor() {
let h = LocalProcessDeployerHandler::default();
let pd = PackDescriptor::try_new(LOCAL_DEPLOYER_PACK).expect("descriptor parses");
assert!(
h.supported_versions().matches(&pd.version().0),
"version req {} must accept the default {} binding's version",
h.supported_versions(),
LOCAL_DEPLOYER_PACK
);
}
#[test]
fn exposes_credentials_contract() {
let h = LocalProcessDeployerHandler::default();
let creds = h
.deployer_credentials()
.expect("local-process handler must expose credentials");
let caps = creds.required_capabilities();
assert_eq!(caps.len(), 2);
}
#[test]
fn wizard_qaspec_yaml_id_matches_canonical() {
let yaml = LocalProcessDeployerHandler::default()
.wizard_qaspec_yaml()
.expect("local-process handler ships a wizard QASpec");
let spec: qa_spec::FormSpec =
serde_yaml_bw::from_str(yaml).expect("wizard.qaspec.yaml parses as FormSpec");
assert_eq!(spec.id, "greentic.deployer.local-process.wizard");
}
}