Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
TrishGillett committed Aug 4, 2024
1 parent 0cf3b06 commit 7bbc6ed
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 104 deletions.
23 changes: 16 additions & 7 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 @@ -226,7 +230,6 @@ def prepare_tokens(self) -> List[TokenManager]:
for key, value in env_dict.items()
if key.startswith("GITHUB_TOKEN")
}

if len(env_tokens) > 0:
self.logger.info(
f"Found {len(env_tokens)} 'GITHUB_TOKEN' environment variables for authentication."
Expand All @@ -235,7 +238,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 +250,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 7bbc6ed

Please sign in to comment.