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

Fixes #217 #218

Merged
merged 2 commits into from
Dec 23, 2023
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "horust"
version = "0.1.7"
version = "0.1.8"
authors = ["Federico Ponzi <[email protected]>"]
description = "A complete supervisor and init system, designed for running in containers."
edition = "2021"
Expand Down
4 changes: 2 additions & 2 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
10 changes: 3 additions & 7 deletions src/horust/formats/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl Service {
P: AsRef<Path> + ?Sized + AsRef<OsStr> + Debug,
{
let preconfig = std::fs::read_to_string(path)?;
let postconfig = shellexpand::full(&preconfig)?.to_string();
toml::from_str::<Service>(&postconfig).map_err(Error::from)
let postconfig = shellexpand::full(&preconfig)?;
Ok(toml::from_str::<Service>(&postconfig)?)
}
/// Creates the environment K=V variables, used for exec into the new process.
/// User defined environment variables overwrite the predefined values.
Expand Down Expand Up @@ -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<String>,
Expand All @@ -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();
Expand Down
30 changes: 26 additions & 4 deletions tests/section_environment.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use assert_cmd::prelude::*;
use predicates::prelude::*;
use predicates::str::contains;
use std::env::temp_dir;

Check warning on line 4 in tests/section_environment.rs

View workflow job for this annotation

GitHub Actions / Test (stable)

unused import: `std::env::temp_dir`

Check warning on line 4 in tests/section_environment.rs

View workflow job for this annotation

GitHub Actions / Test (beta)

unused import: `std::env::temp_dir`

Check warning on line 4 in tests/section_environment.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

unused import: `std::env::temp_dir`

#[allow(dead_code)]
mod utils;
Expand Down Expand Up @@ -28,18 +29,39 @@
}

#[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() {
Expand Down
Loading