-
-
Notifications
You must be signed in to change notification settings - Fork 254
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
cargo pgrx test --runas
envar passing
#1674
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -546,7 +546,30 @@ fn start_pg(loglines: LogLines) -> eyre::Result<String> { | |||||||||||
cmd.arg(postmaster_path); | ||||||||||||
cmd | ||||||||||||
} else if let Some(runas) = get_runas() { | ||||||||||||
#[inline] | ||||||||||||
fn accept_envar(var: &str) -> bool { | ||||||||||||
// taken from https://doc.rust-lang.org/cargo/reference/environment-variables.html | ||||||||||||
var.starts_with("CARGO") | ||||||||||||
|| var.starts_with("RUST") | ||||||||||||
|| var.starts_with("DEP_") | ||||||||||||
|| ["OUT_DIR", "TARGET", "HOST", "NUM_JOBS", "OPT_LEVEL", "DEBUG", "PROFILE"] | ||||||||||||
.contains(&var) | ||||||||||||
} | ||||||||||||
|
||||||||||||
let mut cmd = sudo_command(runas); | ||||||||||||
|
||||||||||||
// when running the `postmaster` process via `sudo`, we need to copy the cargo/rust-related | ||||||||||||
// environment variables and pass as arguments to sudo, ahead of the `postmaster` command itself | ||||||||||||
// | ||||||||||||
// This ensures that in-process #[pg_test]s will see the `CARGO_xxx` envars they expect | ||||||||||||
for (var, value) in std::env::vars() { | ||||||||||||
if accept_envar(&var) { | ||||||||||||
let env_as_arg = format!("{var}={}", shlex::try_quote(&value)?); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we use shlex, we should just skip the env vars that we can't quote the values of correctly, or we should panic more noisily, or we should stop iterating the env vars entirely. here is one of those options.
Suggested change
|
||||||||||||
cmd.arg(env_as_arg); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
Comment on lines
+565
to
+570
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alternatively, instead of splitting and then reapplying these, why not use sudo's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn’t see that in the man page. Let me investigate that and make sure we can rely on it even being there here in 2023. |
||||||||||||
|
||||||||||||
// now we can add the `postmaster` as the command for `sudo` to execute | ||||||||||||
cmd.arg(postmaster_path); | ||||||||||||
cmd | ||||||||||||
} else { | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, regex maybe?