Skip to content

Commit

Permalink
CFE-4450: Allow passing environment variables to package managers
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Nov 22, 2024
1 parent bbec246 commit 1e58dfd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/packages/vendored/apt_get.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,17 @@ def package_arguments_builder(is_apt_install):
elif line.startswith("options="):
global apt_get_options
option = line.split("=", 1)[1].rstrip()

if option:
apt_get_options.append(option)
if option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value
else:
apt_get_options.append(option)

if name:
args.extend(one_package_argument(name, arch, version, is_apt_install))
Expand Down
14 changes: 14 additions & 0 deletions modules/packages/vendored/yum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ def list_updates(online):
yum_options.append(option)
elif option.startswith("enablerepo=") or option.startswith("disablerepo="):
yum_options.append("--" + option)
elif option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value

online_flag = []
if not online:
Expand Down Expand Up @@ -229,6 +236,13 @@ def package_arguments_builder(is_yum_install):
yum_options.append(option)
elif option.startswith("enablerepo=") or option.startswith("disablerepo="):
yum_options.append("--" + option)
elif option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value
if line.startswith("Name="):
if name:
# Each new "Name=" triggers a new entry.
Expand Down
27 changes: 27 additions & 0 deletions modules/packages/vendored/zypper.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,21 @@ def package_arguments_builder(is_zypper_install):
elif line.startswith("Architecture="):
arch = line.split("=", 1)[1].rstrip()

elif line.startswith("options="):
global zypper_options
option = line.split("=", 1)[1].rstrip()

if option:
if option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value
else:
zypper_options.append(option)

if name:
single_list, multi_list = one_package_argument(name, arch, version, is_zypper_install)
single_cmd_args += single_list
Expand Down Expand Up @@ -405,6 +420,18 @@ def file_install():
found = True
cmd_line.append(line.split("=", 1)[1].rstrip())

elif line.startswith("options="):
global zypper_options
option = line.split("=", 1)[1].rstrip()
if option:
if option.startswith("env:"):
env_option = option.split(":", 1)[1]
env_var = env_option.split("=", 1)
if len(env_var) == 2:
name = env_var[0]
value = env_var[1]
os.environ[name] = value

if not found:
return 0

Expand Down

0 comments on commit 1e58dfd

Please sign in to comment.