jeff3071 commented on code in PR #54812:
URL: https://github.com/apache/airflow/pull/54812#discussion_r2545958347
##########
providers/github/src/airflow/providers/github/hooks/github.py:
##########
@@ -55,17 +54,33 @@ def get_conn(self) -> GithubClient:
conn = self.get_connection(self.github_conn_id)
access_token = conn.password
host = conn.host
-
- # Currently the only method of authenticating to GitHub in Airflow is
via a token. This is not the
- # only means available, but raising an exception to enforce this
method for now.
- # TODO: When/If other auth methods are implemented this exception
should be removed/modified.
- if not access_token:
- raise AirflowException("An access token is required to
authenticate to GitHub.")
+ extras = conn.extra_dejson or {}
+
+ if access_token:
+ auth: Auth.Auth = Auth.Token(access_token)
+ elif extras:
+ if key_path := extras.get("key_path"):
+ if not key_path.endswith(".pem"):
+ raise RuntimeError("Unrecognised key file")
+ with open(key_path) as key_file:
+ private_key = key_file.read()
+
+ app_id = extras.get("app_id")
+ installation_id = extras.get("installation_id")
+ if not isinstance(installation_id, int):
+ raise RuntimeError("The provided installation_id should be
integer.")
+ if not isinstance(app_id, (str | int)):
+ raise RuntimeError("The provided app_id should be integer or
string.")
+ token_permissions = extras.get("token_permissions", None)
+
+ auth = Auth.AppAuth(app_id,
private_key).get_installation_auth(installation_id, token_permissions)
Review Comment:
Great catch thank!
--
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]