Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand environmental variables in sshOpts #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<String>,
Expand All @@ -30,6 +32,23 @@ pub struct GenericSettings {
pub magic_rollback: Option<bool>,
}

impl GenericSettings {
fn de_ssh_opts<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
where
D: Deserializer<'de>,
{
let buf: Vec<String> = 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,
Expand Down