From 16d4308d291d0bab43d96d1d8c6929d940aacb6f Mon Sep 17 00:00:00 2001 From: magic_rb Date: Wed, 12 Jun 2024 18:26:40 +0200 Subject: [PATCH] Fix GitHub `InstallationToken` renewal. Signed-off-by: magic_rb --- buildbot_nix/github/installation_token.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/buildbot_nix/github/installation_token.py b/buildbot_nix/github/installation_token.py index 6714246..da6f9f9 100644 --- a/buildbot_nix/github/installation_token.py +++ b/buildbot_nix/github/installation_token.py @@ -41,7 +41,9 @@ class InstallationToken(RepoToken): 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 @@ -72,7 +74,7 @@ class InstallationToken(RepoToken): 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 )