feat(package_manager): evaluate env vars in installer commands
Remove hardcoded DRIVE_ACCESSKEY/SECRET env vars and replace with variable references ($DRIVE_USER, $DRIVE_ACCESSKEY). Added logic to evaluate environment variable references in command execution by expanding $VAR references to their actual values from the environment. This makes the configuration more flexible and secure by avoiding hardcoded credentials.
This commit is contained in:
parent
6c3812753f
commit
b68f4ee760
1 changed files with 15 additions and 5 deletions
|
|
@ -61,8 +61,6 @@ impl PackageManager {
|
||||||
|
|
||||||
fn register_drive(&mut self) {
|
fn register_drive(&mut self) {
|
||||||
|
|
||||||
let drive_user = std::env::var("DRIVE_ACCESSKEY").unwrap();
|
|
||||||
let drive_password = std::env::var("DRIVE_SECRET").unwrap();
|
|
||||||
|
|
||||||
self.components.insert(
|
self.components.insert(
|
||||||
"drive".to_string(),
|
"drive".to_string(),
|
||||||
|
|
@ -84,8 +82,8 @@ impl PackageManager {
|
||||||
pre_install_cmds_windows: vec![],
|
pre_install_cmds_windows: vec![],
|
||||||
post_install_cmds_windows: vec![],
|
post_install_cmds_windows: vec![],
|
||||||
env_vars: HashMap::from([
|
env_vars: HashMap::from([
|
||||||
("MINIO_ROOT_USER".to_string(), drive_user.clone()),
|
("MINIO_ROOT_USER".to_string(), "$DRIVE_USER".to_string()),
|
||||||
("MINIO_ROOT_PASSWORD".to_string(), drive_password.clone()),
|
("MINIO_ROOT_PASSWORD".to_string(), "$DRIVE_ACCESSKEY".to_string()),
|
||||||
]),
|
]),
|
||||||
data_download_list: Vec::new(),
|
data_download_list: Vec::new(),
|
||||||
exec_cmd: "nohup {{BIN_PATH}}/minio server {{DATA_PATH}} --address :9000 --console-address :9001 > {{LOGS_PATH}}/minio.log 2>&1 &".to_string(),
|
exec_cmd: "nohup {{BIN_PATH}}/minio server {{DATA_PATH}} --address :9000 --console-address :9001 > {{LOGS_PATH}}/minio.log 2>&1 &".to_string(),
|
||||||
|
|
@ -741,11 +739,23 @@ impl PackageManager {
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Create new env vars map with evaluated $VAR references
|
||||||
|
let mut evaluated_envs = HashMap::new();
|
||||||
|
for (k, v) in &component.env_vars {
|
||||||
|
if v.starts_with('$') {
|
||||||
|
let var_name = &v[1..];
|
||||||
|
evaluated_envs.insert(k.clone(), std::env::var(var_name).unwrap_or_default());
|
||||||
|
} else {
|
||||||
|
evaluated_envs.insert(k.clone(), v.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let child = std::process::Command::new("sh")
|
let child = std::process::Command::new("sh")
|
||||||
.current_dir(&bin_path)
|
.current_dir(&bin_path)
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(&rendered_cmd)
|
.arg(&rendered_cmd)
|
||||||
.envs(&component.env_vars)
|
.envs(&evaluated_envs)
|
||||||
.spawn();
|
.spawn();
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue