Add an ssh_arguments configuration file field (#211)

Can be used to add SSH command-line arguments like `-o
ConnectTimeout=2`
This commit is contained in:
Fred Morcos
2019-09-01 20:45:44 +02:00
committed by Roey Darwish Dror
parent 6dac7a18b2
commit bfbb486fba
3 changed files with 30 additions and 12 deletions

View File

@@ -87,6 +87,7 @@ pub struct ConfigFile {
git_repos: Option<Vec<String>>, git_repos: Option<Vec<String>>,
disable: Option<Vec<Step>>, disable: Option<Vec<Step>>,
remote_topgrades: Option<Vec<String>>, remote_topgrades: Option<Vec<String>>,
ssh_arguments: Option<String>,
} }
impl ConfigFile { impl ConfigFile {
@@ -270,6 +271,11 @@ impl Config {
&self.config_file.remote_topgrades &self.config_file.remote_topgrades
} }
/// Extra SSH arguments
pub fn ssh_arguments(&self) -> &Option<String> {
&self.config_file.ssh_arguments
}
/// Prompt for a key before exiting /// Prompt for a key before exiting
pub fn keep_at_end(&self) -> bool { pub fn keep_at_end(&self) -> bool {
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok() self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()

View File

@@ -132,7 +132,14 @@ fn run() -> Result<(), Error> {
execute( execute(
&mut report, &mut report,
remote_topgrade, remote_topgrade,
|| generic::run_remote_topgrade(run_type, remote_topgrade, config.run_in_tmux()), || {
generic::run_remote_topgrade(
run_type,
remote_topgrade,
config.ssh_arguments(),
config.run_in_tmux(),
)
},
config.no_retry(), config.no_retry(),
)?; )?;
} }

View File

@@ -137,7 +137,12 @@ pub fn run_composer_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()
Ok(()) Ok(())
} }
pub fn run_remote_topgrade(run_type: RunType, hostname: &str, run_in_tmux: bool) -> Result<(), Error> { pub fn run_remote_topgrade(
run_type: RunType,
hostname: &str,
ssh_arguments: &Option<String>,
run_in_tmux: bool,
) -> Result<(), Error> {
let ssh = utils::require("ssh")?; let ssh = utils::require("ssh")?;
if run_in_tmux && !run_type.dry() { if run_in_tmux && !run_type.dry() {
@@ -149,15 +154,15 @@ pub fn run_remote_topgrade(run_type: RunType, hostname: &str, run_in_tmux: bool)
unreachable!("Tmux execution is only implemented in Unix"); unreachable!("Tmux execution is only implemented in Unix");
} else { } else {
run_type let mut args = vec!["-t", hostname];
.execute(&ssh)
.args(&[ if let Some(ssh_arguments) = ssh_arguments {
"-t", args.extend(ssh_arguments.split_whitespace());
hostname, }
"env",
&format!("TOPGRADE_PREFIX={}", hostname), let env = format!("TOPGRADE_PREFIX={}", hostname);
"topgrade", args.extend(&["env", &env, "topgrade"]);
])
.check_run() run_type.execute(&ssh).args(&args).check_run()
} }
} }