copy env so we are doing additive stuff rather than completely rewriting it

This commit is contained in:
burnettk 2023-02-21 22:00:02 -05:00
parent e506c37265
commit 7ae03bec27
No known key found for this signature in database
1 changed files with 13 additions and 12 deletions

View File

@ -154,30 +154,31 @@ class GitService:
cls, command: list[str], return_success_state: bool = False
) -> Union[subprocess.CompletedProcess[bytes], bool]:
"""Run_shell_command."""
git_env_options = {
"GIT_COMMITTER_NAME": (
current_app.config.get("SPIFFWORKFLOW_BACKEND_GIT_USERNAME")
or "unknown"
),
"GIT_COMMITTER_EMAIL": (
current_app.config.get("SPIFFWORKFLOW_BACKEND_GIT_USER_EMAIL")
or "unknown@example.org"
),
}
my_env = os.environ.copy()
my_env["GIT_COMMITTER_NAME"] = (
current_app.config.get("SPIFFWORKFLOW_BACKEND_GIT_USERNAME") or "unknown"
)
my_env["GIT_COMMITTER_EMAIL"] = (
current_app.config.get("SPIFFWORKFLOW_BACKEND_GIT_USER_EMAIL")
or "unknown@example.org"
)
# SSH authentication can be also provided via gitconfig.
ssh_key_path = current_app.config.get(
"SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH"
)
if ssh_key_path is not None:
git_env_options["GIT_SSH_COMMAND"] = (
my_env["GIT_SSH_COMMAND"] = (
"ssh -F /dev/null -o UserKnownHostsFile=/dev/null -o"
" StrictHostKeyChecking=no -i %s" % ssh_key_path
)
# this is fine since we pass the commands directly
result = subprocess.run( # noqa
command, check=False, capture_output=True, env=git_env_options
command, check=False, capture_output=True, env=my_env
)
if return_success_state:
return result.returncode == 0