From 8c75c9bc0984df5890ed614b213ff7d6b3abee73 Mon Sep 17 00:00:00 2001 From: Trish Gillett-Kawamoto Date: Wed, 14 Aug 2024 19:14:48 -0600 Subject: [PATCH] fix: fix problem when app token used without installation ID provided (#291) Addresses the problem described by @camerondavison [here](https://github.com/MeltanoLabs/tap-github/pull/284#discussion_r1717520222), and introduced in https://github.com/MeltanoLabs/tap-github/pull/284. If not provided, installation ID should be set to None, since that is the way `generate_app_access_token` expects a missing installation ID to be represented. --- tap_github/authenticator.py | 4 +++- tap_github/tests/test_authenticator.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tap_github/authenticator.py b/tap_github/authenticator.py index 8f5acf1e..6fe1aefc 100644 --- a/tap_github/authenticator.py +++ b/tap_github/authenticator.py @@ -167,7 +167,9 @@ def __init__(self, env_key: str, rate_limit_buffer: Optional[int] = None, **kwar parts = env_key.split(";;") self.github_app_id = parts[0] self.github_private_key = (parts[1:2] or [""])[0].replace("\\n", "\n") - self.github_installation_id: Optional[str] = (parts[2:3] or [""])[0] + self.github_installation_id: Optional[str] = ( + parts[2] if len(parts) >= 3 else None + ) self.token_expires_at: Optional[datetime] = None self.claim_token() diff --git a/tap_github/tests/test_authenticator.py b/tap_github/tests/test_authenticator.py index 68227815..2a325bb1 100644 --- a/tap_github/tests/test_authenticator.py +++ b/tap_github/tests/test_authenticator.py @@ -135,7 +135,7 @@ def test_initialization_with_2_part_env_key(self): token_manager = AppTokenManager("12345;;key\\ncontent") assert token_manager.github_app_id == "12345" assert token_manager.github_private_key == "key\ncontent" - assert token_manager.github_installation_id == "" + assert token_manager.github_installation_id is None def test_initialization_with_malformed_env_key(self): expected_error_expression = re.escape(