diff --git a/gu-model/src/envman.rs b/gu-model/src/envman.rs index 0463d365c..e1fe4d4e4 100644 --- a/gu-model/src/envman.rs +++ b/gu-model/src/envman.rs @@ -108,6 +108,12 @@ impl Default for ResourceFormat { } } +#[derive(Clone, Serialize, Deserialize, Default, Hash, Eq, PartialEq, Debug)] +pub struct ExecOptions { + pub user: Option, + pub working_dir: Option, +} + #[derive(Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Debug)] #[serde(rename_all = "camelCase")] pub enum Command { @@ -115,6 +121,7 @@ pub enum Command { // return cmd output executable: String, args: Vec, + options: ExecOptions, }, Open, Close, diff --git a/gu-provider/src/dockerman.rs b/gu-provider/src/dockerman.rs index fb82413c9..9352c23a5 100644 --- a/gu-provider/src/dockerman.rs +++ b/gu-provider/src/dockerman.rs @@ -81,15 +81,23 @@ impl DockerSession { &mut self, executable: String, mut args: Vec, + options: ExecOptions, ) -> impl Future { args.insert(0, executable); let cfg = { use async_docker::models::*; - ExecConfig::new() + let mut config = ExecConfig::new() .with_attach_stdout(true) .with_attach_stderr(true) - .with_cmd(args) + .with_cmd(args); + if let Some(user) = options.user { + config.set_user(user) + } + if let Some(working_dir) = options.working_dir { + config.set_working_dir(working_dir) + } + config }; self.container @@ -469,10 +477,13 @@ fn run_command( match command { Command::Open => docker_man.run_for_deployment(session_id, DockerSession::do_open), Command::Close => docker_man.run_for_deployment(session_id, DockerSession::do_close), - Command::Exec { executable, args } => docker_man - .run_for_deployment(session_id, |deployment| { - deployment.do_exec(executable, args) - }), + Command::Exec { + executable, + args, + options, + } => docker_man.run_for_deployment(session_id, |deployment| { + deployment.do_exec(executable, args, options) + }), // TODO: FIXME @destruktiv: same as Exec but async Command::Start { executable: _, diff --git a/gu-provider/src/hdman.rs b/gu-provider/src/hdman.rs index 61c06d048..a06d9958c 100644 --- a/gu-provider/src/hdman.rs +++ b/gu-provider/src/hdman.rs @@ -11,7 +11,7 @@ use std::{ use actix::{fut, prelude::*}; use futures::{future, prelude::*}; -use log::{debug, error, info}; +use log::{debug, error, info, warn}; use serde::{Deserialize, Serialize}; use gu_actix::prelude::*; @@ -295,7 +295,14 @@ fn run_command( match command { Command::Open => Box::new(fut::ok("Open mock".to_string())), Command::Close => Box::new(fut::ok("Close mock".to_string())), - Command::Exec { executable, args } => { + Command::Exec { + executable, + args, + options, + } => { + if options != Default::default() { + warn!("ExecOptions unimplemented in hdman"); + } let executable = session.get_session_exec_path(&executable); let session_id = session_id.clone(); let session_dir = session.workspace.path().to_owned();