From 72ff5f8817159037471c45f711f2020ca142e023 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Tue, 10 Aug 2021 16:02:49 -0600 Subject: [PATCH] Expand environmental variables in sshOpts --- Cargo.lock | 17 +++++++++++++++++ Cargo.toml | 1 + src/data.rs | 23 +++++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08ac3bfc..c1b1060e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,6 +136,7 @@ name = "deploy-rs" version = "0.1.0" dependencies = [ "clap", + "envmnt", "flexi_logger", "fork", "futures-util", @@ -154,6 +155,16 @@ dependencies = [ "yn", ] +[[package]] +name = "envmnt" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbfac51e9996e41d78a943227b7f313efcebf545b21584a0e213b956a062e11e" +dependencies = [ + "fsio", + "indexmap", +] + [[package]] name = "filetime" version = "0.2.13" @@ -210,6 +221,12 @@ dependencies = [ "libc", ] +[[package]] +name = "fsio" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a50045aa8931ae01afbc5d72439e8f57f326becb8c70d07dfc816778eff3d167" + [[package]] name = "fuchsia-zircon" version = "0.3.3" diff --git a/Cargo.toml b/Cargo.toml index 0ded1259..cdeeb6af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ tokio = { version = "1.9.0", features = [ "full" ] } toml = "0.5" whoami = "0.9.0" yn = "0.1" +envmnt = "0.9.0" # smol_str is required by rnix, but 0.1.17 doesn't build on rustc # 1.45.2 (shipped in nixos-20.09); it requires rustc 1.46.0. See diff --git a/src/data.rs b/src/data.rs index 6fe7f75f..70410a5e 100644 --- a/src/data.rs +++ b/src/data.rs @@ -2,8 +2,9 @@ // // SPDX-License-Identifier: MPL-2.0 +use envmnt::{self, ExpandOptions, ExpansionType}; use merge::Merge; -use serde::Deserialize; +use serde::{Deserialize, Deserializer}; use std::collections::HashMap; #[derive(Deserialize, Debug, Clone, Merge)] @@ -14,7 +15,8 @@ pub struct GenericSettings { #[serde( skip_serializing_if = "Vec::is_empty", default, - rename(deserialize = "sshOpts") + rename(deserialize = "sshOpts"), + deserialize_with = "GenericSettings::de_ssh_opts" )] #[merge(strategy = merge::vec::append)] pub ssh_opts: Vec, @@ -30,6 +32,23 @@ pub struct GenericSettings { pub magic_rollback: Option, } +impl GenericSettings { + fn de_ssh_opts<'de, D>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, + { + let buf: Vec = Vec::deserialize(deserializer)?; + + let mut options = ExpandOptions::new(); + options.expansion_type = Some(ExpansionType::UnixBrackets); + + Ok(buf + .into_iter() + .map(|opt| envmnt::expand(&opt, Some(options))) + .collect()) + } +} + #[derive(Deserialize, Debug, Clone)] pub struct NodeSettings { pub hostname: String,