Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 4, 2024
1 parent 7136362 commit d095f41
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 118 deletions.
22 changes: 16 additions & 6 deletions tap_github/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def generate_jwt_token(
github_app_id: str,
github_private_key: str,
expiration_time: int = 600,
algorithm: str = "RS256"
algorithm: str = "RS256",
) -> str:
actual_time = int(time.time())

Expand Down Expand Up @@ -189,12 +189,16 @@ def claim_token(self):
'":app_id:;;-----BEGIN RSA PRIVATE KEY-----\\n_YOUR_P_KEY_\\n-----END RSA PRIVATE KEY-----"'
)

self.token, self.token_expires_at = generate_app_access_token(self.github_app_id, self.github_private_key, self.github_installation_id)
self.token, self.token_expires_at = generate_app_access_token(
self.github_app_id, self.github_private_key, self.github_installation_id
)

# Check if the token isn't valid. If not, overwrite it with None
if not self.is_valid_token():
if self.logger:
self.logger.warning("An app token was generated but could not be validated.")
self.logger.warning(
"An app token was generated but could not be validated."
)
self.token = None
self.token_expires_at = None

Expand Down Expand Up @@ -235,7 +239,9 @@ def prepare_tokens(self) -> List[TokenManager]:

token_managers: List[TokenManager] = []
for token in personal_tokens:
token_manager = PersonalTokenManager(token, rate_limit_buffer=rate_limit_buffer, logger=self.logger)
token_manager = PersonalTokenManager(
token, rate_limit_buffer=rate_limit_buffer, logger=self.logger
)
if token_manager.is_valid_token():
token_managers.append(token_manager)

Expand All @@ -245,11 +251,15 @@ def prepare_tokens(self) -> List[TokenManager]:
# "{app_id};;{-----BEGIN RSA PRIVATE KEY-----\n_YOUR_PRIVATE_KEY_\n-----END RSA PRIVATE KEY-----}"
env_key = env_dict["GITHUB_APP_PRIVATE_KEY"]
try:
app_token_manager = AppTokenManager(env_key, rate_limit_buffer=rate_limit_buffer, logger=self.logger)
app_token_manager = AppTokenManager(
env_key, rate_limit_buffer=rate_limit_buffer, logger=self.logger
)
if app_token_manager.is_valid_token():
token_managers.append(app_token_manager)
except ValueError as e:
self.logger.warn(f"An error was thrown while preparing an app token: {e}")
self.logger.warn(
f"An error was thrown while preparing an app token: {e}"
)

self.logger.info(f"Tap will run with {len(token_managers)} auth tokens")
return token_managers
Expand Down
Loading

0 comments on commit d095f41

Please sign in to comment.