Skip to content

Commit

Permalink
fixed from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jx2lee committed Feb 5, 2025
1 parent b0379b8 commit 6b5ed13
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions airflow/dag_processing/bundles/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def __init__(self, git_conn_id="git_default", *args, **kwargs):

if self.key_file and self.private_key:
raise AirflowException("Both 'key_file' and 'private_key' cannot be provided at the same time")
if self.key_file:
self.env["GIT_SSH_COMMAND"] = self._build_ssh_command(self.key_file)
self._process_git_auth_url()

def _build_ssh_command(self, key_path: str) -> str:
Expand All @@ -99,11 +97,8 @@ def _process_git_auth_url(self):
elif not self.repo_url.startswith("git@") or not self.repo_url.startswith("https://"):
self.repo_url = os.path.expanduser(self.repo_url)

def set_git_env(self, key: str) -> dict[str, str]:
if self.key_file:
return self.env
def set_git_env(self, key: str) -> None:
self.env["GIT_SSH_COMMAND"] = self._build_ssh_command(key)
return self.env

@contextlib.contextmanager
def configure_hook_env(self):
Expand All @@ -115,7 +110,7 @@ def configure_hook_env(self):
self.set_git_env(tmp_keyfile.name)
yield
else:
self.set_git_env(self.private_key)
self.set_git_env(self.key_file)
yield


Expand Down Expand Up @@ -159,8 +154,7 @@ def __init__(
self.log.warning("Could not create GitHook for connection %s : %s", self.git_conn_id, e)

def _initialize(self):
with self.hook.configure_hook_env() as tmp_keyfile:
self.hook.env = self.hook.set_git_env(tmp_keyfile)
with self.hook.configure_hook_env():
self._clone_bare_repo_if_required()
self._ensure_version_in_bare_repo()

Expand Down

0 comments on commit 6b5ed13

Please sign in to comment.