diff --git a/Cargo.toml b/Cargo.toml index b4d064c..e93dbb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "horust" -version = "0.1.7" +version = "0.1.8" authors = ["Federico Ponzi "] description = "A complete supervisor and init system, designed for running in containers." edition = "2021" diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 76ea9d4..0d9425f 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -121,8 +121,8 @@ keep-env = false re-export = [ "PATH", "DB_PASS"] additional = { key = "value"} ``` -* **`keep-env` = `bool`**: default: true. Pass over all the environment variables. -Regardless the value of keep-env, the following keys will be updated / defined: +* **`keep-env` = `bool`**: default: false. Pass over all the environment variables. +Regardless of the value of keep-env, the following keys will be updated / defined: * `USER` * `HOSTNAME` * `HOME` diff --git a/src/horust/formats/service.rs b/src/horust/formats/service.rs index edda7af..653ea68 100644 --- a/src/horust/formats/service.rs +++ b/src/horust/formats/service.rs @@ -75,8 +75,8 @@ impl Service { P: AsRef + ?Sized + AsRef + Debug, { let preconfig = std::fs::read_to_string(path)?; - let postconfig = shellexpand::full(&preconfig)?.to_string(); - toml::from_str::(&postconfig).map_err(Error::from) + let postconfig = shellexpand::full(&preconfig)?; + Ok(toml::from_str::(&postconfig)?) } /// Creates the environment K=V variables, used for exec into the new process. /// User defined environment variables overwrite the predefined values. @@ -203,7 +203,7 @@ impl From<&str> for LogOutput { #[derive(Serialize, Clone, Default, Deserialize, Debug, Eq, PartialEq)] #[serde(rename_all = "kebab-case")] pub struct Environment { - #[serde(default = "Environment::default_keep_env")] + #[serde(default)] pub keep_env: bool, #[serde(default)] pub re_export: Vec, @@ -212,10 +212,6 @@ pub struct Environment { } impl Environment { - fn default_keep_env() -> bool { - true - } - fn get_hostname_val() -> String { let hostname_path = "/etc/hostname"; let localhost = "localhost".to_string(); diff --git a/tests/section_environment.rs b/tests/section_environment.rs index d9564e8..91cfd45 100644 --- a/tests/section_environment.rs +++ b/tests/section_environment.rs @@ -1,6 +1,7 @@ use assert_cmd::prelude::*; use predicates::prelude::*; use predicates::str::contains; +use std::env::temp_dir; #[allow(dead_code)] mod utils; @@ -28,18 +29,39 @@ additional = { TERM = "bar" } } #[test] -fn test_environment_keep_env() { +fn test_environment_keep_env_absent() { + let (mut cmd, temp_dir) = get_cli(); + // By default, keep-env is false + store_service_script(temp_dir.path(), ENVIRONMENT_SCRIPT, Some(""), None); + cmd.env("DB_PASS", "MyPassword") + .assert() + .success() + .stdout(contains("MyPassword").not()); +} +#[test] +fn test_environment_keep_env_true() { let (mut cmd, temp_dir) = get_cli(); - // keep-env should keep the env :D let service = r#"[environment] -keep-env = true -"#; + keep-env = true + "#; store_service_script(temp_dir.path(), ENVIRONMENT_SCRIPT, Some(service), None); cmd.env("DB_PASS", "MyPassword") .assert() .success() .stdout(contains("MyPassword")); } +#[test] +fn test_environment_keep_env_false() { + let (mut cmd, temp_dir) = get_cli(); + let service = r#"[environment] + keep-env = false + "#; + store_service_script(temp_dir.path(), ENVIRONMENT_SCRIPT, Some(service), None); + cmd.env("DB_PASS", "MyPassword") + .assert() + .success() + .stdout(contains("MyPassword").not()); +} #[test] fn test_environment_re_export() {