Skip to content

Commit

Permalink
fix(env_directive): apply redactions only to env with redact (#4388)
Browse files Browse the repository at this point in the history
Fixes #4368

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
risu729 and autofix-ci[bot] authored Feb 14, 2025
1 parent a1a3c9f commit d5c1be0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 0 additions & 4 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@
}
}
]
},
"redact": {
"type": "boolean",
"description": "redact the value from logs"
}
}
},
Expand Down
17 changes: 10 additions & 7 deletions src/config/env_directive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ impl EnvResults {
} else {
r.env_remove.remove(&k);
// trace!("resolve: inserting {:?}={:?} from {:?}", &k, &v, &source);
if redact {
r.redactions.push(k.clone());
}
env.insert(k, (v, Some(source.clone())));
}
}
Expand Down Expand Up @@ -255,6 +258,9 @@ impl EnvResults {
if resolve_opts.vars {
r.vars.insert(k, (v, f.clone()));
} else {
if redact {
r.redactions.push(k.clone());
}
r.env_remove.insert(k.clone());
env.insert(k, (v, Some(f.clone())));
}
Expand All @@ -279,6 +285,9 @@ impl EnvResults {
if resolve_opts.vars {
r.vars.insert(k, (v, f.clone()));
} else {
if redact {
r.redactions.push(k.clone());
}
r.env_remove.insert(k.clone());
env.insert(k, (v, Some(f.clone())));
}
Expand Down Expand Up @@ -310,15 +319,9 @@ impl EnvResults {
)?;
}
EnvDirective::Module(name, value, _opts) => {
Self::module(&mut r, source, name, &value)?;
Self::module(&mut r, source, name, &value, redact)?;
}
};

if redact {
for k in env.keys() {
r.redactions.push(k.clone());
}
}
}
let env_vars = env
.iter()
Expand Down
11 changes: 10 additions & 1 deletion src/config/env_directive/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ use std::path::PathBuf;
use toml::Value;

impl EnvResults {
pub fn module(r: &mut EnvResults, source: PathBuf, name: String, value: &Value) -> Result<()> {
pub fn module(
r: &mut EnvResults,
source: PathBuf,
name: String,
value: &Value,
redact: bool,
) -> Result<()> {
let path = dirs::PLUGINS.join(name.to_kebab_case());
let plugin = VfoxPlugin::new(name, path);
if let Some(env) = plugin.mise_env(value)? {
for (k, v) in env {
if redact {
r.redactions.push(k.clone());
}
r.env.insert(k, (v, source.clone()));
}
}
Expand Down

0 comments on commit d5c1be0

Please sign in to comment.