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 012f5c20aa
commit 54248ca568
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 cls, command: list[str], return_success_state: bool = False
) -> Union[subprocess.CompletedProcess[bytes], bool]: ) -> Union[subprocess.CompletedProcess[bytes], bool]:
"""Run_shell_command.""" """Run_shell_command."""
git_env_options = { my_env = os.environ.copy()
"GIT_COMMITTER_NAME": ( my_env["GIT_COMMITTER_NAME"] = (
current_app.config.get("SPIFFWORKFLOW_BACKEND_GIT_USERNAME") current_app.config.get("SPIFFWORKFLOW_BACKEND_GIT_USERNAME") or "unknown"
or "unknown" )
),
"GIT_COMMITTER_EMAIL": ( my_env["GIT_COMMITTER_EMAIL"] = (
current_app.config.get("SPIFFWORKFLOW_BACKEND_GIT_USER_EMAIL") current_app.config.get("SPIFFWORKFLOW_BACKEND_GIT_USER_EMAIL")
or "unknown@example.org" or "unknown@example.org"
), )
}
# SSH authentication can be also provided via gitconfig. # SSH authentication can be also provided via gitconfig.
ssh_key_path = current_app.config.get( ssh_key_path = current_app.config.get(
"SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH" "SPIFFWORKFLOW_BACKEND_GIT_SSH_PRIVATE_KEY_PATH"
) )
if ssh_key_path is not None: 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" "ssh -F /dev/null -o UserKnownHostsFile=/dev/null -o"
" StrictHostKeyChecking=no -i %s" % ssh_key_path " StrictHostKeyChecking=no -i %s" % ssh_key_path
) )
# this is fine since we pass the commands directly # this is fine since we pass the commands directly
result = subprocess.run( # noqa 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: if return_success_state:
return result.returncode == 0 return result.returncode == 0