Skip to main content

write_env_vars

Function write_env_vars 

Source
pub fn write_env_vars(path: &Path, pairs: &[(&str, &str)]) -> Result<()>
Expand description

Set variables in the .env the loader reads, keeping everything else in the file.

A rewrite of the whole file is not an option: .env holds this install’s other secrets, and config init already refuses to overwrite one for exactly that reason. So the file is read, the named keys are replaced in place (every occurrence: the loader takes the last, and a file with two values for one key is a file somebody will read wrong), and anything else is left byte for byte. The write goes through the same 0600 path as config init.