Skip to content

Commit

Permalink
Merge pull request #179 from MagicRB/fix_installation_token_renewal
Browse files Browse the repository at this point in the history
Fix GitHub `InstallationToken` renewal.
  • Loading branch information
Mic92 authored Jun 13, 2024
2 parents c92a655 + 16d4308 commit aeddb48
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions buildbot_nix/github/installation_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def _generate_token(
token = InstallationToken._create_installation_access_token(
jwt_token, installation_id
).json()["token"]
expiration = datetime.now(tz=UTC) + InstallationToken.GITHUB_TOKEN_LIFETIME
expiration = (
datetime.now(tz=UTC) + InstallationToken.GITHUB_TOKEN_LIFETIME * 0.8
)

return token, expiration

Expand Down Expand Up @@ -72,7 +74,7 @@ def get_as_secret(self) -> str:
return f"%(secret:github-token-{self.installation_id})"

def verify(self) -> None:
if datetime.now(tz=UTC) - self.expiration > self.GITHUB_TOKEN_LIFETIME * 0.8:
if datetime.now(tz=UTC) > self.expiration:
self.token, self.expiration = InstallationToken._generate_token(
self.jwt_token, self.installation_id
)
Expand Down

0 comments on commit aeddb48

Please sign in to comment.