[agent] Legatus agent: pinned-root TLS and mTLS, HTTP client, enroll, job pipeline, renewal, Linux target, CLI (21 tests)

This commit is contained in:
2026-11-17 12:09:57 +01:00
parent f935a41ef8
commit 58c87547db
8 changed files with 1785 additions and 2 deletions
+65
View File
@@ -0,0 +1,65 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! The targets this machine offers: Linux (systemd) on Linux, none elsewhere in v0.1.
use std::path::Path;
use std::time::Duration;
use legatus_linux::{DeployError, HttpHealth, Layout, LinuxBackend, Outcome, Plan, Systemctl};
use legatus_protocol::msg::{DeployJob, Deployed, Target as JobTarget};
use crate::pipeline::Target;
/// The Linux target with real systemd.
pub struct Linux {
backend: LinuxBackend<Systemctl, HttpHealth>,
}
impl Linux {
/// Apps under `root` (normally `/var/lib/legatus/apps`).
pub fn new(root: impl Into<std::path::PathBuf>) -> Linux {
Linux {
backend: LinuxBackend::new(Layout::new(root), Systemctl, HttpHealth),
}
}
}
impl Target for Linux {
fn kinds(&self) -> Vec<String> {
if cfg!(target_os = "linux") {
vec!["linux".into()]
} else {
Vec::new()
}
}
fn deploy(
&self,
job: &DeployJob,
artifact: &Path,
sha256: &str,
) -> Result<Outcome, DeployError> {
let JobTarget::Linux(t) = &job.target;
let file = std::fs::File::open(artifact).map_err(|e| DeployError::Switch(e.to_string()))?;
let plan = Plan {
app: &job.app,
version: &job.version,
unit: &t.unit,
health_url: t.health_url.as_deref(),
health_timeout: Duration::from_secs(u64::from(t.health_timeout_seconds)),
keep: t.keep,
};
self.backend
.deploy(&plan, std::io::BufReader::new(file), sha256)
}
fn deployed(&self) -> Vec<Deployed> {
self.backend
.deployed()
.into_iter()
.map(|(app, version)| Deployed { app, version })
.collect()
}
}