Commit 4b839330 authored by PERE Alexandre's avatar PERE Alexandre

Merge branch '33-parametric-profiles-2' into 'develop'

Resolve "Parametric profiles"

See merge request !22
parents c78b6b2d bb772754
......@@ -338,7 +338,7 @@ struct Host {
impl Host {
// Builds a host from a configuration.
#[instrument(name="Host::from_conf")]
fn from_conf(conf: HostConf) -> Result<Host, Error> {
fn from_conf(conf: HostConf, context: FrontendContext) -> Result<Host, Error> {
trace!("Loading from conf");
// We retrieve the ssh profile from the configuration
let profile = ssh::config::get_profile(
......@@ -351,7 +351,7 @@ impl Host {
trace!(?conn, "Connection to frontend acquired");
// We generate the host
let mut context = FrontendContext(TerminalContext::default());
let mut context = context;
context.0.envs.insert(EnvironmentKey("RUNAWAY_PATH".into()),
EnvironmentValue(conf.directory.to_str().unwrap().into()));
Ok(Host {
......@@ -542,8 +542,8 @@ pub struct HostHandle {
impl HostHandle {
/// This function spawns the thread that will handle all the repository operations using the
/// CampaignResource, and returns a handle to it.
pub fn spawn(host_conf: HostConf) -> Result<HostHandle, Error> {
let host = Host::from_conf(host_conf.clone())?;
pub fn spawn(host_conf: HostConf, context: TerminalContext<PathBuf>) -> Result<HostHandle, Error> {
let host = Host::from_conf(host_conf.clone(), FrontendContext(context))?;
let conn = host.conn.clone();
let (sender, receiver) = mpsc::unbounded();
let handle = thread::Builder::new().name("host".into())
......@@ -990,8 +990,10 @@ mod test {
execution: vec!["$RUNAWAY_COMMAND".to_owned()],
directory: path::PathBuf::from("/projets/flowers/alex/executions"),
};
let res_handle = HostHandle::spawn(conf).unwrap();
let context = TerminalContext::default();
let res_handle = HostHandle::spawn(conf, context).unwrap();
// We test environment of first connection
let conn1 = {
......@@ -1080,7 +1082,10 @@ mod test {
directory: path::PathBuf::from("/projets/flowers/alex/executions"),
};
let res_handle = HostHandle::spawn(conf).unwrap();
let context = TerminalContext::default();
let res_handle = HostHandle::spawn(conf, context).unwrap();
async fn test(res: HostHandle) {
let conn = res.async_acquire().await.unwrap();
......
......@@ -18,7 +18,7 @@ use clap;
use crate::exit::Exit;
use crate::logger::EchoSubscriber;
use liborchestra::primitives::{read_globs_from_file, list_local_folder, Glob};
use liborchestra::commons::{EnvironmentStore, EnvironmentKey, EnvironmentValue};
use liborchestra::commons::{EnvironmentStore, EnvironmentKey, EnvironmentValue, TerminalContext};
use liborchestra::scheduler::SchedulerHandle;
use itertools::Itertools;
use tracing::{self, info, error};
......@@ -96,10 +96,12 @@ macro_rules! try_return_err {
/// Allows to load host from a host path configuration
pub fn get_host(host_name: &str) -> Result<HostHandle, Exit>{
pub fn get_host(host_name: &str, envs: EnvironmentStore) -> Result<HostHandle, Exit>{
let host_path = get_host_path(host_name);
let mut context = TerminalContext::default();
context.envs = envs;
let config = to_exit!(HostConf::from_file(&host_path), Exit::LoadHostConfiguration)?;
to_exit!(HostHandle::spawn(config), Exit::SpawnHost)
to_exit!(HostHandle::spawn(config, context), Exit::SpawnHost)
}
/// Allows to generate globs from send and fetch ignore file.
......
......@@ -58,7 +58,7 @@ pub fn batch(matches: clap::ArgMatches<'static>) -> Result<Exit, Exit>{
// We load the host
info!("Loading host");
let host = misc::get_host(matches.value_of("REMOTE").unwrap())?;
let host = misc::get_host(matches.value_of("REMOTE").unwrap(), store.clone())?;
push_env(&mut store, "RUNAWAY_REMOTE", host.get_name());
debug!("Host {} loaded", host);
......
......@@ -38,9 +38,18 @@ pub fn exec(matches: clap::ArgMatches) -> Result<Exit, Exit>{
// We create the store that will keep env vars
let mut store = EnvironmentStore::new();
// We read the envs to the store.
if !matches.is_present("no-env-read"){
let envs = misc::read_local_runaway_envs();
debug!("Local environment variables captured: {}", envs.iter()
.fold(String::new(), |mut acc, (k, v)| {acc.push_str(&format!("\n{:?}={:?}", k, v)); acc}));
envs.into_iter()
.for_each(|(k, v)| {push_env(&mut store, k.0, v.0);});
}
// We load the host
info!("Loading host");
let host = misc::get_host(matches.value_of("REMOTE").unwrap())?;
let host = misc::get_host(matches.value_of("REMOTE").unwrap(), store.clone())?;
push_env(&mut store, "RUNAWAY_REMOTE", host.get_name());
debug!("Host {:?} loaded", host);
......
......@@ -58,7 +58,7 @@ pub fn sched(matches: clap::ArgMatches<'static>) -> Result<Exit, Exit>{
// We load the host
info!("Loading host");
let host = misc::get_host(matches.value_of("REMOTE").unwrap())?;
let host = misc::get_host(matches.value_of("REMOTE").unwrap(), store.clone())?;
push_env(&mut store, "RUNAWAY_REMOTE", host.get_name());
debug!("Host {} loaded", host);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment