difftreelog
feat manual connection destination
in: trunk
2 files changed
cmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth--- a/cmds/fleet/src/cmds/build_systems.rs
+++ b/cmds/fleet/src/cmds/build_systems.rs
@@ -125,6 +125,9 @@
if let Some(deploy_kind) = opts.action_attr::<DeployKind>(&host, "deploy_kind").await? {
host.set_deploy_kind(deploy_kind);
};
+ if let Some(destination) = opts.action_attr::<String>(&host, "dest").await? {
+ host.set_session_destination(destination);
+ };
set.spawn_local(
(async move {
crates/fleet-base/src/host.rsdiffbeforeafterboth98 pub name: String,98 pub name: String,99 groups: OnceCell<Vec<String>>,99 groups: OnceCell<Vec<String>>,100100101 // TODO: Both of those values are taken from host opts, there should be a cleaner way to specify it101 deploy_kind: OnceCell<DeployKind>,102 deploy_kind: OnceCell<DeployKind>,103 session_destination: OnceCell<String>,102104103 pub host_config: Option<Value>,105 pub host_config: Option<Value>,104 pub nixos_config: OnceCell<Value>,106 pub nixos_config: OnceCell<Value>,209 Ok(generations)211 Ok(generations)210 }212 }211213214 pub fn set_session_destination(&self, dest: String) {215 self.session_destination216 .set(dest)217 .ok()218 .expect("session destination is already set")219 }212 pub fn set_deploy_kind(&self, kind: DeployKind) {220 pub fn set_deploy_kind(&self, kind: DeployKind) {213 self.deploy_kind221 self.deploy_kind214 .set(kind)222 .set(kind)217 }225 }218 pub async fn deploy_kind(&self) -> Result<DeployKind> {226 pub async fn deploy_kind(&self) -> Result<DeployKind> {219 if let Some(kind) = self.deploy_kind.get() {227 if let Some(kind) = self.deploy_kind.get() {220 return Ok(kind.clone());228 return Ok(*kind);221 }229 }222 let is_fleet_managed = match self.file_exists("/etc/FLEET_HOST").await {230 let is_fleet_managed = match self.file_exists("/etc/FLEET_HOST").await {223 Ok(v) => v,231 Ok(v) => v,237 }245 }238 // TOCTOU is possible246 // TOCTOU is possible239 let _ = self.deploy_kind.set(DeployKind::Fleet);247 let _ = self.deploy_kind.set(DeployKind::Fleet);240 Ok(self248 Ok(*self.deploy_kind.get().expect("deploy kind is just set"))241 .deploy_kind242 .get()243 .expect("deploy kind is just set")244 .clone())245 }249 }246 pub async fn escalation_strategy(&self) -> Result<EscalationStrategy> {250 pub async fn escalation_strategy(&self) -> Result<EscalationStrategy> {247 // Prefer sudo, as run0 has some gotchas with polkit251 // Prefer sudo, as run0 has some gotchas with polkit262 };266 };263 let session = SessionBuilder::default();267 let session = SessionBuilder::default();268269 let dest = self.session_destination.get().unwrap_or(&self.name);264 let session = session270 let session = session265 .connect(&self.name)271 .connect(&dest)266 .await272 .await267 .map_err(|e| anyhow!("ssh error while connecting to {}: {e:#?}", self.name))?;273 .map_err(|e| anyhow!("ssh error while connecting to {}: {e:#?}", self.name))?;268 let session = Arc::new(session);274 let session = Arc::new(session);281 .arg("test -e \"$1\" && echo true || echo false")287 .arg("test -e \"$1\" && echo true || echo false")282 .arg("_")288 .arg("_")283 .arg(path);289 .arg(path);284 Ok(cmd.run_value().await?)290 cmd.run_value().await285 }291 }286 pub async fn read_file_bin(&self, path: impl AsRef<OsStr>) -> Result<Vec<u8>> {292 pub async fn read_file_bin(&self, path: impl AsRef<OsStr>) -> Result<Vec<u8>> {287 let mut cmd = self.cmd("cat").await?;293 let mut cmd = self.cmd("cat").await?;