RaphCodec commented on code in PR #64422:
URL: https://github.com/apache/airflow/pull/64422#discussion_r3107142881
##########
providers/git/src/airflow/providers/git/hooks/git.py:
##########
@@ -104,10 +110,50 @@ def __init__(
self.host_proxy_cmd = extra.get("host_proxy_cmd")
self.ssh_port: int | None = int(extra["ssh_port"]) if
extra.get("ssh_port") else None
+ # GitHub App Auth Options
+ raw_github_app_id = extra.get("github_app_id")
+ if raw_github_app_id is not None:
+ try:
+ self.github_app_id: int | None = int(raw_github_app_id)
+ except (TypeError, ValueError) as exc:
+ raise AirflowException(
+ f"Invalid 'github_app_id' value {raw_github_app_id!r}. It
must be an integer."
+ ) from exc
+ else:
+ self.github_app_id = None
+
+ raw_github_installation_id = extra.get("github_installation_id")
+ if raw_github_installation_id is not None:
+ try:
+ self.github_installation_id: int | None =
int(raw_github_installation_id)
+ except (TypeError, ValueError) as exc:
+ raise AirflowException(
+ f"Invalid 'github_installation_id' value
{raw_github_installation_id!r}. It must be an integer."
+ ) from exc
+ else:
+ self.github_installation_id = None
self.env: dict[str, str] = {}
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.github_app_id and not self.github_installation_id) or (
+ not self.github_app_id and self.github_installation_id
+ ):
+ raise AirflowException(
+ "Both 'github_app_id' and 'github_installation_id' must be
provided to use GitHub App Authentication"
+ )
+ if self.github_app_id and self.github_installation_id:
+ if not self.key_file and not self.private_key:
+ raise AirflowException("Missing inline private_key or key_file
for GitHub App Auth")
+ if self.key_file and not self.private_key:
+ try:
+ with open(self.key_file, encoding="utf-8") as key_file:
+ self.private_key = key_file.read()
+ except OSError as exc:
+ raise AirflowException(
+ f"Failed to read GitHub App private key file
{self.key_file!r}: {exc}"
+ ) from exc
+ self.user_name, self.auth_token = self._get_github_app_token()
Review Comment:
fixed. stored the github app private key in a seperate variable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]